Commit 8a0a8b38 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

tests: Fix tests for Polynomial functor

Those were broken by the recent data structure optimization.
parent d7f81067
......@@ -195,15 +195,15 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
it "parses a constant" $ do
morphp (mkPoly [[c ["a", "b", "c"]]]) "x: inj 0 (a)" `shouldParse`
encoding [(Sorted 1 (mkVal 0 [ConstValue 0]))] []
encoding [(Sorted 1 (h1 0 0 [0]))] []
morphp (mkPoly [[c ["a", "b", "c"]]]) "x: inj 0 (b)" `shouldParse`
encoding [(Sorted 1 (mkVal 0 [ConstValue 1]))] []
encoding [(Sorted 1 (h1 0 0 [1]))] []
it "parses the identity" $
morphp (mkPoly [[Identity Variable]]) "x: inj 0 (y)\ny: inj 0 (x)" `shouldParse`
encoding
[(Sorted 1 (mkVal 0 [IdValue ()])), (Sorted 1 (mkVal 0 [IdValue ()]))]
[(1, (Sorted 1 (0, 0)), 0), (0, (Sorted 1 (0, 0)), 1)]
[(Sorted 1 (h1 0 1 [])), (Sorted 1 (h1 0 1 []))]
[(1, (Sorted 1 0), 0), (0, (Sorted 1 0), 1)]
it "gives a useful error if the injection index is out of bounds" $ do
morphp (mkPoly [[c ["a"]]]) `shouldFailOn `"x: inj 5 (a)"
......@@ -211,61 +211,52 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
it "parses a product of a constant and an X" $
morphp (mkPoly [[c ["a"], Identity Variable]]) "x: inj 0 (a, x)" `shouldParse`
encoding
[(Sorted 1 (mkVal 0 [ConstValue 0, IdValue ()]))]
[(0, (Sorted 1 (1, 0)), 0)]
encoding [(Sorted 1 (h1 0 1 [0]))] [(0, (Sorted 1 0), 0)]
it "parses a product of two elements" $
morphp (mkPoly [[Identity Variable, Identity Variable]]) "x: inj 0 (x, x)" `shouldParse`
encoding
[(Sorted 1 (mkVal 0 [IdValue (), IdValue ()]))]
[(0, (Sorted 1 (0, 0)), 0), (0, (Sorted 1 (1, 0)), 0)]
encoding [(Sorted 1 (h1 0 2 []))] [(0, (Sorted 1 0), 0), (0, (Sorted 1 1), 0)]
it "parses a sum of two constants" $
morphp (mkPoly [[c ["a"]], [c ["b"]]]) "x: inj 0 (a)\ny: inj 1 (b)" `shouldParse`
encoding
[(Sorted 1 (mkVal 0 [ConstValue 0])), (Sorted 1 (mkVal 1 [ConstValue 0]))]
[]
encoding [(Sorted 1 (h1 0 0 [0])), (Sorted 1 (h1 1 0 [0]))] []
it "parses X+(AxX)" $
morphp
(mkPoly [[Identity Variable], [c ["a"], Identity Variable]])
"x: inj 0 (y)\ny: inj 1 (a, x)" `shouldParse`
encoding
[ (Sorted 1 (mkVal 0 [IdValue ()]))
, (Sorted 1 (mkVal 1 [ConstValue 0, IdValue ()]))
[ (Sorted 1 (h1 0 1 []))
, (Sorted 1 (h1 1 1 [0]))
]
[(1, (Sorted 1 (1, 0)), 0), (0, (Sorted 1 (0, 0)), 1)]
[(1, (Sorted 1 0), 0), (0, (Sorted 1 0), 1)]
it "allows to omit 'inj' for co-products with only one factor" $ do
morphp (mkPoly [[c ["a"]]]) "x: (a)" `shouldParse`
encoding [(Sorted 1 (mkVal 0 [ConstValue 0]))] []
encoding [(Sorted 1 (h1 0 0 [0]))] []
morphp (mkPoly [[Identity Variable, Identity Variable]]) "x: (x, x)" `shouldParse`
encoding
[(Sorted 1 (mkVal 0 [IdValue (), IdValue ()]))]
[(0, (Sorted 1 (0, 0)), 0), (0, (Sorted 1 (1, 0)), 0)]
encoding [(Sorted 1 (h1 0 2 []))] [(0, (Sorted 1 0), 0), (0, (Sorted 1 1), 0)]
it "doesn't confuse a constant called inj and an injection" $ do
morphp (mkPoly [[c ["injection"]]]) "x: injection" `shouldParse`
encoding [(Sorted 1 (mkVal 0 [ConstValue 0]))] []
encoding [(Sorted 1 (h1 0 0 [0]))] []
morphp (mkPoly [[c ["inj"]]]) "x: inj" `shouldParse`
encoding [(Sorted 1 (mkVal 0 [ConstValue 0]))] []
encoding [(Sorted 1 (h1 0 0 [0]))] []
morphp (mkPoly [[c ["inj"]]]) "x: inj 0 inj" `shouldParse`
encoding [(Sorted 1 (mkVal 0 [ConstValue 0]))] []
encoding [(Sorted 1 (h1 0 0 [0]))] []
it "allows to omit parens for products with only one factor" $ do
morphp (mkPoly [[c ["a"]], [c ["b"]]]) "x: inj 0 a" `shouldParse`
encoding [(Sorted 1 (mkVal 0 [ConstValue 0]))] []
encoding [(Sorted 1 (h1 0 0 [0]))] []
it "allows to omit both 'inj' and parens" $ do
morphp (mkPoly [[c ["a"]]]) "x: a" `shouldParse`
encoding [(Sorted 1 (mkVal 0 [ConstValue 0]))] []
encoding [(Sorted 1 (h1 0 0 [0]))] []
it "parses an exponential" $ do
morphp (mkPoly [[e Variable ["a"]]]) "x: {a: x}" `shouldParse`
encoding
[(Sorted 1 (mkVal 0 [ExponentialValue (v [()])]))]
[(0, (Sorted 1 (0, 0)), 0)]
encoding [(Sorted 1 (h1 0 1 []))] [(0, (Sorted 1 0), 0)]
it "fails to parse an exponential that isn't totally defined" $ do
morphp (mkPoly [[e Variable ["a", "b"]]])
......@@ -280,35 +271,35 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
"x: inj0 {a: x, b: y}\ny: inj1 y"
`shouldParse`
(encoding
[ (Sorted 1 (mkVal 0 [ExponentialValue (v [(), ()])]))
, (Sorted 1 (mkVal 1 [IdValue ()]))
[ (Sorted 1 (h1 0 2 []))
, (Sorted 1 (h1 1 1 []))
]
[ (1, (Sorted 1 (0, 0)), 1)
, (0, (Sorted 1 (0, 0)), 0)
, (0, (Sorted 1 (0, 1)), 1)
[ (1, (Sorted 1 0), 1)
, (0, (Sorted 1 0), 0)
, (0, (Sorted 1 1), 1)
])
it "allows positive numbers as constants for integer set" $ do
morphp (mkPoly [[Const IntSet]]) "x: 5\ny:30" `shouldParse`
(encoding
[ (Sorted 1 (mkVal 0 [ConstValue 5]))
, (Sorted 1 (mkVal 0 [ConstValue 30]))
[ (Sorted 1 (h1 0 0 [5]))
, (Sorted 1 (h1 0 0 [30]))
]
[])
it "allows positive numbers as constants for integer set" $ do
morphp (mkPoly [[Const IntSet]]) "x: -3\ny:-77" `shouldParse`
(encoding
[ (Sorted 1 (mkVal 0 [ConstValue (-3)]))
, (Sorted 1 (mkVal 0 [ConstValue (-77)]))
[ (Sorted 1 (h1 0 0 [(-3)]))
, (Sorted 1 (h1 0 0 [(-77)]))
]
[])
it "allows positive numbers as constants for naturals set" $ do
morphp (mkPoly [[Const NatSet]]) "x: 5\ny:30" `shouldParse`
(encoding
[ (Sorted 1 (mkVal 0 [ConstValue 5]))
, (Sorted 1 (mkVal 0 [ConstValue 30]))
[ (Sorted 1 (h1 0 0 [5]))
, (Sorted 1 (h1 0 0 [30]))
]
[])
......@@ -317,8 +308,7 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
it "allows numbers in the correct range as constants for FiniteNatSet" $ do
let f = mkPoly [[Const (FiniteNatSet 4)]]
morphp f "x: 0" `shouldParse`
(encoding [(Sorted 1 (mkVal 0 [ConstValue 0]))] [])
morphp f "x: 0" `shouldParse` (encoding [(Sorted 1 (h1 0 0 [0]))] [])
morphp f `shouldSucceedOn` "x: 1"
morphp f `shouldSucceedOn` "x: 2"
morphp f `shouldSucceedOn` "x: 3"
......@@ -333,8 +323,8 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
morphp (mkPoly [[Exponential Variable (FiniteNatExp 2)]]) "x: {0: x, 1: x}"
`shouldParse`
(encoding
[(Sorted 1 (mkVal 0 [ExponentialValue (v [(), ()])]))]
[(0, (Sorted 1 (0, 0)), 0), (0, (Sorted 1 (0, 1)), 0)])
[(Sorted 1 (h1 0 2 []))]
[(0, (Sorted 1 0), 0), (0, (Sorted 1 1), 0)])
it "requires all values of the exponent set for FiniteNatExp" $ do
morphp (mkPoly [[Exponential Variable (FiniteNatExp 2)]])
......@@ -343,7 +333,7 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
it "can correctly parse constants from a set with shared prefixes" $ do
morphp (mkPoly [[Const (ExplicitSet (v ["a1", "a10"]))]]) "x: a10"
`shouldParse`
(encoding [(Sorted 1 (mkVal 0 [ConstValue 1]))] [])
(encoding [(Sorted 1 (h1 0 0 [1]))] [])
refineSpec :: Spec
refineSpec = describe "refining" $ do
......@@ -392,8 +382,10 @@ mkPoly :: [[Factor a]] -> Polynomial a
mkPoly =
Polynomial . Sum . NonEmpty.fromList . map (Product . NonEmpty.fromList)
mkVal :: Int -> [FactorValue a] -> SumValue a
mkVal i = SumValue i . ProductValue . v
h1 :: Int -> Int -> [Int] -> PolyH1
h1 s v = PolyH1 s v . V.fromList
v :: [a] -> Vector a
v = V.fromList
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment