Tests in Disco [002L]
We can also attach tests to our functions in Disco. Each test goes on a line by itself beginning with !!!.
!!! double(0) == 0 !!! double(2) == 4 !!! double(7) == 14 !!! forall n : N. double(n) >= 0 double : N -> N double(n) = 2nTests can either be simple true or false tests, or they can have a
forall to say that something should be true for every value
of a certain type. When we :load this file, Disco will run
the tests and report whether they succeed.
Disco> :load double.disco Loading double.disco... Running tests... double: OK Loaded.If we try changing the
double(n) >= 0 test to
double(n) > 0, we can see that the test fails:
Disco> :load double.disco
Loading double.disco...
Running tests...
double:
- Certainly false: ∀n. double(n) > 0
Found counterexample:
n = 0
- Left side: 0
- Right side: 0
Loaded.
However, another way to express a correct test would be as follows:
!!! forall n : N. (n == 0) or double(n) > 0