@@ -2,16 +2,21 @@ module Test.Main where
2
2
3
3
import Prelude
4
4
5
- import Effect (Effect )
6
- import Effect.Console (log , logShow )
7
5
import Data.Enum (class BoundedEnum , class Enum , Cardinality (..), cardinality , fromEnum , pred , succ , toEnum , enumFromTo )
8
6
import Data.Generic.Rep as G
9
7
import Data.Generic.Rep.Bounded as GBounded
10
8
import Data.Generic.Rep.Enum as GEnum
11
9
import Data.Generic.Rep.Eq as GEq
10
+ import Data.Generic.Rep.HeytingAlgebra as GHeytingAlgebra
12
11
import Data.Generic.Rep.Ord as GOrd
12
+ import Data.Generic.Rep.Ring as GRing
13
+ import Data.Generic.Rep.Semiring as GSemiring
13
14
import Data.Generic.Rep.Show as GShow
15
+ import Data.HeytingAlgebra (ff , tt )
14
16
import Data.Maybe (Maybe (..))
17
+ import Data.Tuple (Tuple (..))
18
+ import Effect (Effect )
19
+ import Effect.Console (log , logShow )
15
20
import Test.Assert (assert )
16
21
17
22
data List a = Nil | Cons { head :: a , tail :: List a }
@@ -103,6 +108,36 @@ instance boundedEnumPair :: (BoundedEnum a, BoundedEnum b) => BoundedEnum (Pair
103
108
toEnum = GEnum .genericToEnum
104
109
fromEnum = GEnum .genericFromEnum
105
110
111
+ data A1 = A1 (Tuple (Tuple Int { a :: Int } ) { a :: Int } )
112
+ derive instance genericA1 :: G.Generic A1 _
113
+ instance eqA1 :: Eq A1 where
114
+ eq a = GEq .genericEq a
115
+ instance showA1 :: Show A1 where
116
+ show a = GShow .genericShow a
117
+ instance semiringA1 :: Semiring A1 where
118
+ zero = GSemiring .genericZero
119
+ one = GSemiring .genericOne
120
+ add x y = GSemiring .genericAdd x y
121
+ mul x y = GSemiring .genericMul x y
122
+ instance ringA1 :: Ring A1 where
123
+ sub x y = GRing .genericSub x y
124
+
125
+ data B1 = B1 (Tuple (Tuple Boolean { a :: Boolean } ) { a :: Boolean } )
126
+ derive instance genericB1 :: G.Generic B1 _
127
+ instance eqB1 :: Eq B1 where
128
+ eq a = GEq .genericEq a
129
+ instance showB1 :: Show B1 where
130
+ show a = GShow .genericShow a
131
+ instance heytingAlgebraB1 :: HeytingAlgebra B1 where
132
+ ff = GHeytingAlgebra .genericFF
133
+ tt = GHeytingAlgebra .genericTT
134
+ implies x y = GHeytingAlgebra .genericImplies x y
135
+ conj x y = GHeytingAlgebra .genericConj x y
136
+ disj x y = GHeytingAlgebra .genericDisj x y
137
+ not x = GHeytingAlgebra .genericNot x
138
+
139
+ instance booleanAlgebraB1 :: BooleanAlgebra B1
140
+
106
141
main :: Effect Unit
107
142
main = do
108
143
logShow (cons 1 (cons 2 Nil ))
@@ -196,3 +231,33 @@ main = do
196
231
log " Checking product toEnum/fromEnum roundtrip"
197
232
assert $ let allPairs = enumFromTo bottom top :: Array (Pair Bit SimpleBounded )
198
233
in (toEnum <<< fromEnum <$> allPairs) == (Just <$> allPairs)
234
+
235
+ log " Checking zero"
236
+ assert $ (zero :: A1 ) == A1 (Tuple (Tuple 0 {a: 0 }) {a: 0 })
237
+
238
+ log " Checking one"
239
+ assert $ (one :: A1 ) == A1 (Tuple (Tuple 1 {a: 1 }) {a: 1 })
240
+
241
+ log " Checking add"
242
+ assert $ A1 (Tuple (Tuple 100 {a: 10 }) {a: 20 }) + A1 (Tuple (Tuple 50 {a: 30 }) {a: 40 }) == A1 (Tuple (Tuple 150 {a: 40 }) {a: 60 })
243
+
244
+ log " Checking mul"
245
+ assert $ A1 (Tuple (Tuple 100 {a: 10 }) {a: 20 }) * A1 (Tuple (Tuple 50 {a: 30 }) {a: 40 }) == A1 (Tuple (Tuple 5000 {a: 300 }) {a: 800 })
246
+
247
+ log " Checking sub"
248
+ assert $ A1 (Tuple (Tuple 100 {a: 10 }) {a: 20 }) - A1 (Tuple (Tuple 50 {a: 30 }) {a: 40 }) == A1 (Tuple (Tuple 50 {a: -20 }) {a: -20 })
249
+
250
+ log " Checking ff"
251
+ assert $ (ff :: B1 ) == B1 (Tuple (Tuple false {a: false }) {a: false })
252
+
253
+ log " Checking tt"
254
+ assert $ (tt :: B1 ) == B1 (Tuple (Tuple true {a: true }) {a: true })
255
+
256
+ log " Checking conj"
257
+ assert $ (B1 (Tuple (Tuple true {a: false }) {a: true }) && B1 (Tuple (Tuple false {a: false }) {a: true })) == B1 (Tuple (Tuple false { a: false }) { a: true })
258
+
259
+ log " Checking disj"
260
+ assert $ (B1 (Tuple (Tuple true {a: false }) {a: true }) || B1 (Tuple (Tuple false {a: false }) {a: true })) == B1 (Tuple (Tuple true { a: false }) { a: true })
261
+
262
+ log " Checking not"
263
+ assert $ not B1 (Tuple (Tuple true {a: false }) {a: true }) == B1 (Tuple (Tuple false {a: true }) {a: false })
0 commit comments