-
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
Fix integer overflow test with Ints #58
Changes from 2 commits
db8c0ba
d7b4bb0
3e1b616
78e5561
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,17 +3,32 @@ module Test.Prim.Int where | |||||||||||
import Prelude | ||||||||||||
|
||||||||||||
import Effect (Effect) | ||||||||||||
import Test.QuickCheck (class Arbitrary) | ||||||||||||
import Test.QuickCheck.Gen (chooseInt) | ||||||||||||
import Test.QuickCheck.Laws (checkLaws) | ||||||||||||
import Test.QuickCheck.Laws.Data as Data | ||||||||||||
import Type.Proxy (Proxy(..)) | ||||||||||||
|
||||||||||||
-- | Necessary for the EuclideanRing test | ||||||||||||
-- | so as to prevent integer overflow when multiplying large integer values | ||||||||||||
newtype EuclideanRingInt = EuclideanRingInt Int | ||||||||||||
derive newtype instance eqEuclideanRingInt :: Eq EuclideanRingInt | ||||||||||||
derive newtype instance semiringEuclideanRingInt :: Semiring EuclideanRingInt | ||||||||||||
derive newtype instance ringEuclideanRingInt :: Ring EuclideanRingInt | ||||||||||||
derive newtype instance commutativeRingEuclideanRingInt :: CommutativeRing EuclideanRingInt | ||||||||||||
derive newtype instance euclideanRingEuclideanRingInt :: EuclideanRing EuclideanRingInt | ||||||||||||
instance arbitraryEuclideanRingInt :: Arbitrary EuclideanRingInt where | ||||||||||||
arbitrary = do | ||||||||||||
EuclideanRingInt <$> chooseInt (-10_000) 10_000 | ||||||||||||
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.
Suggested change
Is there a reason for 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. Number.MAX_SAFE_INTEGER is |
||||||||||||
|
||||||||||||
checkInt ∷ Effect Unit | ||||||||||||
checkInt = checkLaws "Int" do | ||||||||||||
Data.checkEq prxInt | ||||||||||||
Data.checkOrd prxInt | ||||||||||||
Data.checkCommutativeRing prxInt | ||||||||||||
Data.checkSemiring prxInt | ||||||||||||
Data.checkEuclideanRing prxInt | ||||||||||||
Data.checkEuclideanRing prxEuclideanRingInt | ||||||||||||
Data.checkRing prxInt | ||||||||||||
where | ||||||||||||
prxInt = Proxy ∷ Proxy Int | ||||||||||||
prxEuclideanRingInt = Proxy ∷ Proxy EuclideanRingInt |
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.
What do you think of naming this
SmallInt
instead, usable to avoid overflows when testing large integer values? It doesn't seem specific toEuclideanRing
other than that we're using it in a test for it.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.
Now that #57 is in, this could be refactored to use the
gen
version and not even need this newtype.