Testing Suite - drewbent/grid-world-scheme GitHub Wiki


## (unit-test p . cases)

This is the core of the testing suite. It takes a procedure (p) and a series of lists (cases). Each test case has its desired output in the first element of the list. The rest of the elements are the arguments to be given to the procedure. unit-test tests all the cases and returns #t if they all return the desired output. Any inconsistency will result in a formatted error message and will cause unit-test to return #f.

Arguments

  • p - procedure
  • case1 - ( [desired output] . args )
  • case2 - ( [desired output . args )
  • etc.

Sample usage

(unit-test + '(7 1 5 1) '(3 1 4 -2)) --> #t

7 = 1 + 5 + 1

3 = 1 + 4 - 2

(unit-test + '(7 1 5 1) '(3 1 4 -1)) --> #f

7 = 1 + 5 + 1

3 != 1 + 4 - 1

Error message:

The following test case failed:

Test data: (1 4 -1)

Desired output: 3

Actual output: 4

These are two simple examples. unit-test can work with more complex procedures as well.

(unit-test (λ (loc1 loc2) (loc1 'compare-to loc2)) (list 1 (new-location 1 1) (new-location 0 0)))

(error? p . cases)

Negated version of unit-test.

(exception? p)

Determines if a procedure returns an error or not.

(exception? (λ () (/ 2 0))) --> #t

(run-tests)

Runs a series of unit-tests and bundles all the error messages together. Unit-tests can be organized by categories (only 1-deep currently). See the code for more details.

⚠️ **GitHub.com Fallback** ⚠️