Add property tests to resistor-color-duo#907
Add property tests to resistor-color-duo#907tejasbubane wants to merge 1 commit intoexercism:masterfrom
Conversation
c5b4115 to
d70c7ac
Compare
|
Hi @tejasbubane, and thanks for your PR! I'll get back to it in the next few days unless someone else does. :-) |
sshine
left a comment
There was a problem hiding this comment.
Nice work so far.
I've left some comments below for improvement.
For interesting reading material,
https://www.fpcomplete.com/blog/quickcheck-hedgehog-validity
It may also be worth linking to in the link collection in your hint.
| instance Arbitrary Color where | ||
| arbitrary = oneof $ map return [Black, Brown, Red, Orange, Yellow, Green, Blue, Violet, Grey, White] |
There was a problem hiding this comment.
Three things:
- Avoid orphan instances by using a
newtyperather than-fno-warn-orphans. - Exhaust the data type programmatically by
deriving (..., Enum, Bounded). - Use
elements :: [a] -> Gen ainstead ofoneofhere.
| instance Arbitrary Color where | |
| arbitrary = oneof $ map return [Black, Brown, Red, Orange, Yellow, Green, Blue, Violet, Grey, White] | |
| newtype AnyColor = AnyColor Color deriving (Show, Eq) | |
| instance Arbitrary AnyColor where | |
| arbitrary = AnyColor <$> elements [minBound..] |
But instead of using the Arbitrary type class, consider simply making a colorGen:
| instance Arbitrary Color where | |
| arbitrary = oneof $ map return [Black, Brown, Red, Orange, Yellow, Green, Blue, Violet, Grey, White] | |
| colorGen :: Gen Color | |
| colorGen = elements [minBound..] |
I might also place this generator at the bottom of the file.
| @@ -1,19 +1,32 @@ | |||
| {-# OPTIONS_GHC -fno-warn-type-defaults #-} | |||
| {-# OPTIONS_GHC -fno-warn-orphans #-} | |||
There was a problem hiding this comment.
See comment below above.
| {-# OPTIONS_GHC -fno-warn-orphans #-} |
| that only accepts two colors and produces the resistor's numeric value | ||
| component of its resistance. | ||
|
|
||
| **Bonus - Property Testing:** |
There was a problem hiding this comment.
I haven't seen that we use "Bonus" or mark sub-subsections using **...** elsewhere on the track.
I might skip this heading altogether.
|
Hey @tejasbubane, are you interested in following up on this PR? |
Closes #867