@@ -5,7 +5,7 @@ import Control.Monad.Eff.Console (CONSOLE, log)
5
5
import Control.Monad.Eff.Exception (EXCEPTION )
6
6
import Control.Monad.Eff.Random (RANDOM )
7
7
import Data.Array (filter , range )
8
- import Data.BigInt (BigInt , abs , fromInt , prime , pow , odd , even , fromString , toNumber , fromBase , toString , not , or , xor , and , shl , shr )
8
+ import Data.BigInt (BigInt , abs , fromInt , prime , pow , odd , even , fromString , toNumber , fromBase , toBase , toString , not , or , xor , and , shl , shr )
9
9
import Data.Foldable (fold )
10
10
import Data.Int as Int
11
11
import Data.Maybe (Maybe (..), fromMaybe )
@@ -31,10 +31,10 @@ runSmallInt (SmallInt n) = n
31
31
-- | Arbitrary instance for BigInt
32
32
newtype TestBigInt = TestBigInt BigInt
33
33
derive newtype instance eqTestBigInt :: Eq TestBigInt
34
- derive newtype instance ordTestBigInt :: Ord TestBigInt
34
+ derive newtype instance ordTestBigInt :: Ord TestBigInt
35
35
derive newtype instance semiringTestBigInt :: Semiring TestBigInt
36
36
derive newtype instance ringTestBigInt :: Ring TestBigInt
37
- derive newtype instance commutativeRingTestBigInt :: CommutativeRing TestBigInt
37
+ derive newtype instance commutativeRingTestBigInt :: CommutativeRing TestBigInt
38
38
derive newtype instance euclideanRingTestBigInt :: EuclideanRing TestBigInt
39
39
40
40
instance arbitraryBigInt :: Arbitrary TestBigInt where
@@ -80,6 +80,11 @@ main = do
80
80
assert $ fromBase 2 " 100" == Just four
81
81
assert $ fromBase 16 " ff" == fromString " 255"
82
82
83
+ log " Rendering bigints as strings with a different base"
84
+ assert $ toBase 2 four == " 100"
85
+ assert $ (toBase 16 <$> fromString " 255" ) == Just " ff"
86
+ assert $ toString (fromInt 12345 ) == " 12345"
87
+
83
88
log " Conversions between String, Int and BigInt should not loose precision"
84
89
quickCheck (\n -> fromString (show n) == Just (fromInt n))
85
90
quickCheck (\n -> Int .toNumber n == toNumber (fromInt n))
@@ -124,12 +129,11 @@ main = do
124
129
log " Shifting"
125
130
assert $ shl two one == four
126
131
assert $ shr two one == one
127
-
132
+
128
133
let prxBigInt = Proxy ∷ Proxy TestBigInt
129
134
Data .checkEq prxBigInt
130
135
Data .checkOrd prxBigInt
131
- Data .checkSemiring prxBigInt
136
+ Data .checkSemiring prxBigInt
132
137
Data .checkRing prxBigInt
133
- -- Data.checkEuclideanRing prxBigInt
138
+ -- Data.checkEuclideanRing prxBigInt
134
139
Data .checkCommutativeRing prxBigInt
135
-
0 commit comments