-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add checks for Enum * Remove redundant checks * New set of laws * Inconsistent variable names * Use pred/succ instead of arithmetic * Don't call checkEnum from checkBoundedEnum * Detect overflow when checking submultiplicative euclidean function * Update module names in imports; fix whitespace * Remove duplicate Enum instances * Fix errors in Enum file * Drop BoundedEnum check for Either * Drop BoundedEnum check for Maybe * Drop BoundedEnum check for Tuple * Add checkEnumGen * Revert EuclideanRing change Co-authored-by: JordanMartinez <[email protected]> Co-authored-by: JordanMartinez <[email protected]>
- Loading branch information
1 parent
b09ef8c
commit 44d0449
Showing
11 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
module Test.QuickCheck.Laws.Data.Enum where | ||
|
||
import Prelude | ||
|
||
import Data.Enum (pred, succ, class Enum) | ||
import Data.Maybe (maybe) | ||
import Effect (Effect) | ||
import Effect.Console (log) | ||
import Test.QuickCheck (quickCheck') | ||
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary) | ||
import Test.QuickCheck.Gen (Gen) | ||
import Type.Proxy (Proxy) | ||
|
||
checkEnum | ||
∷ ∀ a | ||
. Arbitrary a | ||
⇒ Enum a | ||
⇒ Ord a | ||
⇒ Proxy a | ||
→ Effect Unit | ||
checkEnum _ = checkEnumGen (arbitrary :: Gen a) | ||
|
||
checkEnumGen | ||
∷ ∀ a | ||
. Enum a | ||
⇒ Ord a | ||
⇒ Gen a | ||
→ Effect Unit | ||
checkEnumGen gen = do | ||
log "Checking 'Successor' law for Enum" | ||
quickCheck' 1000 $ successor <$> gen | ||
|
||
log "Checking 'Predecessor' law for Enum" | ||
quickCheck' 1000 $ predecessor <$> gen | ||
|
||
log "Checking 'Succ retracts pred' law for Enum" | ||
quickCheck' 1000 $ succRetractsPred <$> gen | ||
|
||
log "Checking 'Pred retracts succ' law for Enum" | ||
quickCheck' 1000 $ predRetractsSucc <$> gen | ||
|
||
log "Checking 'Non-skipping succ' law for Enum" | ||
quickCheck' 1000 $ nonSkippingSucc <$> gen <*> gen | ||
|
||
log "Checking 'Non-skipping pred' law for Enum" | ||
quickCheck' 1000 $ nonSkippingPred <$> gen <*> gen | ||
|
||
where | ||
|
||
successor :: a -> Boolean | ||
successor a = maybe true (a < _) (succ a) | ||
|
||
predecessor :: a -> Boolean | ||
predecessor a = maybe true (_ < a) (pred a) | ||
|
||
succRetractsPred :: a -> Boolean | ||
succRetractsPred a = (pred a >>= succ >>= pred) == pred a | ||
|
||
predRetractsSucc :: a -> Boolean | ||
predRetractsSucc a = (succ a >>= pred >>= succ) == succ a | ||
|
||
nonSkippingSucc :: a -> a -> Boolean | ||
nonSkippingSucc a b = b <= a || maybe false (_ <= b) (succ a) | ||
|
||
nonSkippingPred :: a -> a -> Boolean | ||
nonSkippingPred a b = a <= b || maybe false (b <= _) (pred a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters