Difference between revisions of "Test-Suite Template"

From ApCoCoAWiki
Line 21: Line 21:
 
       TestRing::=QQ[x,y,z]; <br>
 
       TestRing::=QQ[x,y,z]; <br>
 
       Using TestRing Do
 
       Using TestRing Do
         $apcocoa/ts/assert.IsTrue(x=x, "x does not equal x.");
+
         $apcocoa/ts/assert.AssertTrue(x=x, "x does not equal x.");
 
       EndUsing; <br>
 
       EndUsing; <br>
 
     EndDefine; <br>
 
     EndDefine; <br>
Line 39: Line 39:
 
To run just a single test, call TODO.
 
To run just a single test, call TODO.
  
==Functions that are useful for testing==
+
==Assert functions==
For some packages, especially the numerical packages, the testfunction doesn't work very good, because you have to give the exact output-string, which can vary at different computers. For such packages there are some functions, which are listed below:
+
Especially for numerical packages the following assert functions might be helpful.
  
 
[[TestNumericalNumber]]
 
[[TestNumericalNumber]]

Revision as of 16:02, 22 June 2010

Testing an ApCoCoA-Package

This page explains how to create a test-suite for your package. Testing is important to make sure, that your package is still working correctly, when something in ApCoCoA or the ApCoCoALib changes.

A template for a test-suite

Please respect the following points when writing a test-suite for your package:

  • Create a package and name it like the corresponding package, with file ending .ts instead of the usual .cpkg
  • Define a function for every test you want to realize.
  • Name the functions as follows:
 Test<PackageName><MyTestName>()
  • Every function realizes EXACTLY one test.
  • A test can FAIL or SUCCEED. The test fails iff the test functions throws an error. To this end, use the AssertXY functions defined in assert.cpkg as much as is sensible. Note, that your test functions do not return anything.
  • If you miss some AssertXY function, add it to assert.cpkg.
  • You are free to add an arbitrary number of helper functions to your test-suite, just make sure that their names DO NOT start with 'Test'.

The following code shows a template for an apcocoa test package. You can find further examples of already existing test-suites in packages/apcocoa/ts of your ApCoCoA directory.

 Package $apcocoa/ts/template 
Define Initialize() -- e.g. initialize variables, that you want to use for all of your tests EndDefine;
Define TestTemplate01() -- 1st test
TestRing::=QQ[x,y,z];
Using TestRing Do $apcocoa/ts/assert.AssertTrue(x=x, "x does not equal x."); EndUsing;
EndDefine;
Define TestTemplate02() -- 2nd test
TestRing::=ZZ/(2)[x[1..5]];
Using TestRing Do -- implementation of another test EndUsing;
EndDefine;
-- TestTemplate03() and so on..
EndPackage;

Starting your tests

To run all the tests defined in a test-package, call

 $apcocoa/ts/aunit.RegisterTests("template");
 $apcocoa/ts/aunit.RunTests(); 

To run just a single test, call TODO.

Assert functions

Especially for numerical packages the following assert functions might be helpful.

TestNumericalNumber

TestNumPoly

TestListOfNumPoly

TestSortedListOfNumPoly

TestNumMatrix