@@ -5,7 +5,7 @@ import Control.Monad.Eff.Console (CONSOLE, log)
55import Control.Monad.Eff.Exception (EXCEPTION )
66import Control.Monad.Eff.Random (RANDOM )
77import 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 )
99import Data.Foldable (fold )
1010import Data.Int as Int
1111import Data.Maybe (Maybe (..), fromMaybe )
@@ -31,10 +31,10 @@ runSmallInt (SmallInt n) = n
3131-- | Arbitrary instance for BigInt
3232newtype TestBigInt = TestBigInt BigInt
3333derive newtype instance eqTestBigInt :: Eq TestBigInt
34- derive newtype instance ordTestBigInt :: Ord TestBigInt
34+ derive newtype instance ordTestBigInt :: Ord TestBigInt
3535derive newtype instance semiringTestBigInt :: Semiring TestBigInt
3636derive newtype instance ringTestBigInt :: Ring TestBigInt
37- derive newtype instance commutativeRingTestBigInt :: CommutativeRing TestBigInt
37+ derive newtype instance commutativeRingTestBigInt :: CommutativeRing TestBigInt
3838derive newtype instance euclideanRingTestBigInt :: EuclideanRing TestBigInt
3939
4040instance arbitraryBigInt :: Arbitrary TestBigInt where
@@ -80,6 +80,11 @@ main = do
8080 assert $ fromBase 2 " 100" == Just four
8181 assert $ fromBase 16 " ff" == fromString " 255"
8282
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+
8388 log " Conversions between String, Int and BigInt should not loose precision"
8489 quickCheck (\n -> fromString (show n) == Just (fromInt n))
8590 quickCheck (\n -> Int .toNumber n == toNumber (fromInt n))
@@ -124,12 +129,11 @@ main = do
124129 log " Shifting"
125130 assert $ shl two one == four
126131 assert $ shr two one == one
127-
132+
128133 let prxBigInt = Proxy ∷ Proxy TestBigInt
129134 Data .checkEq prxBigInt
130135 Data .checkOrd prxBigInt
131- Data .checkSemiring prxBigInt
136+ Data .checkSemiring prxBigInt
132137 Data .checkRing prxBigInt
133- -- Data.checkEuclideanRing prxBigInt
138+ -- Data.checkEuclideanRing prxBigInt
134139 Data .checkCommutativeRing prxBigInt
135-
0 commit comments