@@ -2,16 +2,21 @@ module Test.Main where
22
33import Prelude
44
5- import Effect (Effect )
6- import Effect.Console (log , logShow )
75import Data.Enum (class BoundedEnum , class Enum , Cardinality (..), cardinality , fromEnum , pred , succ , toEnum , enumFromTo )
86import Data.Generic.Rep as G
97import Data.Generic.Rep.Bounded as GBounded
108import Data.Generic.Rep.Enum as GEnum
119import Data.Generic.Rep.Eq as GEq
10+ import Data.Generic.Rep.HeytingAlgebra as GHeytingAlgebra
1211import Data.Generic.Rep.Ord as GOrd
12+ import Data.Generic.Rep.Ring as GRing
13+ import Data.Generic.Rep.Semiring as GSemiring
1314import Data.Generic.Rep.Show as GShow
15+ import Data.HeytingAlgebra (ff , tt )
1416import Data.Maybe (Maybe (..))
17+ import Data.Tuple (Tuple (..))
18+ import Effect (Effect )
19+ import Effect.Console (log , logShow )
1520import Test.Assert (assert )
1621
1722data List a = Nil | Cons { head :: a , tail :: List a }
@@ -103,6 +108,36 @@ instance boundedEnumPair :: (BoundedEnum a, BoundedEnum b) => BoundedEnum (Pair
103108 toEnum = GEnum .genericToEnum
104109 fromEnum = GEnum .genericFromEnum
105110
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+
106141main :: Effect Unit
107142main = do
108143 logShow (cons 1 (cons 2 Nil ))
@@ -196,3 +231,33 @@ main = do
196231 log " Checking product toEnum/fromEnum roundtrip"
197232 assert $ let allPairs = enumFromTo bottom top :: Array (Pair Bit SimpleBounded )
198233 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