Module pl.test

Useful test utilities.

Functions

asserteq (x, y) like assert, except takes two arguments that must be equal and can be tables.
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)
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 value
  • y: a value equal to x
asserteq2 (x1, x2, y1, y2)
a version of asserteq that takes two pairs of values. x1==y1 and x2==y2 must be true. Useful for functions that naturally return two values.

Parameters:

  • x1: any value
  • x2: any value
  • y1: any value
  • y2: 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.

Parameters:

  • ...:

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 message
  • n: number of times to call the function
  • fun: the function
  • ...: