-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add checks for Enum #23
Changes from 1 commit
c0816ae
79b286b
fa66b38
cbf406e
f1a33bf
a311bef
cb786f5
cf6ff0c
6ccc118
4896982
b2ae0e6
16d262e
b67b96e
da8ecf1
2026905
125a9ea
0fb9559
d49403d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
module Test.QuickCheck.Laws.Data.Enum where | ||
|
||
import Prelude | ||
import Control.Monad.Eff.Console (log) | ||
import Data.Enum (pred, succ, class Enum) | ||
import Data.Maybe (Maybe(Nothing)) | ||
import Test.QuickCheck (QC, quickCheck') | ||
import Test.QuickCheck.Arbitrary (class Arbitrary) | ||
import Type.Proxy (Proxy) | ||
|
||
checkEnum | ||
∷ ∀ eff a | ||
. (Arbitrary a, Enum a, Ord a) | ||
⇒ Proxy a | ||
→ QC eff Unit | ||
checkEnum _ = do | ||
|
||
log "Checking 'GT ordering' law for Enum" | ||
quickCheck' 1000 gtordering | ||
|
||
log "Checking 'LT ordering' law for Enum" | ||
quickCheck' 1000 ltordering | ||
|
||
log "Checking 'predsuccpred' law for BoundedEnum" | ||
quickCheck' 1000 predsuccpredLaw | ||
|
||
log "Checking 'succpredsucc' law for BoundedEnum" | ||
quickCheck' 1000 succpredsuccLaw | ||
|
||
where | ||
gtordering ∷ a → Boolean | ||
gtordering a = succ a == Nothing || succ a > pred a | ||
|
||
ltordering ∷ a → Boolean | ||
ltordering a = succ a == Nothing || pred a < succ a | ||
|
||
predsuccpredLaw :: a -> Boolean | ||
predsuccpredLaw a = succ a == Nothing || (pred a >>= succ >>= pred) == pred a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first I thought this might be a typo and we should be checking If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, the last two can get rid of the test. |
||
|
||
succpredsuccLaw :: a -> Boolean | ||
succpredsuccLaw a = succ a == Nothing || (succ a >>= pred >>= succ) == succ a | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is redundant; if
gtordering
holds, and we have a law-abidingOrd
instance, then this will certainly hold. I think we should remove this law from the Enum class, really.