property-based tests of quartiles
Now that we have implementations of quartiles, how do we know it works? What properties would you want the quartiles values to obey?
Here are a few properties to implement:
- The median (q2) should be between the smallest and largest numbers.
- q0 <= q1 <= q2 <= q3 <= q4
These are invariants that we can guarantee. But invariants are just one way to create properties. We can also do a metamorphic test:
- Generate a random list l1.
- Calculate the quartiles l1q.
- Add a number to the list l1 that is greater than the max, call it l2.
- Calculate the quartiles l2q.
The values in l2q should be greater than or equal to the corresponding values in l1q.
Implement these three properties. That's the challenge this week.