@@ -5,18 +5,19 @@ import Prelude
55import Effect (Effect )
66import Effect.Console (log )
77
8- import Data.Ratio ((%))
9- import Data.Rational ( Rational )
8+ import Data.Ratio (Ratio , (%))
9+ import Data.BigInt ( BigInt , fromInt )
1010
11- import Test.StrongCheck (Result , quickCheck' , (===))
12- import Test.StrongCheck.Arbitrary (class Arbitrary )
13- import Test.StrongCheck.Gen (Gen , chooseInt , suchThat )
14- import Test.StrongCheck.Laws (checkLaws )
15- import Test.StrongCheck.Laws.Data as Data
11+ import Test.QuickCheck (Result , quickCheck' , (===))
12+ import Test.QuickCheck.Arbitrary (class Arbitrary , arbitrary )
13+ import Test.QuickCheck.Gen (Gen , suchThat )
14+ import Test.QuickCheck.Laws (checkLaws )
15+ import Test.QuickCheck.Laws.Data as Data
16+ import Test.QuickCheck.Laws.Data.Field (checkField ) as DataField
1617
1718import Type.Proxy (Proxy (Proxy))
1819
19- newtype TestRational = TestRational Rational
20+ newtype TestRational = TestRational ( Ratio BigInt )
2021
2122derive newtype instance commutativeRingTestRational :: CommutativeRing TestRational
2223derive newtype instance eqTestRational :: Eq TestRational
@@ -26,29 +27,24 @@ derive newtype instance ringTestRational :: Ring TestRational
2627derive newtype instance semiringTestRational :: Semiring TestRational
2728derive newtype instance divisionRingTestRational :: DivisionRing TestRational
2829
29- int :: Gen Int
30- int = chooseInt (- 999 ) 999
30+ bigint :: Gen BigInt
31+ bigint = fromInt <$> arbitrary
3132
32- nonZeroInt :: Gen Int
33- nonZeroInt = int `suchThat` notEq 0
33+ nonZeroBigInt :: Gen BigInt
34+ nonZeroBigInt = bigint `suchThat` notEq (fromInt 0 )
3435
35- newtype SmallInt = SmallInt Int
36+ newtype NonZeroBigInt = NonZeroBigInt BigInt
3637
37- instance arbitrarySmallInt :: Arbitrary SmallInt where
38- arbitrary = SmallInt <$> int
39-
40- newtype NonZeroInt = NonZeroInt Int
41-
42- instance arbitraryNonZeroInt :: Arbitrary NonZeroInt where
43- arbitrary = NonZeroInt <$> nonZeroInt
38+ instance arbitraryNonZeroBigInt :: Arbitrary NonZeroBigInt where
39+ arbitrary = NonZeroBigInt <$> nonZeroBigInt
4440
4541instance arbitraryTestRational :: Arbitrary TestRational where
46- arbitrary = compose TestRational <<< (%) <$> int <*> nonZeroInt
42+ arbitrary = compose TestRational <<< (%) <$> bigint <*> nonZeroBigInt
4743
4844testRational :: Proxy TestRational
4945testRational = Proxy
5046
51- newtype TestRatNonZero = TestRatNonZero Rational
47+ newtype TestRatNonZero = TestRatNonZero ( Ratio BigInt )
5248
5349derive newtype instance eqTestRatNonZero :: Eq TestRatNonZero
5450derive newtype instance semiringTestRatNonZero :: Semiring TestRatNonZero
@@ -58,7 +54,7 @@ derive newtype instance euclideanRingTestRatNonZero :: EuclideanRing TestRatNonZ
5854derive newtype instance divisionRingTestRatNonZero :: DivisionRing TestRatNonZero
5955
6056instance arbitraryTestRatNonZero :: Arbitrary TestRatNonZero where
61- arbitrary = compose TestRatNonZero <<< (%) <$> nonZeroInt <*> nonZeroInt
57+ arbitrary = compose TestRatNonZero <<< (%) <$> nonZeroBigInt <*> nonZeroBigInt
6258
6359testRatNonZero :: Proxy TestRatNonZero
6460testRatNonZero = Proxy
@@ -67,10 +63,10 @@ main :: Effect Unit
6763main = checkLaws " Rational" do
6864 Data .checkEq testRational
6965 Data .checkOrd testRational
70- Data .checkSemiring testRational
66+ Data .checkSemiring testRational
7167 Data .checkRing testRational
7268 Data .checkCommutativeRing testRational
73- Data .checkField testRational
69+ DataField .checkField testRational
7470 Data .checkEuclideanRing testRatNonZero
7571 Data .checkDivisionRing testRational
7672 Data .checkDivisionRing testRatNonZero
@@ -86,6 +82,6 @@ main = checkLaws "Rational" do
8682 remainder :: TestRatNonZero -> TestRatNonZero -> Result
8783 remainder (TestRatNonZero a) (TestRatNonZero b) = a / b * b + (a `mod` b) === a
8884
89- reducing :: NonZeroInt -> NonZeroInt -> SmallInt -> NonZeroInt -> Result
90- reducing (NonZeroInt a) (NonZeroInt b) (SmallInt n) (NonZeroInt d)
85+ reducing :: NonZeroBigInt -> NonZeroBigInt -> NonZeroBigInt -> NonZeroBigInt -> Result
86+ reducing (NonZeroBigInt a) (NonZeroBigInt b) (NonZeroBigInt n) (NonZeroBigInt d)
9187 = (a * n) % (a * d) === (b * n) % (b * d)
0 commit comments