Code changed, tests failing, fantastic. Now let’s fix them*.
First of all, let’s see what exactly is breaking:
Looking at the property’s code:
Nothing too complicated. It is the smart constructor that does not like quickcheck’s input. Let’s see why. Here’s the code:
Oh, ok, I see. The error message looks like the 0 number of dice might be the problem but in fact it is the number of faces of each die - it’s 100 and the limit is 99. The answer to that is to adjust quickcheck’s input data. For this property (verify that showable DieTerms are shown in a certain way), I will narrow the input down to values producing showable DieTerms:
number of dice: 0-99
number of faces of each die: 0-99
We can do it with generators. Generators help provide quickcheck with desired test data input:
Just as a reminder, I’m using following aliases to make the code more explicit:
With generators prepared like this, I can modify the prop_ShowDieTerm property to operate on them and not on type Word8:
Does it work? Let’s find out:
Success!
Now I should fix remaining properties but that’s a task for another day.
Other things to consider:
since I’m using smart constructors now, it would be a good idea to test them
since smart constructors take care of data checking I don’t have to verify the “Show” implementation for incorrect inputs (as every incorrect input will not even make it to the show function - an error will be generated first)
*The code I’m writing here may not be immediately available in the roller repository (even in the develop branch).