@@ -0,0 +1,78 @@
5+import Data.Fixed (class KnownPrecision, Fixed, PProxy, fromNumber, reifyPrecision)
6+import Data.Maybe (Maybe, fromJust, isJust)
8+import Effect.Console (log)
9+import Partial.Unsafe (unsafePartial)
10+import Test.QuickCheck (arbitrary, quickCheck', (<?>))
11+import Test.QuickCheck.Gen (Gen, chooseInt, suchThat)
13+-- Just here to package up the safe use of `unsafePartial`.
14+trying :: forall a b. Gen a -> (a -> Maybe b) -> Gen b
15+trying gen f = map (unsafePartial fromJust) (map f gen `suchThat` isJust)
17+genFixedP :: forall p. KnownPrecision p => PProxy p -> Gen (Fixed p)
18+genFixedP _ = map fromNumber arbitrary `trying` identity
22+ log "Commutative monoid under addition:"
25+ log "Associativity: (a + b) + c = a + (b + c)"
27+ precision <- chooseInt 0 10
28+ unsafePartial fromJust $ reifyPrecision precision \p -> do
32+ pure $ (a + b) + c == a + (b + c) <?> show { a, b, c }
34+ log "Identity: zero + a = a + zero = a"
37+ precision <- chooseInt 0 10
38+ unsafePartial fromJust $ reifyPrecision precision \p -> do
40+ pure $ zero + a == a <?> show { a }
42+ precision <- chooseInt 0 10
43+ unsafePartial fromJust $ reifyPrecision precision \p -> do
45+ pure $ a + zero == a <?> show { a }
47+ log "Commutative: a + b = b + a"
49+ precision <- chooseInt 0 10
50+ unsafePartial fromJust $ reifyPrecision precision \p -> do
53+ pure $ a + b == b + a <?> show { a, b }
55+ log "Multiplicative unit: one * a = a * one = a"
58+ precision <- chooseInt 0 10
59+ unsafePartial fromJust $ reifyPrecision precision \p -> do
61+ pure $ one * a == a <?> show { a }
63+ precision <- chooseInt 0 10
64+ unsafePartial fromJust $ reifyPrecision precision \p -> do
66+ pure $ a * one == a <?> show { a }
68+ log "Multiplicative zero: zero * a = a * zero = zero"
70+ precision <- chooseInt 0 10
71+ unsafePartial fromJust $ reifyPrecision precision \p -> do
73+ pure $ zero * a == zero <?> show { a }
75+ precision <- chooseInt 0 10
76+ unsafePartial fromJust $ reifyPrecision precision \p -> do
78+ pure $ a * zero == zero <?> show { a }