1 Suggestions and tips for writing test files
4 (1) test file contains pairs of expressions. The first
5 expression is the input, and the second is the expected output; for
6 example, here are two tests:
14 You may terminate each line with either a semicolon or a dollar
15 sign. To keep the file somewhat organized, terminate the input line
16 with a semicolon and the expected output with a dollar sign. It's helpful to
17 separate each input / expected output pair with a blank line.
19 (2) Name your file "rtest_<a word that describes its contents>.mac".
20 For example, "rtest_abs.mac" is a good name for tests for the absolute
23 (3) If the input is something that doesn't need to be checked, make a
24 compound statement with the last statement being 0. Thus
32 (4) If a test needs to use a non-default value for an option variable, try to
33 make the change local instead of global. For example
35 is (x < 1), prederror : false;
38 Doing so keeps your test from modifying the global environment.
40 (5) The first line of the test file should be
45 (6) From a Maxima input prompt, use the 'batch' function to run your test:
47 (%i1) batch("rtest_abs.mac", 'test);
48 Error log on #<output stream rtest_abs.ERR>
50 You may need to give Maxima a full pathname to the file. After the
51 test finishes, you can look at the .ERR file to see which tests
54 (7) If your test defines functions, makes assumptions, or assigns
55 values to symbols, the last few lines of your test should clean up the
56 global environment; thus if your test does assume(x > 0), assigns a
57 value to 'a', and defines a function 'f', the last line of your test
58 should be something like
60 (forget(x > 0), remvalue(a), remfunction(f),0);
63 (8) To append a test file to the main Maxima test suite,
64 you'll need to append the file name to the list in the file
65 /tests/testsuite.lisp. If your test has known errors, you'll need to
66 include this data into testsuite.lisp. To illustrate, the tests
67 42 and 42 in rtest_abs are known bugs. To tell Maxima that these
68 are known bugs, append ((mlist) "rtest_abs" 42 43) to the file
69 list in testsuite.lisp.
71 Also, you'll need to append the name of the test file to
72 makefile.am. Finally, build Maxima and run the test suite. If all goes
73 well, commit the new test file.
77 (a) Check that your test runs multiple times without error. After
78 appending a new test to Maxima's test suite, make sure that run_testsuite()
79 runs multiple times without error.
81 (b) Always test the simple cases: abs(0), abs(0.0), abs(0.0b0), ... Also,
82 check that functions work correctly for CRE expressions, arguments that
83 contain '%i', empty lists, empty matrices, ... Thus always test
84 the 'boundary' cases; these are things like max(), min(), apply("*",[]), ....
86 (c) Check the sourceforge bug list for all reported bugs for the functions(s)
87 you are testing. Include tests for these bugs; also put a comment in your
88 test file that references the bug report:
90 /* See SF Bug # 771061 */
92 expand((vt . a^^(-1) . u+1)^^(-2));
93 ((vt.a^^(-1).u)^^2+2*(vt.a^^(-1).u)+1)^^(-1)$
95 If a bug causes a fatal error, you'll need to exclude it from your test
96 (or better, include it, but comment it out).
98 (d) It might be easier to place all known failures at the top of the
99 file. With this policy, you can append new tests without updating the
100 list of known failures in testsuite.lisp.
102 (e) If a test checks a not so well known identity, include a reference to the
106 hgfred([v+1/2],[2*v+1],2*%i*z);
107 4^(v/2)*bessel_j(v,z)*gamma(v+1)*exp(%i*z)/z^v$
109 (f) Maxima evaluates the input, but only simplifies the expected output. Thus
112 makelist(sin(k * %pi),k,1,5);
115 will fail. You'll need to write the test as either
117 makelist(sin(k * %pi),k,1,5);
118 ''(makelist(0,k,1,5))$
122 makelist(sin(k * %pi),k,1,5);
125 To get a test to pass,you may need to insert a few parenthesis in the
126 expected output; for example
131 Another way to handle such things is to use explicit calls to ratsimp:
136 To test a function such as factor, you do not want to apply ratsimp.