11module Test.Main where
22
3- import Prelude hiding (not )
43import Control.Monad.Eff (Eff )
54import Control.Monad.Eff.Console (CONSOLE , log )
5+ import Control.Monad.Eff.Exception (EXCEPTION )
6+ import Control.Monad.Eff.Random (RANDOM )
67import Data.Array (filter , range )
7- import Data.BigInt (BigInt , abs , fromInt , prime , pow , odd , even , fromString ,
8- toNumber , fromBase , toString , not , or , xor , and , shl , shr )
8+ import Data.BigInt (BigInt , abs , fromInt , prime , pow , odd , even , fromString , toNumber , fromBase , toString , not , or , xor , and , shl , shr )
99import Data.Foldable (fold )
10+ import Data.Int as Int
1011import Data.Maybe (Maybe (..), fromMaybe )
1112import Data.NonEmpty ((:|))
13+ import Prelude hiding (not )
1214import Test.Assert (ASSERT , assert )
13- import Control.Monad.Eff.Random (RANDOM ())
14- import Control.Monad.Eff.Exception (EXCEPTION ())
15- import Test.QuickCheck (QC (), quickCheck )
15+ import Test.QuickCheck (QC , quickCheck )
1616import Test.QuickCheck.Arbitrary (class Arbitrary )
17- import Test.QuickCheck.Gen (Gen (), chooseInt , arrayOf , elements )
18- import Data.Int as Int
17+ import Test.QuickCheck.Gen (Gen , arrayOf , chooseInt , elements , resize )
18+ import Test.QuickCheck.Laws.Data as Data
19+ import Type.Proxy (Proxy (..))
20+
1921
2022-- | Newtype with an Arbitrary instance that generates only small integers
2123newtype SmallInt = SmallInt Int
@@ -28,6 +30,12 @@ runSmallInt (SmallInt n) = n
2830
2931-- | Arbitrary instance for BigInt
3032newtype TestBigInt = TestBigInt BigInt
33+ derive newtype instance eqTestBigInt :: Eq TestBigInt
34+ derive newtype instance ordTestBigInt :: Ord TestBigInt
35+ derive newtype instance semiringTestBigInt :: Semiring TestBigInt
36+ derive newtype instance ringTestBigInt :: Ring TestBigInt
37+ derive newtype instance commutativeRingTestBigInt :: CommutativeRing TestBigInt
38+ derive newtype instance euclideanRingTestBigInt :: EuclideanRing TestBigInt
3139
3240instance arbitraryBigInt :: Arbitrary TestBigInt where
3341 arbitrary = do
@@ -37,7 +45,7 @@ instance arbitraryBigInt :: Arbitrary TestBigInt where
3745 where digits :: Gen Int
3846 digits = chooseInt 0 9
3947 digitString :: Gen String
40- digitString = (fold <<< map show) <$> arrayOf digits
48+ digitString = (fold <<< map show) <$> (resize 50 $ arrayOf digits)
4149
4250-- | Convert SmallInt to BigInt
4351fromSmallInt :: SmallInt -> BigInt
@@ -116,3 +124,12 @@ main = do
116124 log " Shifting"
117125 assert $ shl two one == four
118126 assert $ shr two one == one
127+
128+ let prxBigInt = Proxy ∷ Proxy TestBigInt
129+ Data .checkEq prxBigInt
130+ Data .checkOrd prxBigInt
131+ Data .checkSemiring prxBigInt
132+ Data .checkRing prxBigInt
133+ -- Data.checkEuclideanRing prxBigInt
134+ Data .checkCommutativeRing prxBigInt
135+
0 commit comments