From c0816aebde88d84f4430609adf3240477099fc3c Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Fri, 11 Nov 2016 13:19:38 +0100 Subject: [PATCH 01/15] Add checks for Enum --- src/Test/QuickCheck/Laws.purs | 7 ++- src/Test/QuickCheck/Laws/Data.purs | 1 + .../QuickCheck/Laws/Data/BoundedEnum.purs | 5 ++- src/Test/QuickCheck/Laws/Data/Enum.purs | 43 +++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/Test/QuickCheck/Laws/Data/Enum.purs diff --git a/src/Test/QuickCheck/Laws.purs b/src/Test/QuickCheck/Laws.purs index 7dfd83d..f8bbfd9 100644 --- a/src/Test/QuickCheck/Laws.purs +++ b/src/Test/QuickCheck/Laws.purs @@ -5,7 +5,7 @@ module Test.QuickCheck.Laws import Prelude import Control.Monad.Eff.Console (log) -import Data.Enum (class BoundedEnum) +import Data.Enum (class Enum, class BoundedEnum) import Data.Monoid (class Monoid) import Test.QuickCheck (QC) import Test.QuickCheck.Arbitrary (class Arbitrary, class Coarbitrary) @@ -21,6 +21,7 @@ derive newtype instance arbitraryA ∷ Arbitrary A derive newtype instance boundedA ∷ Bounded A derive newtype instance boundedEnumA :: BoundedEnum A derive newtype instance coarbitraryA ∷ Coarbitrary A +derive newtype instance enumA ∷ Enum A derive newtype instance eqA ∷ Eq A derive newtype instance ordA ∷ Ord A derive newtype instance semigroupA ∷ Semigroup A @@ -32,6 +33,7 @@ derive newtype instance arbitraryB ∷ Arbitrary B derive newtype instance boundedB ∷ Bounded B derive newtype instance boundedEnumB :: BoundedEnum B derive newtype instance coarbitraryB ∷ Coarbitrary B +derive newtype instance enumB ∷ Enum B derive newtype instance eqB ∷ Eq B derive newtype instance ordB ∷ Ord B derive newtype instance semigroupB ∷ Semigroup B @@ -43,6 +45,7 @@ derive newtype instance arbitraryC ∷ Arbitrary C derive newtype instance boundedC ∷ Bounded C derive newtype instance boundedEnumC :: BoundedEnum C derive newtype instance coarbitraryC ∷ Coarbitrary C +derive newtype instance enumC ∷ Enum C derive newtype instance eqC ∷ Eq C derive newtype instance ordC ∷ Ord C derive newtype instance semigroupC ∷ Semigroup C @@ -54,6 +57,7 @@ derive newtype instance arbitraryD ∷ Arbitrary D derive newtype instance boundedD ∷ Bounded D derive newtype instance boundedEnumD :: BoundedEnum D derive newtype instance coarbitraryD ∷ Coarbitrary D +derive newtype instance enumD ∷ Enum D derive newtype instance eqD ∷ Eq D derive newtype instance ordD ∷ Ord D derive newtype instance semigroupD ∷ Semigroup D @@ -65,6 +69,7 @@ derive newtype instance arbitraryE ∷ Arbitrary E derive newtype instance boundedE ∷ Bounded E derive newtype instance boundedEnumE :: BoundedEnum E derive newtype instance coarbitraryE ∷ Coarbitrary E +derive newtype instance enumE ∷ Enum E derive newtype instance eqE ∷ Eq E derive newtype instance ordE ∷ Ord E derive newtype instance semigroupE ∷ Semigroup E diff --git a/src/Test/QuickCheck/Laws/Data.purs b/src/Test/QuickCheck/Laws/Data.purs index 608dfa3..49b4ec2 100644 --- a/src/Test/QuickCheck/Laws/Data.purs +++ b/src/Test/QuickCheck/Laws/Data.purs @@ -3,6 +3,7 @@ module Test.QuickCheck.Laws.Data (module Exports) where import Test.QuickCheck.Laws.Data.BooleanAlgebra (checkBooleanAlgebra) as Exports import Test.QuickCheck.Laws.Data.Bounded (checkBounded) as Exports import Test.QuickCheck.Laws.Data.CommutativeRing (checkCommutativeRing) as Exports +import Test.QuickCheck.Laws.Data.Enum (checkEnum) as Exports import Test.QuickCheck.Laws.Data.Eq (checkEq) as Exports import Test.QuickCheck.Laws.Data.BoundedEnum (checkBoundedEnum) as Exports import Test.QuickCheck.Laws.Data.EuclideanRing (checkEuclideanRing) as Exports diff --git a/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs b/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs index fc2a7a8..bc728a1 100644 --- a/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs +++ b/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs @@ -9,6 +9,7 @@ import Data.Maybe (Maybe(Just)) import Data.Newtype (unwrap) import Test.QuickCheck (QC, quickCheck') import Test.QuickCheck.Arbitrary (class Arbitrary) +import Test.QuickCheck.Laws.Data.Enum (checkEnum) import Type.Proxy (Proxy) @@ -26,7 +27,9 @@ checkBoundedEnum . (Arbitrary a, BoundedEnum a, Ord a) ⇒ Proxy a → QC eff Unit -checkBoundedEnum _ = do +checkBoundedEnum p = do + + checkEnum p log "Checking 'succ' law for BoundedEnum" quickCheck' 1 succLaw diff --git a/src/Test/QuickCheck/Laws/Data/Enum.purs b/src/Test/QuickCheck/Laws/Data/Enum.purs new file mode 100644 index 0000000..75b1e68 --- /dev/null +++ b/src/Test/QuickCheck/Laws/Data/Enum.purs @@ -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 + + succpredsuccLaw :: a -> Boolean + succpredsuccLaw a = succ a == Nothing || (succ a >>= pred >>= succ) == succ a + From 79b286bbde846382ab3cecf983a428782bd5c25e Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Fri, 11 Nov 2016 14:11:08 +0100 Subject: [PATCH 02/15] Remove redundant checks --- src/Test/QuickCheck/Laws/Data/Enum.purs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/Enum.purs b/src/Test/QuickCheck/Laws/Data/Enum.purs index 75b1e68..9f60640 100644 --- a/src/Test/QuickCheck/Laws/Data/Enum.purs +++ b/src/Test/QuickCheck/Laws/Data/Enum.purs @@ -36,8 +36,8 @@ checkEnum _ = do ltordering a = succ a == Nothing || pred a < succ a predsuccpredLaw :: a -> Boolean - predsuccpredLaw a = succ a == Nothing || (pred a >>= succ >>= pred) == pred a + predsuccpredLaw a = (pred a >>= succ >>= pred) == pred a succpredsuccLaw :: a -> Boolean - succpredsuccLaw a = succ a == Nothing || (succ a >>= pred >>= succ) == succ a + succpredsuccLaw a = (succ a >>= pred >>= succ) == succ a From fa66b38d2f72305aade6afb217c460b80aeda58a Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Fri, 11 Nov 2016 16:00:59 +0100 Subject: [PATCH 03/15] New set of laws --- src/Test/QuickCheck/Laws/Data/Enum.purs | 59 ++++++++++++++++--------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/Enum.purs b/src/Test/QuickCheck/Laws/Data/Enum.purs index 9f60640..492f2e4 100644 --- a/src/Test/QuickCheck/Laws/Data/Enum.purs +++ b/src/Test/QuickCheck/Laws/Data/Enum.purs @@ -4,7 +4,7 @@ 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 Data.Maybe (maybe) import Test.QuickCheck (QC, quickCheck') import Test.QuickCheck.Arbitrary (class Arbitrary) import Type.Proxy (Proxy) @@ -16,28 +16,43 @@ checkEnum → 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 'Successor' law for Enum" + quickCheck' 1000 successor + + log "Checking 'Predecessor' law for Enum" + quickCheck' 1000 predecessor + + log "Checking 'Succ retracts pred' law for Enum" + quickCheck' 1000 succRetractsPred + + log "Checking 'Pred retracts succ' law for Enum" + quickCheck' 1000 predRetractsSucc + + log "Checking 'Non-skipping succ' law for Enum" + quickCheck' 1000 nonSkippingSucc + + log "Checking 'Non-skipping pred' law for Enum" + quickCheck' 1000 nonSkippingPred - 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 = (pred a >>= succ >>= pred) == pred a - - succpredsuccLaw :: a -> Boolean - succpredsuccLaw a = (succ a >>= pred >>= succ) == succ a - + + 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 x y = y <= x || maybe false (_ <= y) (succ x) + + nonSkippingPred :: a -> a -> Boolean + nonSkippingPred x y = x <= y || maybe false (y <= _) (pred x) + From cbf406e7eaf400aa5311358db349227425a0f7cf Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 15 Nov 2016 22:59:22 +0100 Subject: [PATCH 04/15] Inconsistent variable names --- src/Test/QuickCheck/Laws/Data/Enum.purs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/Enum.purs b/src/Test/QuickCheck/Laws/Data/Enum.purs index 492f2e4..7c6844c 100644 --- a/src/Test/QuickCheck/Laws/Data/Enum.purs +++ b/src/Test/QuickCheck/Laws/Data/Enum.purs @@ -51,8 +51,8 @@ checkEnum _ = do predRetractsSucc a = (succ a >>= pred >>= succ) == succ a nonSkippingSucc :: a -> a -> Boolean - nonSkippingSucc x y = y <= x || maybe false (_ <= y) (succ x) + nonSkippingSucc a b = b <= a || maybe false (_ <= b) (succ a) nonSkippingPred :: a -> a -> Boolean - nonSkippingPred x y = x <= y || maybe false (y <= _) (pred x) + nonSkippingPred a b = a <= b || maybe false (b <= _) (pred a) From f1a33bfa8e1ca949bee42653155cefaccb05f6eb Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 15 Nov 2016 23:03:17 +0100 Subject: [PATCH 05/15] Use pred/succ instead of arithmetic --- src/Test/QuickCheck/Laws/Data/BoundedEnum.purs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs b/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs index bc728a1..154d7b5 100644 --- a/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs +++ b/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs @@ -55,7 +55,6 @@ checkBoundedEnum p = do log "Checking 'tofromenum' law for BoundedEnum" quickCheck' 1000 tofromenumLaw - where c :: Int c = unwrap (cardinality :: Cardinality a) @@ -75,10 +74,10 @@ checkBoundedEnum p = do succpredLaw a = a == top || (succ a >>= pred) == Just a enumpredLaw :: a -> Boolean - enumpredLaw a = a == bottom || (fromEnum <$> pred a) == Just (fromEnum a - 1) - + enumpredLaw a = a == bottom || (fromEnum <$> pred a) == pred (fromEnum a) + enumsuccLaw :: a -> Boolean - enumsuccLaw a = a == top || (fromEnum <$> succ a) == Just (fromEnum a + 1) + enumsuccLaw a = a == top || (fromEnum <$> succ a) == succ (fromEnum a) compareLaw :: a -> a -> Boolean compareLaw a b = a `compare` b == fromEnum a `compare` fromEnum b From a311bef4b0dca0bfcab6befc6d302b5f58538910 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 22 Nov 2016 22:08:46 +0100 Subject: [PATCH 06/15] Don't call checkEnum from checkBoundedEnum --- src/Test/QuickCheck/Laws/Data/BoundedEnum.purs | 3 --- test/Test/Data/Either.purs | 1 + test/Test/Data/Maybe.purs | 1 + test/Test/Data/Ordering.purs | 1 + test/Test/Data/Tuple.purs | 1 + test/Test/Data/Unit.purs | 1 + test/Test/Prim/Boolean.purs | 1 + 7 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs b/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs index 154d7b5..2badf7d 100644 --- a/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs +++ b/src/Test/QuickCheck/Laws/Data/BoundedEnum.purs @@ -9,7 +9,6 @@ import Data.Maybe (Maybe(Just)) import Data.Newtype (unwrap) import Test.QuickCheck (QC, quickCheck') import Test.QuickCheck.Arbitrary (class Arbitrary) -import Test.QuickCheck.Laws.Data.Enum (checkEnum) import Type.Proxy (Proxy) @@ -29,8 +28,6 @@ checkBoundedEnum → QC eff Unit checkBoundedEnum p = do - checkEnum p - log "Checking 'succ' law for BoundedEnum" quickCheck' 1 succLaw diff --git a/test/Test/Data/Either.purs b/test/Test/Data/Either.purs index 63d77c9..19bc21a 100644 --- a/test/Test/Data/Either.purs +++ b/test/Test/Data/Either.purs @@ -15,6 +15,7 @@ checkEither = checkLaws "Either" do Data.checkEq prxEither Data.checkOrd prxEither Data.checkBounded prxEither + Data.checkEnum prxEither Data.checkBoundedEnum prxEither Data.checkFunctor prx2Either Data.checkFoldableFunctor prx2Either diff --git a/test/Test/Data/Maybe.purs b/test/Test/Data/Maybe.purs index 10ffcb3..0efa6be 100644 --- a/test/Test/Data/Maybe.purs +++ b/test/Test/Data/Maybe.purs @@ -15,6 +15,7 @@ checkMaybe = checkLaws "Maybe" do Data.checkEq prxMaybe Data.checkOrd prxMaybe Data.checkBounded prxMaybe + Data.checkEnum prxMaybe Data.checkBoundedEnum prxMaybe Data.checkSemigroup prxMaybe Data.checkMonoid prxMaybe diff --git a/test/Test/Data/Ordering.purs b/test/Test/Data/Ordering.purs index ea7c3b3..ff38e4e 100644 --- a/test/Test/Data/Ordering.purs +++ b/test/Test/Data/Ordering.purs @@ -12,6 +12,7 @@ checkOrdering = checkLaws "Ordering" do Data.checkEq prxOrdering Data.checkOrd prxOrdering Data.checkBounded prxOrdering + Data.checkEnum prxOrdering Data.checkBoundedEnum prxOrdering Data.checkSemigroup prxOrdering where diff --git a/test/Test/Data/Tuple.purs b/test/Test/Data/Tuple.purs index bd1fb8c..59caa8e 100644 --- a/test/Test/Data/Tuple.purs +++ b/test/Test/Data/Tuple.purs @@ -15,6 +15,7 @@ checkTuple = checkLaws "Tuple" do Data.checkEq prxTuple Data.checkOrd prxTuple Data.checkBounded prxTuple + Data.checkEnum prxTuple Data.checkBoundedEnum prxTuple Data.checkSemigroup prxTuple Data.checkMonoid prxTuple diff --git a/test/Test/Data/Unit.purs b/test/Test/Data/Unit.purs index 164f2dc..223f863 100644 --- a/test/Test/Data/Unit.purs +++ b/test/Test/Data/Unit.purs @@ -12,6 +12,7 @@ checkUnit = checkLaws "Unit" do Data.checkEq prxUnit Data.checkOrd prxUnit Data.checkBounded prxUnit + Data.checkEnum prxUnit Data.checkBoundedEnum prxUnit Data.checkSemigroup prxUnit Data.checkMonoid prxUnit diff --git a/test/Test/Prim/Boolean.purs b/test/Test/Prim/Boolean.purs index 3d9530e..80665b8 100644 --- a/test/Test/Prim/Boolean.purs +++ b/test/Test/Prim/Boolean.purs @@ -12,6 +12,7 @@ checkBoolean = checkLaws "Boolean" do Data.checkEq prxBoolean Data.checkOrd prxBoolean Data.checkBounded prxBoolean + Data.checkEnum prxBoolean Data.checkBoundedEnum prxBoolean Data.checkHeytingAlgebra prxBoolean Data.checkBooleanAlgebra prxBoolean From cf6ff0c86d10db635541872538a17372335417c0 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 3 Sep 2017 18:40:50 +0200 Subject: [PATCH 07/15] Detect overflow when checking submultiplicative euclidean function --- src/Test/QuickCheck/Laws/Data/EuclideanRing.purs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/EuclideanRing.purs b/src/Test/QuickCheck/Laws/Data/EuclideanRing.purs index 5ba2df3..92ea6ed 100644 --- a/src/Test/QuickCheck/Laws/Data/EuclideanRing.purs +++ b/src/Test/QuickCheck/Laws/Data/EuclideanRing.purs @@ -61,5 +61,10 @@ checkEuclideanRing _ = do submultiplicative ∷ a → a → Boolean submultiplicative a b - | a /= zero && b /= zero = degree a <= degree (a * b) - | otherwise = true + | a == zero || b == zero = true + | productOverflows a b = true + | otherwise = degree a <= degree (a * b) + + productOverflows :: a -> a -> Boolean + productOverflows a b = p / b /= a + where p = a * b From 4896982dd582a02de0e16446fa510ee46bcddfa3 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Thu, 23 Sep 2021 06:24:31 -0700 Subject: [PATCH 08/15] Update module names in imports; fix whitespace --- src/Test/QuickCheck/Laws/Data/Enum.purs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/Enum.purs b/src/Test/QuickCheck/Laws/Data/Enum.purs index a16ffa2..d3ae3cb 100644 --- a/src/Test/QuickCheck/Laws/Data/Enum.purs +++ b/src/Test/QuickCheck/Laws/Data/Enum.purs @@ -2,11 +2,13 @@ module Test.QuickCheck.Laws.Data.Enum where import Prelude -import Control.Monad.Eff.Console (log) + +import Effect.Console (log) +import Effect import Data.Enum (pred, succ, class Enum) import Data.Maybe (maybe) -import Test.QuickCheck (QC, quickCheck') -import Test.QuickCheck.Arbitrary (class Arbitrary) +import Test.QuickCheck (quickCheck') +import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary) import Type.Proxy (Proxy) checkEnum @@ -15,10 +17,9 @@ checkEnum ⇒ Enum a ⇒ Ord a ⇒ Proxy a - → QC eff Unit + → Effect Unit checkEnum _ = do - log "Checking 'Successor' law for Enum" quickCheck' 1000 successor @@ -37,7 +38,6 @@ checkEnum _ = do log "Checking 'Non-skipping pred' law for Enum" quickCheck' 1000 nonSkippingPred - where successor :: a -> Boolean @@ -57,4 +57,3 @@ checkEnum _ = do nonSkippingPred :: a -> a -> Boolean nonSkippingPred a b = a <= b || maybe false (b <= _) (pred a) - From b2ae0e6e6567efd641419f2cfaa783ee09133919 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Thu, 23 Sep 2021 06:27:10 -0700 Subject: [PATCH 09/15] Remove duplicate Enum instances --- src/Test/QuickCheck/Laws.purs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Test/QuickCheck/Laws.purs b/src/Test/QuickCheck/Laws.purs index a03d2e0..5877c2f 100644 --- a/src/Test/QuickCheck/Laws.purs +++ b/src/Test/QuickCheck/Laws.purs @@ -20,7 +20,6 @@ derive newtype instance boundedA ∷ Bounded A derive newtype instance enumA :: Enum A derive newtype instance boundedEnumA :: BoundedEnum A derive newtype instance coarbitraryA ∷ Coarbitrary A -derive newtype instance enumA ∷ Enum A derive newtype instance eqA ∷ Eq A derive newtype instance ordA ∷ Ord A derive newtype instance semigroupA ∷ Semigroup A @@ -33,7 +32,6 @@ derive newtype instance boundedB ∷ Bounded B derive newtype instance enumB :: Enum B derive newtype instance boundedEnumB :: BoundedEnum B derive newtype instance coarbitraryB ∷ Coarbitrary B -derive newtype instance enumB ∷ Enum B derive newtype instance eqB ∷ Eq B derive newtype instance ordB ∷ Ord B derive newtype instance semigroupB ∷ Semigroup B @@ -46,7 +44,6 @@ derive newtype instance boundedC ∷ Bounded C derive newtype instance enumC :: Enum C derive newtype instance boundedEnumC :: BoundedEnum C derive newtype instance coarbitraryC ∷ Coarbitrary C -derive newtype instance enumC ∷ Enum C derive newtype instance eqC ∷ Eq C derive newtype instance ordC ∷ Ord C derive newtype instance semigroupC ∷ Semigroup C @@ -59,7 +56,6 @@ derive newtype instance boundedD ∷ Bounded D derive newtype instance enumD :: Enum D derive newtype instance boundedEnumD :: BoundedEnum D derive newtype instance coarbitraryD ∷ Coarbitrary D -derive newtype instance enumD ∷ Enum D derive newtype instance eqD ∷ Eq D derive newtype instance ordD ∷ Ord D derive newtype instance semigroupD ∷ Semigroup D @@ -72,7 +68,6 @@ derive newtype instance boundedE ∷ Bounded E derive newtype instance enumE :: Enum E derive newtype instance boundedEnumE :: BoundedEnum E derive newtype instance coarbitraryE ∷ Coarbitrary E -derive newtype instance enumE ∷ Enum E derive newtype instance eqE ∷ Eq E derive newtype instance ordE ∷ Ord E derive newtype instance semigroupE ∷ Semigroup E From 16d262eafaf196dfecf998bbd8292309b0858fec Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Thu, 23 Sep 2021 06:27:57 -0700 Subject: [PATCH 10/15] Fix errors in Enum file --- src/Test/QuickCheck/Laws/Data/Enum.purs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/Enum.purs b/src/Test/QuickCheck/Laws/Data/Enum.purs index d3ae3cb..73348db 100644 --- a/src/Test/QuickCheck/Laws/Data/Enum.purs +++ b/src/Test/QuickCheck/Laws/Data/Enum.purs @@ -4,15 +4,15 @@ module Test.QuickCheck.Laws.Data.Enum where import Prelude import Effect.Console (log) -import Effect +import Effect (Effect) import Data.Enum (pred, succ, class Enum) import Data.Maybe (maybe) import Test.QuickCheck (quickCheck') -import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary) +import Test.QuickCheck.Arbitrary (class Arbitrary) import Type.Proxy (Proxy) checkEnum - ∷ ∀ eff a + ∷ ∀ a . Arbitrary a ⇒ Enum a ⇒ Ord a From b67b96ee057ad4b19ff4c71eec607313cf91b2aa Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Thu, 23 Sep 2021 06:34:08 -0700 Subject: [PATCH 11/15] Drop BoundedEnum check for Either --- test/Test/Data/Either.purs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Test/Data/Either.purs b/test/Test/Data/Either.purs index dc27363..855f0e4 100644 --- a/test/Test/Data/Either.purs +++ b/test/Test/Data/Either.purs @@ -15,7 +15,6 @@ checkEither = checkLaws "Either" do Data.checkOrd prxEither Data.checkBounded prxEither Data.checkEnum prxEither - Data.checkBoundedEnum prxEither Data.checkFunctor prx2Either Data.checkFunctorWithIndex prx2Either Data.checkFoldableFunctor prx2Either From da8ecf11f037284d98a99d8d30bc23f609de5a1d Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Thu, 23 Sep 2021 06:34:27 -0700 Subject: [PATCH 12/15] Drop BoundedEnum check for Maybe --- test/Test/Data/Maybe.purs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Test/Data/Maybe.purs b/test/Test/Data/Maybe.purs index 2e6637e..338e712 100644 --- a/test/Test/Data/Maybe.purs +++ b/test/Test/Data/Maybe.purs @@ -15,7 +15,6 @@ checkMaybe = checkLaws "Maybe" do Data.checkOrd prxMaybe Data.checkBounded prxMaybe Data.checkEnum prxMaybe - Data.checkBoundedEnum prxMaybe Data.checkSemigroup prxMaybe Data.checkMonoid prxMaybe Data.checkFunctor prx2Maybe From 20269058e110d3005d2e5eb611b39aacdd059dbd Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Thu, 23 Sep 2021 06:34:51 -0700 Subject: [PATCH 13/15] Drop BoundedEnum check for Tuple --- test/Test/Data/Tuple.purs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Test/Data/Tuple.purs b/test/Test/Data/Tuple.purs index 310e4a9..63752d6 100644 --- a/test/Test/Data/Tuple.purs +++ b/test/Test/Data/Tuple.purs @@ -14,8 +14,7 @@ checkTuple = checkLaws "Tuple" do Data.checkEq prxTuple Data.checkOrd prxTuple Data.checkBounded prxTuple - Data.checkEnum prxTuple - Data.checkBoundedEnum prxTuple + Data.checkEnum prxTuple Data.checkSemigroup prxTuple Data.checkMonoid prxTuple Data.checkFunctor prx2Tuple From 0fb9559da9f21de8a4b660a18df07d1d52ad61fe Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 27 Sep 2021 20:34:19 -0700 Subject: [PATCH 14/15] Add checkEnumGen --- src/Test/QuickCheck/Laws/Data.purs | 2 +- src/Test/QuickCheck/Laws/Data/Enum.purs | 28 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data.purs b/src/Test/QuickCheck/Laws/Data.purs index 6d82d27..4266bb5 100644 --- a/src/Test/QuickCheck/Laws/Data.purs +++ b/src/Test/QuickCheck/Laws/Data.purs @@ -3,7 +3,7 @@ module Test.QuickCheck.Laws.Data (module Exports) where import Test.QuickCheck.Laws.Data.BooleanAlgebra (checkBooleanAlgebra, checkBooleanAlgebraGen) as Exports import Test.QuickCheck.Laws.Data.Bounded (checkBounded, checkBoundedGen) as Exports import Test.QuickCheck.Laws.Data.CommutativeRing (checkCommutativeRing, checkCommutativeRingGen) as Exports -import Test.QuickCheck.Laws.Data.Enum (checkEnum) as Exports +import Test.QuickCheck.Laws.Data.Enum (checkEnum, checkEnumGen) as Exports import Test.QuickCheck.Laws.Data.Eq (checkEq, checkEqGen) as Exports import Test.QuickCheck.Laws.Data.BoundedEnum (checkBoundedEnum, checkBoundedEnumGen) as Exports import Test.QuickCheck.Laws.Data.EuclideanRing (checkEuclideanRing, checkEuclideanRingGen) as Exports diff --git a/src/Test/QuickCheck/Laws/Data/Enum.purs b/src/Test/QuickCheck/Laws/Data/Enum.purs index 73348db..a1afe47 100644 --- a/src/Test/QuickCheck/Laws/Data/Enum.purs +++ b/src/Test/QuickCheck/Laws/Data/Enum.purs @@ -3,12 +3,13 @@ module Test.QuickCheck.Laws.Data.Enum where import Prelude -import Effect.Console (log) -import Effect (Effect) 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) +import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary) +import Test.QuickCheck.Gen (Gen) import Type.Proxy (Proxy) checkEnum @@ -18,25 +19,32 @@ checkEnum ⇒ Ord a ⇒ Proxy a → Effect Unit -checkEnum _ = do +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 + quickCheck' 1000 $ successor <$> gen log "Checking 'Predecessor' law for Enum" - quickCheck' 1000 predecessor + quickCheck' 1000 $ predecessor <$> gen log "Checking 'Succ retracts pred' law for Enum" - quickCheck' 1000 succRetractsPred + quickCheck' 1000 $ succRetractsPred <$> gen log "Checking 'Pred retracts succ' law for Enum" - quickCheck' 1000 predRetractsSucc + quickCheck' 1000 $ predRetractsSucc <$> gen log "Checking 'Non-skipping succ' law for Enum" - quickCheck' 1000 nonSkippingSucc + quickCheck' 1000 $ nonSkippingSucc <$> gen <*> gen log "Checking 'Non-skipping pred' law for Enum" - quickCheck' 1000 nonSkippingPred + quickCheck' 1000 $ nonSkippingPred <$> gen <*> gen where From d49403d07f614434bcf21f25717ca436a748950e Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 27 Sep 2021 20:40:16 -0700 Subject: [PATCH 15/15] Revert EuclideanRing change --- src/Test/QuickCheck/Laws/Data/EuclideanRing.purs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Test/QuickCheck/Laws/Data/EuclideanRing.purs b/src/Test/QuickCheck/Laws/Data/EuclideanRing.purs index 9e155da..d1ee7f5 100644 --- a/src/Test/QuickCheck/Laws/Data/EuclideanRing.purs +++ b/src/Test/QuickCheck/Laws/Data/EuclideanRing.purs @@ -76,9 +76,4 @@ checkEuclideanRingGen gen = do submultiplicative ∷ a → a → Boolean submultiplicative a b | a == zero || b == zero = true - | productOverflows a b = true | otherwise = degree a <= degree (a * b) - - productOverflows :: a -> a -> Boolean - productOverflows a b = p / b /= a - where p = a * b