| ▲ | 12_throw_away a day ago | |
> Then instead of asserting that f(1, 2) == 3 you need to do f(a, b) == a+b Not really, no, it's right there in the name: you should be testing properties (you can call them "invariants" if you want to sound fancy). In the example of testing an addition operator, you could test: 1. f(x,y) >= max(x,y) if x and y are non-negative 2. f(x,y) is even iff x and y have the same parity 3. f(x, y) = 0 iff x=-y etc. etc. The great thing is that these tests are very easy and fast to write, precisely because you don't have to re-model the entire domain. (Although it's also a great tool if you have 2 implementations, or are trying to match a reference implementation) | ||