Module pl.test
Useful test utilities.
test.asserteq({1,2},{1,2}) -- can compare tables
test.asserteq(1.2,1.19,0.02) -- compare FP numbers within precision
T = test.tuple -- used for comparing multiple results
test.asserteq(T(string.find(" me","me")),T(2,3))
Dependencies: pl.utils , pl.tablex , pl.pretty , pl.path , debug
Functions
| asserteq (x, y, eps) | like assert, except takes two arguments that must be equal and can be tables. |
| assertmatch (s1, s2) | assert that the first string matches the second. |
| asserteq2 (x1, x2, y1, y2) | a version of asserteq that takes two pairs of values. |
| tuple () | encode an arbitrary argument list as a tuple. |
| timer (msg, n, fun, ...) | Time a function. |
Functions
- asserteq (x, y, eps)
-
like assert, except takes two arguments that must be equal and can be tables.
If they are plain tables, it will use tablex.deepcompare.
Parameters:
x: any valuey: a value equal to xeps: an optional tolerance for numerical comparisons
- assertmatch (s1, s2)
-
assert that the first string matches the second.
Parameters:
s1: a strings2: a string
- asserteq2 (x1, x2, y1, y2)
-
a version of asserteq that takes two pairs of values.
x1==y1 and x2==y2must be true. Useful for functions that naturally return two values.Parameters:
x1: any valuex2: any valuey1: any valuey2: any value
- tuple ()
-
encode an arbitrary argument list as a tuple.
This can be used to compare to other argument lists, which is
very useful for testing functions which return a number of values.
Usage:
asserteq(tuple( ('ab'):find 'a'), tuple(1,1)) - timer (msg, n, fun, ...)
-
Time a function. Call the function a given number of times, and report the number of seconds taken,
together with a message. Any extra arguments will be passed to the function.
Parameters:
msg: a descriptive messagen: number of times to call the functionfun: the function...: optional arguments to fun