-
Book Overview & Buying
-
Table Of Contents
Mastering F#
By :
Unit tests are a tremendously useful tool to verify the robustness of our program. However, as we have seen in the earlier examples, we are always checking against single cases, and, even when automatically generating parameters for our tests, it is always difficult to be sure that there are no edge cases we may be missing.
The solution is not to test against the results of a function but against properties. This way, we can feed any value to the function, and verify that the properties are always fulfilled. We can also think of the properties as the requirements of the application. For example, we may want to verify that our add function, given earlier, fulfills the following three properties of addition:
add x y should be the same as add y x add x y |> add z should be the same as add y z |> add xadd x 0 should be the same as xThanks to F#'s expressiveness, it is really easy to write these conditions...
Change the font size
Change margin width
Change background colour