@@ -33,6 +33,7 @@ runSmallInt (SmallInt n) = n
33
33
34
34
-- | Arbitrary instance for BigInt
35
35
newtype TestBigInt = TestBigInt BigInt
36
+
36
37
derive newtype instance eqTestBigInt :: Eq TestBigInt
37
38
derive newtype instance ordTestBigInt :: Ord TestBigInt
38
39
derive newtype instance semiringTestBigInt :: Semiring TestBigInt
@@ -43,21 +44,24 @@ derive newtype instance euclideanRingTestBigInt :: EuclideanRing TestBigInt
43
44
instance arbitraryBigInt :: Arbitrary TestBigInt where
44
45
arbitrary = do
45
46
n <- (fromMaybe zero <<< fromString) <$> digitString
46
- op <- elements (cons' identity [negate])
47
+ op <- elements (cons' identity [ negate ])
47
48
pure (TestBigInt (op n))
48
- where digits :: Gen Int
49
- digits = chooseInt 0 9
50
- digitString :: Gen String
51
- digitString = (fold <<< map show) <$> (resize 50 $ arrayOf digits)
49
+ where
50
+ digits :: Gen Int
51
+ digits = chooseInt 0 9
52
+
53
+ digitString :: Gen String
54
+ digitString = (fold <<< map show) <$> (resize 50 $ arrayOf digits)
52
55
53
56
-- | Convert SmallInt to BigInt
54
57
fromSmallInt :: SmallInt -> BigInt
55
58
fromSmallInt = fromInt <<< runSmallInt
56
59
57
60
-- | Test if a binary relation holds before and after converting to BigInt.
58
- testBinary :: (BigInt -> BigInt -> BigInt )
59
- -> (Int -> Int -> Int )
60
- -> Effect Unit
61
+ testBinary
62
+ :: (BigInt -> BigInt -> BigInt )
63
+ -> (Int -> Int -> Int )
64
+ -> Effect Unit
61
65
testBinary f g = quickCheck (\x y -> (fromInt x) `f` (fromInt y) == fromInt (x `g` y))
62
66
63
67
main :: Effect Unit
@@ -89,16 +93,18 @@ main = do
89
93
assert $ toString (fromInt 12345 ) == " 12345"
90
94
91
95
log " Converting bigints to arrays with a different base"
92
- assert $ NEA .toArray (digitsInBase 2 four).value == [1 , 0 , 0 ]
93
- assert $ (NEA .toArray <<< _.value <<< digitsInBase 16 <$>
94
- fromString " 255" ) == Just [15 , 15 ]
96
+ assert $ NEA .toArray (digitsInBase 2 four).value == [ 1 , 0 , 0 ]
97
+ assert $
98
+ ( NEA .toArray <<< _.value <<< digitsInBase 16 <$>
99
+ fromString " 255"
100
+ ) == Just [ 15 , 15 ]
95
101
assert $ NEA .toArray (digitsInBase 10 $ fromInt 12345 ).value
96
- == [1 , 2 , 3 , 4 , 5 ]
102
+ == [ 1 , 2 , 3 , 4 , 5 ]
97
103
98
104
assert $ toBase' 2 four == unsafePartial unsafeFromString " 100"
99
105
assert $ (toBase' 16 <$> fromString " 255" ) == NES .fromString " ff"
100
106
assert $ toNonEmptyString (fromInt 12345 )
101
- == unsafePartial unsafeFromString " 12345"
107
+ == unsafePartial unsafeFromString " 12345"
102
108
103
109
log " Converting from Number to BigInt"
104
110
assert $ fromNumber 0.0 == Just zero
@@ -140,7 +146,7 @@ main = do
140
146
assert $ zero `pow` zero == one
141
147
142
148
log " Prime numbers"
143
- assert $ filter (prime <<< fromInt) (range 2 20 ) == [2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 ]
149
+ assert $ filter (prime <<< fromInt) (range 2 20 ) == [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 ]
144
150
145
151
log " Absolute value"
146
152
quickCheck $ \(TestBigInt x) -> abs x == if x > zero then x else (-x)
@@ -178,12 +184,15 @@ main = do
178
184
assert $ (fromString " -2147483649" >>= toInt) == Nothing
179
185
assert $ (fromString " 921231231322337203685124775809" >>= toInt) == Nothing
180
186
assert $ (fromString " -922337203612312312312854775809" >>= toInt) == Nothing
181
- quickCheck (\a b c ->
182
- let x = add (fromInt a) (add (fromInt b) (fromInt c))
183
- in case toInt x of
184
- Nothing -> x < fromInt (-2147483648 ) || x > fromInt 2147483647
185
- Just i -> fromInt i == x
186
- )
187
+ quickCheck
188
+ ( \a b c ->
189
+ let
190
+ x = add (fromInt a) (add (fromInt b) (fromInt c))
191
+ in
192
+ case toInt x of
193
+ Nothing -> x < fromInt (-2147483648 ) || x > fromInt 2147483647
194
+ Just i -> fromInt i == x
195
+ )
187
196
188
197
log " Type Level Int creation"
189
198
assert $ toString (fromTLInt (Proxy :: Proxy 921231231322337203685124775809)) == " 921231231322337203685124775809"
0 commit comments