11module Test.Main where
22
33import Prelude
4- import Control.Monad.Eff.Console (log )
4+ import Control.Monad.Eff (Eff )
5+ import Control.Monad.Eff.Console (CONSOLE , log )
56import Data.Array (filter , range )
6- import Data.BigInt
7- import Data.Foldable (mconcat )
8- import Data.Maybe (Maybe (..))
9- import Data.Maybe.Unsafe (fromJust )
10- import Test.Assert (assert )
7+ import Data.BigInt (BigInt , abs , fromInt , prime , pow , odd , even , fromString ,
8+ toNumber , fromBase , toString )
9+ import Data.Foldable (fold )
10+ import Data.Maybe (Maybe (..), fromMaybe )
11+ import Test.Assert (ASSERT , assert )
12+ import Control.Monad.Eff.Random (RANDOM ())
13+ import Control.Monad.Eff.Exception (EXCEPTION ())
1114import Test.QuickCheck (QC (), quickCheck )
12- import Test.QuickCheck.Arbitrary (Arbitrary )
15+ import Test.QuickCheck.Arbitrary (class Arbitrary )
1316import Test.QuickCheck.Gen (Gen (), chooseInt , arrayOf , elements )
14- import qualified Data.Int as Int
17+ import Data.Int as Int
1518
1619-- | Newtype with an Arbitrary instance that generates only small integers
1720newtype SmallInt = SmallInt Int
@@ -27,13 +30,13 @@ newtype TestBigInt = TestBigInt BigInt
2730
2831instance arbitraryBigInt :: Arbitrary TestBigInt where
2932 arbitrary = do
30- n <- (fromJust <<< fromString) <$> digitString
33+ n <- (fromMaybe zero <<< fromString) <$> digitString
3134 op <- elements id [negate]
32- return (TestBigInt (op n))
35+ pure (TestBigInt (op n))
3336 where digits :: Gen Int
3437 digits = chooseInt 0 9
3538 digitString :: Gen String
36- digitString = (mconcat <<< map show) <$> arrayOf digits
39+ digitString = (fold <<< map show) <$> arrayOf digits
3740
3841-- | Convert SmallInt to BigInt
3942fromSmallInt :: SmallInt -> BigInt
@@ -45,6 +48,7 @@ testBinary :: forall eff. (BigInt -> BigInt -> BigInt)
4548 -> QC eff Unit
4649testBinary f g = quickCheck (\x y -> (fromInt x) `f` (fromInt y) == fromInt (x `g` y))
4750
51+ main :: forall eff . Eff (console :: CONSOLE , assert :: ASSERT , random :: RANDOM , err :: EXCEPTION | eff ) Unit
4852main = do
4953 log " Simple arithmetic operations and conversions from Int"
5054 let two = one + one
0 commit comments