Testing module
This module contains functions for development of unit testing libraries. Tests are defined with add, and then the test set is run with run
program test;
Bool predicate(Int a) = (a%2 == 0);
Void() test1() {
xs = randomIntArray(10,1000);
ys = filter(predicate,xs);
assert(all(predicate,ys));
}
Void main() {
init();
add(@test1,10,"Filtering");
run();
}
Note that random values in this module are generated using rand, a generator with high speed but poor quality. For higher quality random values, consider using Lfrand or another generator. For most testing, this will not be important.
Data types
- Testing::Arbitrary - An arbitrary union type.
Functions
- Void add(Void() test,Int num=1,String name="") - Add a test function.
- Void init() - Re-initialise the test framework.
- [a] randomArray(a() generator,Int minsize=0,Int maxsize=1000) - Return a random array
- Char randomChar() - Return a random character
- [Char] randomCharArray(Int minsize=0,Int maxsize=1000) - Return a random list of characters
- Float randomFloat() - Return a random floating point number
- [Float] randomFloatArray(Int minsize=0,Int maxsize=1000) - Return a random list of floating-point numbers
- Int randomInt() - Return a random integer
- [Int] randomIntArray(Int minsize=0,Int maxsize=1000) - Return a random list of integers
- Float randomNegativeFloat() - Return a random negative floating point number
- Int randomNegativeInt() - Return a random negative integer
- Float randomPositiveFloat() - Return a random positive floating point number
- Int randomPositiveInt() - Return a random positive integer
- Int randomSignOfInt() - Return a distribution of integers
- String randomString(Int minsize=0,Int maxsize=160) - Return a random string
- [String] randomStringArray(Int minsize=0,Int maxsize=10000) - Return a random list of strings
- Arbitrary randomValue(Int depth=10) - Return a random value
- Bool run() - Run the tests.