This piece of work I left specifically for Sunday. Nice, relaxed evening, tea and gentle ambient music are perfect for updating broken tests.
As you remember, all started when I decided to use smart constructors in my roller repository as a way of ensuring the input data for constructors meets my criteria. This broke some tests, I fixed one of them last night and now, since I know what broke and how to fix it, have to fix remaining tests.
At the time of writing this, I have two test files:
- TypesTests.hs
- ParseTests.hs
I decided to start with TypesTests as the logic there is more straightforward.
Remaining properties to fix there are:
prop_ShowAddedDieTerm
prop_ShowSubtractedDieTerm
prop_ShowConstantTerm
prop_ShowAddedConstantTerm
prop_ShowSubtractedConstantTerm
First two properties are easy to fix as the only thing that really needs changing is the input parameters (generators should be used). The other two are not much more complicated - they just require new generator (this time just one).
Initial code:
Error:
The solution is to write a showable constant generator:
And then to just use it in all three “ConstantTerm” properties (here, showing only the first one):
Does it work? Let’s find out:
Success!
Now, since I have all TypesTests properties updated and working with smart constructors, I should check and update ParseTests properties, but it’s a task for another day.
For now, I’m just happy to see this: