Repository navigation
Expand file tree
/
Copy pathMain.purs
More file actions
70 lines (57 loc) · 2.06 KB
/
Copy pathMain.purs
File metadata and controls
70 lines (57 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Test.Main where
import Prelude
import Data.HugeInt (HugeInt)
import Data.HugeInt as HI
import Data.HugeInt.Gen (genHugeInt)
import Data.HugeNum (HugeNum)
import Data.HugeNum as HN
import Data.HugeNum.Gen (genHugeNum)
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Console (log)
import Test.QuickCheck (class Arbitrary, quickCheck)
import Test.QuickCheck.Laws.Data.Eq (checkEq)
import Test.QuickCheck.Laws.Data.Ord (checkOrd)
import Test.QuickCheck.Laws.Data.Ring (checkRing)
import Test.QuickCheck.Laws.Data.Semiring (checkSemiring)
import Type.Proxy (Proxy(..))
-- | HugeNum Arbs
newtype ArbHugeNum = ArbHugeNum HugeNum
derive newtype instance eqArbHugeNum :: Eq ArbHugeNum
derive newtype instance ordArbHugeNum :: Ord ArbHugeNum
derive newtype instance semiringArbHugeNum :: Semiring ArbHugeNum
derive newtype instance ringArbHugeNum :: Ring ArbHugeNum
instance arbitraryArbHugeNum :: Arbitrary ArbHugeNum where
arbitrary = ArbHugeNum <$> genHugeNum
prxHugeNum :: Proxy ArbHugeNum
prxHugeNum = Proxy
-- | HugeInt Arbs
newtype ArbHugeInt = ArbHugeInt HugeInt
derive newtype instance eqArbHugeInt :: Eq ArbHugeInt
derive newtype instance ordArbHugeInt :: Ord ArbHugeInt
derive newtype instance semiringArbHugeInt :: Semiring ArbHugeInt
derive newtype instance ringArbHugeInt :: Ring ArbHugeInt
instance arbitraryArbHugeInt :: Arbitrary ArbHugeInt where
arbitrary = ArbHugeInt <$> genHugeInt
prxHugeInt :: Proxy ArbHugeInt
prxHugeInt = Proxy
main :: Effect Unit
main = do
log "Checking HugeNum instances...\n"
checkEq prxHugeNum
checkOrd prxHugeNum
checkSemiring prxHugeNum
checkRing prxHugeNum
log "Checking HugeInt instances...\n"
checkEq prxHugeInt
checkOrd prxHugeInt
checkSemiring prxHugeInt
checkRing prxHugeInt
log "Checking from/to Num...\n"
quickCheck toFromNumIsIdentity
log "Checking from/to Int...\n"
quickCheck toFromIntIsIdentity
toFromNumIsIdentity :: Number -> Boolean
toFromNumIsIdentity n = HN.toNumber (HN.fromNumber n) == n
toFromIntIsIdentity :: Int -> Boolean
toFromIntIsIdentity n = HI.toInt (HI.fromInt n) == Just n