Previous Page Next Page Contents

prog::test -- automatic comparing of calculation results

Introduction

prog::test(stmt, res) evaluates both MuPAD expressions stmt and res and compares the results.

Call(s)

prog::test(stmt, res <, message>)
prog::test(stmt, TrapError = errnr <, message>)
prog::test(stmt <, message>)

Parameters

statement - a MuPAD statement to test
res - a MuPAD expression or statement that determines the expected result.
errnr - a positive integer that determines a MuPAD error
message - a string that will be displayed as message if the test fails

Options

TrapError = errnr - With this option it is possible to check the error behavior of a function. The tested call must produce an error, and the internal error number must be equal to errnr. In this case no error message is printed. In all other cases the test fails and an error message is printed.

Returns

prog::test returns the void object null(). While executing, messages will be printed on screen or into files.

Related Functions

prog::error, prog::testinit, prog::testexit, prog::testfunc, TESTPATH

Details

Option: TrapError

Example 1

prog::test can be called interactively:

>> prog::test(1 + 1, 2):
   prog::test(is(2 > 1)):
   prog::test(sin(PI), 0, "check sin"):

These tests checked all right, therefore nothing was printed. In the next tests wrong results are tested against, to demonstrate the messages given by prog::test:

>> prog::test(1 + 2, 2):
   prog::test(is(x > 1)):
   prog::test(sin(PI), PI, "check sin"):
      Error in test 'interactive' 3:  1 + 2 = 2 [<> 3]
      Error in test 'interactive' 4:  is(1 < x) = TRUE [<> UNKNOWN]
      Error in test 'interactive' 5:  sin(PI) = PI [<> 0] (check sin)

Example 2

This is a short example for a test file with name "test.tst":

      // test file "test.tst"
      test:= (a, b) -> a^2 + 2*b^2 - a*b:
      prog::testinit("test"):
      prog::testfunc(test):
      prog::test(test(1, 4), 29, "my first example"):
      prog::test(test(3, -2), 24, "the second example"):
      prog::test(error("test"), TrapError = 1028):
      prog::testexit():

The first statement is only a comment. The second line contains an initialization of a test procedure called test. Then the test is initialized with prog::testinit and the function name is set with prog::testfunc.

After that three tests are performed: The first test is right, the second expected result is wrong, and the third test produces an error, but the expected result is this error, the error number returned by traperror is 1028 (user call of error).

The whole test takes nearly no time:

>> read("test.tst")
      Error in test 'test' 2: test(3, -2) = 24 [<> 23] (the second example)
      Info: 2 tests, 1 error,  time:  0.00 / 0.01 s
>> setuserinfo(prog::test, 2):
   read("test.tst")
      testing 'test' 1
        for test(1, 4) = 29
      testing 'test' 2
        for test(3, -2) = 24
      Error in test 'test' 2: test(3, -2) = 24 [<> 23] (the second example)
      Info: 2 tests, 1 error,  time:  0.00 / 0.01 s

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000