Test - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


CodeTools

  

Test

  

facilitate the creation of Maple code test suites

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

Test( input, expected)

Test( input, expected, verification)

Parameters

input

-

expression to be evaluated for correctness

expected

-

expected result of evaluation of input

verification

-

expression of type verification, or one of the names testerror or testnoerror, or a procedure which returns type/verify similar to the verify command.

Options

• 

label = string or posint

  

A label for the test used in the pass/fail message printed. It is "Test i" by default, where i is replaced by a number that counts how many times Test has been called in this session. These labels are important because they are used by the TestFailures command to indicate which test cases have failed.

• 

quiet = truefalse

  

If true, no pass/fail messages will be printed.

• 

boolout = truefalse

  

If true, true will be returned if the test passed, and false otherwise.  If false, the default, NULL will be returned if the test passed, and an exception will be thrown if it fails.

Description

• 

The CodeTools[Test] command is a front-end utility used for the creation and verification of a suite of Maple test projects.  By default it returns a NULL result if the test succeeds and an error if the test fails.

• 

If only input and expected are given, the input is evaluated using verify and compared against the expected result.

• 

If input is a string, it will be parsed using parse.

• 

If the expected output is an expression sequence, then input and expected should each be enclosed in a list.

• 

If the third argument type is a verification expression then it is passed as a third verify argument for testing.

• 

The CodeTools[Test] command knows about two special verifications:

– 

testnoerror ignores the expected parameter and causes the test to fail when there is an exception during the evaluation of input.

– 

testerror is nearly the opposite of testnoerror and causes the test to pass only if there is an exception during the evaluation, and expected is a string that matches the error message prefix.

• 

If the third argument is not a verification  type or not one of above mentioned special verifiers, then it must be a procedure with a type/verify return.

• 

If more than three parameters are passed to "Test" , the others are passed as addition arguments to the specified verifier.

Examples

withCodeTools

CPUTime,DecodeName,EncodeName,GCTime,Log,Profiling,ProgramAnalysis,RealTime,RecursiveMembers,Test,TestFailures,ThreadSafetyCheck,Usage

(1)

Tests that pass.

Testintx,x2,integration range or variable must,testerror,label=Test Pass 1

Test Pass 1 passed

Testintx,x2,,testerror,label=Test Pass 2

Test Pass 2 passed

Testintx2,x,,testnoerror,label=Test Pass 3

Test Pass 3 passed

Testintx,x,x22,label=Test Pass 4

Test Pass 4 passed

Testintx,x,xsqrt22,simplify,label=Test Pass 5,boolout

Test Pass 5 passed

true

(2)

AMatrix1,2,3,4

A1234

(3)

TestA,A,label=Test Pass 6,boolout,quiet

true

(4)

A1|2,3|4

A1234

(5)

B1|2.001,2.999|4

B12.0012.9994

(6)

CodeTools:-TestA,B,float1,digits=4,label=Test Pass 7,boolout,quiet

true

(7)

Tests that fail.

Testintx2,x,integration range or variable must,testerror,label=Test Fail 1

Test Fail 1 failed
 Expected error but did not receive one

Error, (in CodeTools:-Test) TEST FAILED: Test Fail 1

Testintx,x2,,testnoerror,label=Test Fail 2

Test Fail 2 failed
 Expected no errors, but got:
 Error, integration range or variable must be specified in the second argument, got x^2

Error, (in CodeTools:-Test) TEST FAILED: Test Fail 2

Testintx,x,x24,simplify,label=Test Fail 3

Test Fail 3 failed
 Expected result : 1/4*x^2
 Evaluated result: 1/2*x^2

Error, (in CodeTools:-Test) TEST FAILED: Test Fail 3

Testintx,x,xsqrt22,label=Test Fail 4,boolout

Test Fail 4 failed
 Expected result : x^2/sqrt(2)^2
 Evaluated result: 1/2*x^2

false

(8)

The boolout and quiet options work well together.

Testintx,x2,,testerror,boolout,quiet

true

(9)

Testintx2,x,,testerror,boolout,quiet

false

(10)

Compatibility

• 

The CodeTools[Test] command was introduced in Maple 15.

• 

For more information on Maple 15 changes, see Updates in Maple 15.

See Also

CodeTools

type/verification

type/verify

verify