1
1
module Test.Main where
2
2
3
3
import Prelude
4
- import Control.Monad.Eff.Console (log )
4
+ import Control.Monad.Eff (Eff )
5
+ import Control.Monad.Eff.Console (CONSOLE , log )
5
6
import 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 ())
11
14
import Test.QuickCheck (QC (), quickCheck )
12
- import Test.QuickCheck.Arbitrary (Arbitrary )
15
+ import Test.QuickCheck.Arbitrary (class Arbitrary )
13
16
import Test.QuickCheck.Gen (Gen (), chooseInt , arrayOf , elements )
14
- import qualified Data.Int as Int
17
+ import Data.Int as Int
15
18
16
19
-- | Newtype with an Arbitrary instance that generates only small integers
17
20
newtype SmallInt = SmallInt Int
@@ -27,13 +30,13 @@ newtype TestBigInt = TestBigInt BigInt
27
30
28
31
instance arbitraryBigInt :: Arbitrary TestBigInt where
29
32
arbitrary = do
30
- n <- (fromJust <<< fromString) <$> digitString
33
+ n <- (fromMaybe zero <<< fromString) <$> digitString
31
34
op <- elements id [negate]
32
- return (TestBigInt (op n))
35
+ pure (TestBigInt (op n))
33
36
where digits :: Gen Int
34
37
digits = chooseInt 0 9
35
38
digitString :: Gen String
36
- digitString = (mconcat <<< map show) <$> arrayOf digits
39
+ digitString = (fold <<< map show) <$> arrayOf digits
37
40
38
41
-- | Convert SmallInt to BigInt
39
42
fromSmallInt :: SmallInt -> BigInt
@@ -45,6 +48,7 @@ testBinary :: forall eff. (BigInt -> BigInt -> BigInt)
45
48
-> QC eff Unit
46
49
testBinary f g = quickCheck (\x y -> (fromInt x) `f` (fromInt y) == fromInt (x `g` y))
47
50
51
+ main :: forall eff . Eff (console :: CONSOLE , assert :: ASSERT , random :: RANDOM , err :: EXCEPTION | eff ) Unit
48
52
main = do
49
53
log " Simple arithmetic operations and conversions from Int"
50
54
let two = one + one
0 commit comments