For the OCaml part today we covered roughly Hickey chap.3.3 + 5.
For this afternoon's exercise session I ask you to consider the following:
0. Implement fst and snd with pattern matching
1. Write a QCheck test of fac (slide 26, day 1) that tests
whether fac n is divisible by n.
Does it succeed or fail?
In the latter case: is there more than one reason?
patch the test case accordingly
(the generator int_range l u where l and u are
lower and upper bounds respectively may prove helpful)
2. a. Write an implementation of Euclid's algorithm (Hickey, Ex.3.4, p.25)
b. QuickCheck your implementation against Hickey's algorithm (on p.12)
3. Write a classifier to observe the modulus of the various integer generators
4. Test the triangle inequality
(for all points A,B,C. |A C| <= |A B| + |B C|)
as a property for the distance function
5. Test the following different versions of the fibonacci function for
agreement:
- recursive
- iterative
- sub-linear (a challenge for the daring)
6. Test String.uppercase (what properties should it have?)