testing

Testing is a collection of procedures for unit testing icon code.

For example, to test a procedure that squares a number, you might run tests:

  test_start ("Testing square procedure")
  test_approx_equals (4.0, square (2.0))
  test_approx_equals (9.0, square (-3))
  test_finish ()

For an output like:

  Test: Testing square procedure
        Total: 2 Passed: 2 Failed: 0

Links

Procedures

test_approx_equals (expected, actual, message, eps)

Used to test if two numbers are within an agreed tolerance.

Parameters:

expected
the expected value
actual
the actual computed value
message
optional message to display on failure of test
eps
maximum allowed difference between expected and actual


test_equals (expected, actual, message, comparator)

Used to test if two objects are equal.

Parameters:

expected
the expected value
actual
the actual computed value
message
optional message to display on failure of test
comparator
optional comparator method, succeeds if two arguments are same. Defaults to `===`.


test_fails (coexp, message)

Tests if the given coexp fails. i.e. if

  @coexp => fails

Parameters:

coexp
co-expression to test.
message
optional message to display on failure of test


test_finish ()

Finishes a suite of test results, and reports results.


test_start (title)

Initialises a new suite of test results. Must be called before running any tests.

Parameters:

title
names the test suite.

test_succeeds (coexp, message)

Tests if the given coexp succeeds. i.e. if

  @coexp => succeeds

Parameters:

coexp
co-expression to test.
message
optional message to display on failure of test


Home