Skip to content

Commit a0851b8

Browse files
committed
Updates for purescript 0.7.4
1 parent ce2fe22 commit a0851b8

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

bower.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "purescript-bigints",
3-
"version": "0.1.0",
43
"description": "Arbitrary length integers",
54
"homepage": "https://github.com/sharkdp/purescript-bigints",
65
"authors": [
@@ -26,6 +25,6 @@
2625
"purescript-integers": "^0.2.1",
2726
"purescript-console": "^0.1.0",
2827
"purescript-assert": "^0.1.1",
29-
"purescript-quickcheck": "^0.7.0"
28+
"purescript-quickcheck": "^0.11.0"
3029
}
3130
}

src/Data/BigInt.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ foreign import biCompare :: BigInt -> BigInt -> Int
8282

8383
instance ordBigInt :: Ord BigInt where
8484
compare x y = case biCompare x y of
85-
1 -> GT
86-
0 -> EQ
87-
-1 -> LT
85+
1 -> GT
86+
0 -> EQ
87+
_ -> LT
8888

8989
-- | A decimal representation of the `BigInt` as a `String`.
9090
foreign import toString :: BigInt -> String

test/Main.purs

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import Data.Foldable (mconcat)
88
import Data.Maybe (Maybe(..))
99
import Data.Maybe.Unsafe (fromJust)
1010
import Test.Assert (assert)
11-
import Test.QuickCheck (quickCheck)
11+
import Test.QuickCheck (QC(), quickCheck)
1212
import Test.QuickCheck.Arbitrary (Arbitrary)
13-
import Test.QuickCheck.Gen (Gen(..), chooseInt, arrayOf, elements)
13+
import Test.QuickCheck.Gen (Gen(), chooseInt, arrayOf, elements)
1414
import qualified Data.Int as Int
1515

1616
-- | Newtype with an Arbitrary instance that generates only small integers
@@ -23,11 +23,13 @@ runSmallInt :: SmallInt -> Int
2323
runSmallInt (SmallInt n) = n
2424

2525
-- | Arbitrary instance for BigInt
26-
instance arbitraryBigInt :: Arbitrary BigInt where
26+
newtype TestBigInt = TestBigInt BigInt
27+
28+
instance arbitraryBigInt :: Arbitrary TestBigInt where
2729
arbitrary = do
2830
n <- (fromJust <<< fromString) <$> digitString
2931
op <- elements id [negate]
30-
return (op n)
32+
return (TestBigInt (op n))
3133
where digits :: Gen Int
3234
digits = chooseInt 0 9
3335
digitString :: Gen String
@@ -38,9 +40,9 @@ fromSmallInt :: SmallInt -> BigInt
3840
fromSmallInt = fromInt <<< runSmallInt
3941

4042
-- | Test if a binary relation holds before and after converting to BigInt.
41-
testBinary :: (BigInt -> BigInt -> BigInt)
43+
testBinary :: forall eff. (BigInt -> BigInt -> BigInt)
4244
-> (Int -> Int -> Int)
43-
-> _
45+
-> QC eff Unit
4446
testBinary f g = quickCheck (\x y -> (fromInt x) `f` (fromInt y) == fromInt (x `g` y))
4547

4648
main = do
@@ -59,7 +61,7 @@ main = do
5961
assert $ fromString "2.1" == Nothing
6062
assert $ fromString "123456789" == Just (fromInt 123456789)
6163
assert $ fromString "1e7" == Just (fromInt 10000000)
62-
quickCheck $ \a -> (fromString <<< toString) a == Just a
64+
quickCheck $ \(TestBigInt a) -> (fromString <<< toString) a == Just a
6365

6466
log "Parsing strings with a different base"
6567
assert $ fromBase 2 "100" == Just four
@@ -98,4 +100,4 @@ main = do
98100
assert $ filter (prime <<< fromInt) (range 2 20) == [2, 3, 5, 7, 11, 13, 17, 19]
99101

100102
log "Absolute value"
101-
quickCheck $ \x -> abs x == if x > zero then x else (-x)
103+
quickCheck $ \(TestBigInt x) -> abs x == if x > zero then x else (-x)

0 commit comments

Comments
 (0)