diff --git a/part2.html b/part2.html index cb1f3a2..008968c 100644 --- a/part2.html +++ b/part2.html @@ -4214,7 +4214,7 @@ TODO explain `some` and `many`
We can ask QuickCheck to run them in GHCi:
-So far so good. However this isn’t really what QuickCheck was made for. QuickCheck was designer for property-based testing where you can state a property your code should have, and QuickCheck runs your code with randomized inputs, checking the property every time. What would be a simple property that a correct implementation of reverse has? Reversing a list twice should certainly give us back the same list. Let’s write it out:
So far so good. However this isn’t really what QuickCheck was made for. QuickCheck was designed for property-based testing where you can state a property your code should have, and QuickCheck runs your code with randomized inputs, checking the property every time. What would be a simple property that a correct implementation of reverse has? Reversing a list twice should certainly give us back the same list. Let’s write it out:
Our Property has an argument, which means that QuickCheck will generate random values and run the test. We can use the verboseCheck function to see which values are run. We can also give a parameter to the test ourselves if we wish to check a specific value.
scaleMoney :: Double -> Money currency -> Money currency
scaleMoney factor (Money a) = Money (factor * a)*Examples.Phantom> :t scaleMoney 3 twoEuros
-scaleMoney 3 euro :: Money EUR
+scaleMoney 3 twoEuros :: Money EUR
*Examples.Phantom> :t scaleMoney 3 dollar
scaleMoney 3 dollar :: Money USDNext up: adding two amounts that are in the same currency. We get a nice type error if we try to add values in two different currencies.