CodeTools - Maple Programming Help

Home : Support : Online Help : Programming : CodeTools : CodeTools/Test

CodeTools

 Test
 facilitate the creation of Maple code test suites

 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" by default.
 • 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

 > $\mathrm{with}\left(\mathrm{CodeTools}\right)$
 $\left[{\mathrm{CPUTime}}{,}{\mathrm{DecodeName}}{,}{\mathrm{EncodeName}}{,}{\mathrm{GCTime}}{,}{\mathrm{Profiling}}{,}{\mathrm{ProgramAnalysis}}{,}{\mathrm{RealTime}}{,}{\mathrm{Test}}{,}{\mathrm{ThreadSafetyCheck}}{,}{\mathrm{Usage}}\right]$ (1)

Tests that pass.

 > $\mathrm{Test}\left(\mathrm{int}\left(x,{x}^{2}\right),"integration range or variable must",'\mathrm{testerror}',\mathrm{label}="Test Pass 1"\right)$
 Test Pass 1 passed
 > $\mathrm{Test}\left(\mathrm{int}\left(x,{x}^{2}\right),"",'\mathrm{testerror}',\mathrm{label}="Test Pass 2"\right)$
 Test Pass 2 passed
 > $\mathrm{Test}\left(\mathrm{int}\left({x}^{2},x\right),"",'\mathrm{testnoerror}',\mathrm{label}="Test Pass 3"\right)$
 Test Pass 3 passed
 > $\mathrm{Test}\left(\mathrm{int}\left(x,x\right),\frac{{x}^{2}}{2},\mathrm{label}="Test Pass 4"\right)$
 Test Pass 4 passed
 > $\mathrm{Test}\left(\mathrm{int}\left(x,x\right),{\left(\frac{x}{\mathrm{sqrt}\left(2\right)}\right)}^{2},'\mathrm{simplify}',\mathrm{label}="Test Pass 5",'\mathrm{boolout}'\right)$
 Test Pass 5 passed
 ${\mathrm{true}}$ (2)

Tests that fail.

 > $\mathrm{Test}\left(\mathrm{int}\left({x}^{2},x\right),"integration range or variable must",\mathrm{testerror},\mathrm{label}="Test Fail 1"\right)$
 Test Fail 1 failed  Expected error but did not receive one
 > $\mathrm{Test}\left(\mathrm{int}\left(x,{x}^{2}\right),"",'\mathrm{testnoerror}',\mathrm{label}="Test Fail 2"\right)$
 Test Fail 2 failed  Expected no errors, but got:  Error, integration range or variable must be specified in the second argument, got x^2
 > $\mathrm{Test}\left(\mathrm{int}\left(x,x\right),\frac{{x}^{2}}{4},'\mathrm{simplify}',\mathrm{label}="Test Fail 3"\right)$
 Test Fail 3 failed  Expected result : 1/4*x^2  Evaluated result: 1/2*x^2
 > $\mathrm{Test}\left(\mathrm{int}\left(x,x\right),{\left(\frac{x}{\mathrm{sqrt}\left(2\right)}\right)}^{2},\mathrm{label}="Test Fail 4",'\mathrm{boolout}'\right)$
 Test Fail 4 failed  Expected result : x^2/sqrt(2)^2  Evaluated result: 1/2*x^2
 ${\mathrm{false}}$ (3)

The boolout and quiet options work well together.

 > $\mathrm{Test}\left(\mathrm{int}\left(x,{x}^{2}\right),"",'\mathrm{testerror}','\mathrm{boolout}','\mathrm{quiet}'\right)$
 ${\mathrm{true}}$ (4)
 > $\mathrm{Test}\left(\mathrm{int}\left({x}^{2},x\right),"",'\mathrm{testerror}','\mathrm{boolout}','\mathrm{quiet}'\right)$
 ${\mathrm{false}}$ (5)

Compatibility

 • The CodeTools[Test] command was introduced in Maple 15.
{"ft_lang_label":"__label__en","ft_lang_prob":0.66484165,"math_prob":0.9935861,"size":3712,"snap":"2020-34-2020-40","text_gpt3_token_len":966,"char_repetition_ratio":0.14455232,"word_repetition_ratio":0.04275093,"special_character_ratio":0.20716594,"punctuation_ratio":0.14888011,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98770106,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-15T14:54:34Z\",\"WARC-Record-ID\":\"<urn:uuid:7dba76b7-155c-470e-8f5e-a9ab0e6d8aa1>\",\"Content-Length\":\"273115\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a0a3868e-665f-453d-bf33-fb75646687c9>\",\"WARC-Concurrent-To\":\"<urn:uuid:53b1ae40-fc86-43d2-a341-8318c7cb53b1>\",\"WARC-IP-Address\":\"199.71.183.28\",\"WARC-Target-URI\":\"https://www.maplesoft.com/support/help/maple/view.aspx?path=CodeTools%2FTest\",\"WARC-Payload-Digest\":\"sha1:2LACEPMJS2BVWKSGWET2OO3LS4M76TIF\",\"WARC-Block-Digest\":\"sha1:L342TAWDCMZ4KE4HQLIWRZLKUF2LIYFM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439740848.39_warc_CC-MAIN-20200815124541-20200815154541-00181.warc.gz\"}"}