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

Fix integer overflow test with Ints #58

Merged
merged 4 commits into from
Sep 27, 2021
Merged

Conversation

JordanMartinez
Copy link
Contributor

Description of the change

Fixes #30.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

Comment on lines 12 to 13
-- | Necessary for the EuclideanRing test
-- | so as to prevent integer overflow when multiplying large integer values
Copy link
Contributor

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 to EuclideanRing other than that we're using it in a test for it.

Copy link
Contributor Author

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.

Comment on lines 20 to 22
instance arbitraryEuclideanRingInt :: Arbitrary EuclideanRingInt where
arbitrary = do
EuclideanRingInt <$> chooseInt (-10_000) 10_000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
instance arbitraryEuclideanRingInt :: Arbitrary EuclideanRingInt where
arbitrary = do
EuclideanRingInt <$> chooseInt (-10_000) 10_000
instance arbitraryEuclideanRingInt :: Arbitrary EuclideanRingInt where
arbitrary = EuclideanRingInt <$> chooseInt (-10_000) 10_000

Is there a reason for -10_000 to 10_000 specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number.MAX_SAFE_INTEGER is 9007199254740991. I figured 10k was a large enough range to test without being too large to produce the overflow.

@JordanMartinez JordanMartinez merged commit b09ef8c into main Sep 27, 2021
@JordanMartinez JordanMartinez deleted the fixEuclideanRingTest branch September 27, 2021 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants