Skip to content
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

Euclideanring overflow #30

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Test/QuickCheck/Laws.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module Test.QuickCheck.Laws
) where

import Prelude

import Control.Monad.Eff.Console (log)
import Data.Enum (class BoundedEnum)
import Data.Enum (class BoundedEnum, class Enum)
import Data.Monoid (class Monoid)
import Test.QuickCheck (QC)
import Test.QuickCheck.Arbitrary (class Arbitrary, class Coarbitrary)
Expand All @@ -21,6 +22,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
Expand All @@ -32,6 +34,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
Expand All @@ -43,6 +46,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
Expand All @@ -54,6 +58,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
Expand All @@ -65,6 +70,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
Expand Down
8 changes: 6 additions & 2 deletions src/Test/QuickCheck/Laws/Data/EuclideanRing.purs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@ 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 = a * b / b /= a