Commit f7bf2f0e authored by Bastian Kauschke's avatar Bastian Kauschke

fix test with RELEASE

parent aeea9622
......@@ -7,6 +7,7 @@ module Copar.FunctorExpression.Desorting
, desort
, desortedLabel
, mkDesortedLabel
, mapDesortedLabel
) where
import Prelude hiding (init)
......@@ -40,6 +41,13 @@ mkDesortedLabel (Sorted _ x) = x
mkDesortedLabel = id
#endif
mapDesortedLabel :: forall f g. () => ((Label f) -> (Label g)) -> Label (Desorted f) -> Label (Desorted g)
#ifdef RELEASE
mapDesortedLabel = id
#else
mapDesortedLabel = fmap
#endif
desortedLabel :: Label (Desorted f) -> (Label f)
#ifdef RELEASE
desortedLabel = id
......
......@@ -23,6 +23,7 @@ import qualified Data.MorphismEncoding as Encoding
import Copar.Coalgebra.Parser
import Copar.RefinementInterface
import Copar.FunctorExpression.Sorts (Sort, Sorted(..))
import Copar.FunctorExpression.Desorting
import Copar.FunctorExpression.Type
import Copar.Parser.Lexer
......@@ -50,25 +51,31 @@ parseMorphismsSpec = describe "parseMorphisms" $ do
it "parses a minimal example" $
parsing (Functor 1 (Id Variable)) "a: a" `shouldParse`
encoding [(Sorted 1 ())] [(0, (Sorted 1 ()), 0)]
encoding [(Sorted 1 ())] [(0, mkDesortedLabel @Id (Sorted 1 ()), 0)]
it "parses a sligtly less minimal example" $
parsing (Functor 1 (Id Variable)) "a: b\nb: a" `shouldParse`
encoding
[(Sorted 1 ()), (Sorted 1 ())]
[(1, (Sorted 1 ()), 0), (0, (Sorted 1 ()), 1)]
[ (1, mkDesortedLabel @Powerset (Sorted 1 ()), 0)
, (0, mkDesortedLabel @Powerset (Sorted 1 ()), 1)
]
it "parses a powerset example" $
parsing (Functor 1 (P Variable)) "a: [a, b]\nb: []" `shouldParse`
encoding
[(Sorted 1 False), (Sorted 1 True)]
[(0, (Sorted 1 ()), 0), (0, (Sorted 1 ()), 1)]
[ (0, mkDesortedLabel @Powerset (Sorted 1 ()), 0)
, (0, mkDesortedLabel @Powerset (Sorted 1 ()), 1)
]
it "parses a fixed product example" $
parsing (Functor 1 (FP ["l1", "l2"] Variable)) "a: (l1, b)\nb: (l2, a)" `shouldParse`
encoding
[(Sorted 1 "l1"), (Sorted 1 "l2")]
[(1, (Sorted 1 ()), 0), (0, (Sorted 1 ()), 1)]
[ (1, mkDesortedLabel @FixedProduct (Sorted 1 ()), 0)
, (0, mkDesortedLabel @FixedProduct (Sorted 1 ()), 1)
]
it "handles mixed functors" $
parsing (Functor 1 (SomeFunctor (FP ["l1", "l2"] (Functor 2 (SomeFunctor (P Variable))))))
......@@ -78,10 +85,10 @@ parseMorphismsSpec = describe "parseMorphisms" $ do
, (Sorted 2 (SomeF1 False))
, (Sorted 1 (SomeF1 ("l2" :: Text)))
, (Sorted 2 (SomeF1 True )) ]
[ (2, (Sorted 1 (SomeLabel ())), 3)
, (0, (Sorted 1 (SomeLabel ())), 1)
, (1, (Sorted 2 (SomeLabel ())), 0)
, (1, (Sorted 2 (SomeLabel ())), 2)
[ (2, mkDesortedLabel @SomeFunctor (Sorted 1 (SomeLabel ())), 3)
, (0, mkDesortedLabel @SomeFunctor (Sorted 1 (SomeLabel ())), 1)
, (1, mkDesortedLabel @SomeFunctor (Sorted 2 (SomeLabel ())), 0)
, (1, mkDesortedLabel @SomeFunctor (Sorted 2 (SomeLabel ())), 2)
]
it "doesn't confuse sorts" $
......@@ -191,5 +198,5 @@ instance ParseMorphism SomeFunctor where
parsing :: (Functor f, ParseMorphism f) => FunctorExpression f Sort
-> Text
-> Either (ParseErrorBundle Text Void) (Encoding (Sorted (Label f)) (Sorted (F1 f)))
-> Either (ParseErrorBundle Text Void) (Encoding (Label (Desorted f)) (F1 (Desorted f)))
parsing expr = fmap snd . parseMorphisms expr EnableSanityChecks ""
......@@ -40,24 +40,35 @@ c = Const . ExplicitSet . V.fromList
e :: a -> [Text] -> Factor a
e inner = Exponential inner . ExplicitExp . V.fromList
-- Used to abstract over the behavior of `Desorted`.
data PolyData a = PolyData
type instance Label PolyData = (Int, Maybe ())
type instance Weight PolyData = ()
type instance F1 PolyData = (Int, Vector (Maybe ()), Vector Int)
type instance F3 PolyData = ()
instance RefinementInterface PolyData where
init = undefined
update = undefined
removeSomeFunctor
:: Encoding
(Sorted (Label (AbsorbingPolynomial SomeFunctor)))
(Sorted (F1 (AbsorbingPolynomial SomeFunctor)))
(Label (Desorted (AbsorbingPolynomial SomeFunctor)))
(F1 (Desorted (AbsorbingPolynomial SomeFunctor)))
-> Encoding
(Sorted (Int, Maybe ()))
(Sorted (Int, Vector (Maybe ()), Vector Int))
removeSomeFunctor = bimap (fmap processLabels) (fmap processF1)
(Label (Desorted (PolyData)))
(F1 (Desorted (PolyData)))
removeSomeFunctor = bimap
(mapDesortedLabel @(AbsorbingPolynomial SomeFunctor) @PolyData processLabels)
(fmap processF1)
where
processF1 f1 =
( polyF1Summand f1
, V.fromList (map (fmap (const ())) (toList (polyF1Variables f1)))
, V.convert (polyF1Constants f1)
)
processLabels :: (Label (AbsorbingPolynomial SomeFunctor)) -> (Label (PolyData))
processLabels (PolyLabel i x) = (i, () <$ x)
parseMorphismPointSpec :: Spec
parseMorphismPointSpec = describe "parseMorphismPoint" $ do
let morphp fexpr input =
......@@ -75,8 +86,8 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
[ (Sorted 1 (f1 0 [Nothing] []))
, (Sorted 1 (f1 0 [Nothing] []))
]
[ (1, (Sorted 1 (0, Nothing)), 0)
, (0, (Sorted 1 (0, Nothing)), 1)
[ (1, mkLabel (Sorted 1 (0, Nothing)), 0)
, (0, mkLabel (Sorted 1 (0, Nothing)), 1)
]
it "gives a useful error if the injection index is out of bounds" $ do
......@@ -86,14 +97,14 @@ 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 (f1 0 [Nothing] [0]))]
[(0, (Sorted 1 (0, Nothing)), 0)]
[(0, mkLabel (Sorted 1 (0, Nothing)), 0)]
it "parses a product of two elements"
$ morphp (mkPoly [[Identity Variable, Identity Variable]]) "x: inj 0 (x, x)"
`shouldParse` encoding
[(Sorted 1 (f1 0 [Nothing, Nothing] []))]
[ (0, (Sorted 1 (0, Nothing)), 0)
, (0, (Sorted 1 (1, Nothing)), 0)
[ (0, mkLabel (Sorted 1 (0, Nothing)), 0)
, (0, mkLabel (Sorted 1 (1, Nothing)), 0)
]
it "parses a sum of two constants"
......@@ -109,8 +120,8 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
[ (Sorted 1 (f1 0 [Nothing] []))
, (Sorted 1 (f1 1 [Nothing] [0]))
]
[ (1, (Sorted 1 (0, Nothing)), 0)
, (0, (Sorted 1 (0, Nothing)), 1)
[ (1, mkLabel (Sorted 1 (0, Nothing)), 0)
, (0, mkLabel (Sorted 1 (0, Nothing)), 1)
]
it "allows to omit 'inj' for co-products with only one factor" $ do
......@@ -120,8 +131,8 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
morphp (mkPoly [[Identity Variable, Identity Variable]]) "x: (x, x)"
`shouldParse` encoding
[(Sorted 1 (f1 0 [Nothing, Nothing] []))]
[ (0, (Sorted 1 (0, Nothing)), 0)
, (0, (Sorted 1 (1, Nothing)), 0)
[ (0, mkLabel (Sorted 1 (0, Nothing)), 0)
, (0, mkLabel (Sorted 1 (1, Nothing)), 0)
]
it "doesn't confuse a constant called inj and an injection" $ do
......@@ -143,7 +154,7 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
it "parses an exponential" $ do
morphp (mkPoly [[e Variable ["a"]]]) "x: {a: x}" `shouldParse` encoding
[(Sorted 1 (f1 0 [Nothing] []))]
[(0, (Sorted 1 (0, Nothing)), 0)]
[(0, mkLabel (Sorted 1 (0, Nothing)), 0)]
it "fails to parse an exponential that isn't totally defined" $ do
morphp (mkPoly [[e Variable ["a", "b"]]]) `shouldFailOn` "x: {a: x}"
......@@ -159,9 +170,9 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
[ (Sorted 1 (f1 0 [Nothing, Nothing] []))
, (Sorted 1 (f1 1 [Nothing] []))
]
[ (1, (Sorted 1 (0, Nothing)), 1)
, (0, (Sorted 1 (0, Nothing)), 0)
, (0, (Sorted 1 (1, Nothing)), 1)
[ (1, mkLabel (Sorted 1 (0, Nothing)), 1)
, (0, mkLabel (Sorted 1 (0, Nothing)), 0)
, (0, mkLabel (Sorted 1 (1, Nothing)), 1)
]
)
......@@ -208,8 +219,8 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
morphp (mkPoly [[Exponential Variable (FiniteNatExp 2)]]) "x: {0: x, 1: x}"
`shouldParse` (encoding
[(Sorted 1 (f1 0 [Nothing, Nothing] []))]
[ (0, (Sorted 1 (0, Nothing)), 0)
, (0, (Sorted 1 (1, Nothing)), 0)
[ (0, mkLabel (Sorted 1 (0, Nothing)), 0)
, (0, mkLabel (Sorted 1 (1, Nothing)), 0)
]
)
......@@ -283,3 +294,5 @@ f1 s v c = (s, V.fromList v, V.fromList c)
v :: [a] -> Vector a
v = V.fromList
mkLabel = mkDesortedLabel @PolyData
\ No newline at end of file
......@@ -40,7 +40,9 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
"x: {x,x}"
)
`shouldParse` (encoding [(Sorted 1 2)]
[(0, (Sorted 1 1), 0), (0, (Sorted 1 1), 0)]
[ (0, mkDesortedLabel @Bag (Sorted 1 1), 0)
, (0, mkDesortedLabel @Bag (Sorted 1 1), 0)
]
)
refineSpec :: Spec
......
......@@ -43,7 +43,10 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
"x: {x: 0.5, y: 0.5}\ny: {x: 1.0}") `shouldParse`
encoding
[(Sorted 1 1), (Sorted 1 1)]
[(1, (Sorted 1 1), 0), (0, (Sorted 1 0.5), 0), (0, (Sorted 1 0.5), 1)]
[ (1, mkDesortedLabel @Distribution (Sorted 1 1), 0)
, (0, mkDesortedLabel @Distribution (Sorted 1 0.5), 0)
, (0, mkDesortedLabel @Distribution (Sorted 1 0.5), 1)
]
it "errors if edge weight sum isn't 1" $
parseMorphisms (Functor 1 (Distribution Variable)) EnableSanityChecks ""
......
......@@ -7,12 +7,14 @@ import TestHelpers
import Data.Complex
import Data.Ratio
import Copar.RefinementInterface
import Copar.FunctorExpression.Parser
import Copar.FunctorDescription
import Copar.Functors.GroupValued
import Copar.Coalgebra.Parser
import Copar.FunctorExpression.Type
import Copar.FunctorExpression.Sorts ( Sorted(..) )
import Copar.FunctorExpression.Desorting
import Data.Float.Utils ( EqDouble )
......@@ -41,7 +43,9 @@ parseMorphismPointIntSpec = describe "parseMorphismPoint (Int)" $ do
it "parses a simple example"
$ p "x: {x: 2, y: 3}\ny: {}"
`shouldParse` encoding [(Sorted 1 5), (Sorted 1 0)]
[(0, (Sorted 1 2), 0), (0, (Sorted 1 3), 1)]
[ (0, mkLabel @Int (Sorted 1 2), 0)
, (0, mkLabel @Int (Sorted 1 3), 1)
]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 2, x: 3}"
......@@ -61,7 +65,9 @@ parseMorphismPointDoubleSpec = describe "parseMorphismPoint (Double)" $ do
it "parses a simple example"
$ p "x: {x: 0.5, y: 3.7}\ny: {}"
`shouldParse` encoding [(Sorted 1 4.2), (Sorted 1 0)]
[(0, (Sorted 1 0.5), 0), (0, (Sorted 1 3.7), 1)]
[ (0, mkLabel @EqDouble (Sorted 1 0.5), 0)
, (0, mkLabel @EqDouble (Sorted 1 3.7), 1)
]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 0.5, x: 3.7}"
......@@ -83,28 +89,34 @@ parseMorphismPointComplexSpec = describe "parseMorphismPoint (Complex)" $ do
$ p "x: {x: 0.5, y: 3.7}\ny: {}"
`shouldParse` encoding
[(Sorted 1 (c 4.2 0)), (Sorted 1 0)]
[(0, (Sorted 1 (c 0.5 0)), 0), (0, (Sorted 1 (c 3.7 0)), 1)]
[ (0, mkLabel @OrderedComplex (Sorted 1 (c 0.5 0)), 0)
, (0, mkLabel @OrderedComplex (Sorted 1 (c 3.7 0)), 1)
]
it "parses a simple example with only imaginary parts"
$ p "x: {x: 0.5i, y: 3.7i}\ny: {}"
`shouldParse` encoding
[(Sorted 1 (c 0 4.2)), (Sorted 1 0)]
[(0, (Sorted 1 (c 0 0.5)), 0), (0, (Sorted 1 (c 0 3.7)), 1)]
[ (0, mkLabel @OrderedComplex (Sorted 1 (c 0 0.5)), 0)
, (0, mkLabel @OrderedComplex (Sorted 1 (c 0 3.7)), 1)
]
it "parses a simple exmaple with mixed real and fractional parts"
$ p "x: {x: 1 + 0.5i, y: 3.7i + 2}\ny: {}"
`shouldParse` encoding
[(Sorted 1 (c 3 4.2)), (Sorted 1 0)]
[(0, (Sorted 1 (c 1 0.5)), 0), (0, (Sorted 1 (c 2 3.7)), 1)]
[ (0, mkLabel @OrderedComplex (Sorted 1 (c 1 0.5)), 0)
, (0, mkLabel @OrderedComplex (Sorted 1 (c 2 3.7)), 1)
]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 2, x: 3}"
it "works with negative numbers" $ p "x: {x: -2.3}" `shouldParse` encoding
[Sorted 1 (c (-2.3) 0)]
[(0, Sorted 1 (c (-2.3) 0), 0)]
[(0, mkLabel @OrderedComplex (Sorted 1 (c (-2.3) 0)), 0)]
where c a b = OrderedComplex (a :+ b)
......@@ -118,9 +130,14 @@ parseMorphismPointRationalSpec = describe "parseMorphismPoint (Rational)" $ do
it "parses a simple example"
$ p "x: {x: 1/5, y: 3/7}\ny: {}"
`shouldParse` encoding [(Sorted 1 (22%35)), (Sorted 1 0)]
[(0, (Sorted 1 (1%5)), 0), (0, (Sorted 1 (3%7)), 1)]
[ (0, mkLabel @(Ratio Int) (Sorted 1 (1%5)), 0)
, (0, mkLabel @(Ratio Int) (Sorted 1 (3%7)), 1)
]
it "parses negative values"
$ p "x: {x: -1/5, y: -3/7}\ny: {}"
`shouldParse` encoding [(Sorted 1 (-22%35)), (Sorted 1 0)]
[(0, (Sorted 1 (-1%5)), 0), (0, (Sorted 1 (-3%7)), 1)]
[(0, mkLabel (Sorted 1 (-1%5)), 0), (0, mkLabel (Sorted 1 (-3%7)), 1)]
mkLabel :: forall f. () => Sorted (Label (GroupValued f)) -> Label (Desorted (GroupValued f))
mkLabel = mkDesortedLabel @(GroupValued f)
......@@ -26,6 +26,7 @@ import Copar.Functors.MonoidValued
import Copar.FunctorExpression.Type
import Copar.FunctorDescription
import Copar.Coalgebra.Parser
import Copar.RefinementInterface
import Copar.FunctorExpression.Sorts ( Sorted(..) )
import Copar.FunctorExpression.Desorting
import qualified Data.Partition as Part
......@@ -50,7 +51,6 @@ spec = do
orWordParseSpec
orWordRefineSpec
maxIntParseSpec :: Spec
maxIntParseSpec = describe "maxInt parsing" $ do
makeFunctorParseSpec @(Max Int) ("Z", Just "ℤ") "max"
......@@ -62,7 +62,7 @@ maxIntParseSpec = describe "maxInt parsing" $ do
it "parses a simple example"
$ p "x: {x: 2, y: 3}\ny: {}"
`shouldParse` encoding [Sorted 1 3, Sorted 1 minBound]
[(0, (Sorted 1 2), 0), (0, (Sorted 1 3), 1)]
[(0, mkLabel @(Max Int) (Sorted 1 2), 0), (0, mkLabel @(Max Int) (Sorted 1 3), 1)]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 2, x: 3}"
......@@ -79,7 +79,7 @@ minIntParseSpec = describe "minIntParse" $ do
it "parses a simple example"
$ p "x: {x: 2, y: 3}\ny: {}"
`shouldParse` encoding [Sorted 1 2, Sorted 1 maxBound]
[(0, (Sorted 1 2), 0), (0, (Sorted 1 3), 1)]
[(0, mkLabel @(Min Int) (Sorted 1 2), 0), (0, mkLabel @(Min Int) (Sorted 1 3), 1)]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 2, x: 3}"
......@@ -129,7 +129,9 @@ maxRealParseSpec = describe "maxReal parsing" $ do
it "parses a simple example"
$ p "x: {x: 2.5, y: 3.7}\ny: {}"
`shouldParse` encoding [Sorted 1 3.7, Sorted 1 mempty]
[(0, (Sorted 1 2.5), 0), (0, (Sorted 1 3.7), 1)]
[ (0, mkLabel @MaxDouble (Sorted 1 2.5), 0)
, (0, mkLabel @MaxDouble (Sorted 1 3.7), 1)
]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 2.3, x: 3.6}"
......@@ -147,7 +149,9 @@ minRealParseSpec = describe "minReal parsing" $ do
it "parses a simple example"
$ p "x: {x: 2.5, y: 3.7}\ny: {}"
`shouldParse` encoding [Sorted 1 2.5, Sorted 1 mempty]
[(0, (Sorted 1 2.5), 0), (0, (Sorted 1 3.7), 1)]
[ (0, mkLabel @MinDouble (Sorted 1 2.5), 0)
, (0, mkLabel @MinDouble (Sorted 1 3.7), 1)
]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 2.3, x: 3.6}"
......@@ -197,7 +201,9 @@ andWordParseSpec = describe "bit-and parsing" $ do
it "parses a simple example"
$ p "x: {x: 0xA0, y: 0x0A}\ny: {}"
`shouldParse` encoding [Sorted 1 0, Sorted 1 mempty]
[(0, (Sorted 1 0xA0), 0), (0, (Sorted 1 0x0A), 1)]
[ (0, mkLabel @(BitAnd Word64) (Sorted 1 0xA0), 0)
, (0, mkLabel @(BitAnd Word64) (Sorted 1 0x0A), 1)
]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 0xA, x: 0xA}"
......@@ -229,7 +235,9 @@ orWordParseSpec = describe "bit-or parsing" $ do
it "parses a simple example"
$ p "x: {x: 0xA0, y: 0x0A}\ny: {}"
`shouldParse` encoding [Sorted 1 0xAA, Sorted 1 mempty]
[(0, (Sorted 1 0xA0), 0), (0, (Sorted 1 0x0A), 1)]
[ (0, mkLabel @(BitOr Word64) (Sorted 1 0xA0), 0)
, (0, mkLabel @(BitOr Word64) (Sorted 1 0x0A), 1)
]
it "fails on duplicate edges" $ p `shouldFailOn` "x: {x: 0xA, x: 0xA}"
......@@ -305,3 +313,8 @@ itParsesEmpty =
it "parses an empty successor list"
$ makeMorphParser @m "x: {}"
`shouldParse` encoding [Sorted 1 mempty] []
mkLabel :: forall m . RefinementInterface (SlowMonoidValued m)
=> Sorted (Label (SlowMonoidValued m))
-> Label (Desorted (SlowMonoidValued m))
mkLabel = mkDesortedLabel @(SlowMonoidValued m)
\ No newline at end of file
......@@ -22,6 +22,7 @@ import qualified Copar.Parser.Lexer as L
import Copar.Algorithm
import qualified Data.Partition as Part
import Copar.Coalgebra.Parser
import Copar.RefinementInterface
import Copar.FunctorExpression.Desorting
import Copar.FunctorExpression.Type
import Copar.Functors.Polynomial
......@@ -189,10 +190,10 @@ c = Const . ExplicitSet . V.fromList
e :: a -> [Text] -> Factor a
e inner = Exponential inner . ExplicitExp . V.fromList
morphp fexpr input = snd <$> parseMorphisms (Functor 1 fexpr) EnableSanityChecks "" input
parseMorphismPointSpec :: Spec
parseMorphismPointSpec = describe "parseMorphismPoint" $ do
let morphp fexpr input = snd <$> parseMorphisms (Functor 1 fexpr) EnableSanityChecks "" input
it "parses a constant" $ do
morphp (mkPoly [[c ["a", "b", "c"]]]) "x: inj 0 (a)" `shouldParse`
encoding [(Sorted 1 (f1 0 0 [0]))] []
......@@ -203,7 +204,7 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
morphp (mkPoly [[Identity Variable]]) "x: inj 0 (y)\ny: inj 0 (x)" `shouldParse`
encoding
[(Sorted 1 (f1 0 1 [])), (Sorted 1 (f1 0 1 []))]
[(1, (Sorted 1 0), 0), (0, (Sorted 1 0), 1)]
[(1, mkLabel (Sorted 1 0), 0), (0, mkLabel (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,11 +212,11 @@ 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 (f1 0 1 [0]))] [(0, (Sorted 1 0), 0)]
encoding [(Sorted 1 (f1 0 1 [0]))] [(0, mkLabel (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 (f1 0 2 []))] [(0, (Sorted 1 0), 0), (0, (Sorted 1 1), 0)]
encoding [(Sorted 1 (f1 0 2 []))] [(0, mkLabel (Sorted 1 0), 0), (0, mkLabel (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`
......@@ -229,14 +230,15 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
[ (Sorted 1 (f1 0 1 []))
, (Sorted 1 (f1 1 1 [0]))
]
[(1, (Sorted 1 0), 0), (0, (Sorted 1 0), 1)]
[(1, mkLabel (Sorted 1 0), 0), (0, mkLabel (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 (f1 0 0 [0]))] []
morphp (mkPoly [[Identity Variable, Identity Variable]]) "x: (x, x)" `shouldParse`
encoding [(Sorted 1 (f1 0 2 []))] [(0, (Sorted 1 0), 0), (0, (Sorted 1 1), 0)]
encoding [(Sorted 1 (f1 0 2 []))]
[(0, mkLabel (Sorted 1 0), 0), (0, mkLabel (Sorted 1 1), 0)]
it "doesn't confuse a constant called inj and an injection" $ do
morphp (mkPoly [[c ["injection"]]]) "x: injection" `shouldParse`
......@@ -256,7 +258,7 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
it "parses an exponential" $ do
morphp (mkPoly [[e Variable ["a"]]]) "x: {a: x}" `shouldParse`
encoding [(Sorted 1 (f1 0 1 []))] [(0, (Sorted 1 0), 0)]
encoding [(Sorted 1 (f1 0 1 []))] [(0, mkLabel (Sorted 1 0), 0)]
it "fails to parse an exponential that isn't totally defined" $ do
morphp (mkPoly [[e Variable ["a", "b"]]])
......@@ -274,9 +276,9 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
[ (Sorted 1 (f1 0 2 []))
, (Sorted 1 (f1 1 1 []))
]
[ (1, (Sorted 1 0), 1)
, (0, (Sorted 1 0), 0)
, (0, (Sorted 1 1), 1)
[ (1, mkLabel (Sorted 1 0), 1)
, (0, mkLabel (Sorted 1 0), 0)
, (0, mkLabel (Sorted 1 1), 1)
])
it "allows positive numbers as constants for integer set" $ do
......@@ -324,7 +326,7 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
`shouldParse`
(encoding
[(Sorted 1 (f1 0 2 []))]
[(0, (Sorted 1 0), 0), (0, (Sorted 1 1), 0)])
[(0, mkLabel (Sorted 1 0), 0), (0, mkLabel (Sorted 1 1), 0)])
it "requires all values of the exponent set for FiniteNatExp" $ do
morphp (mkPoly [[Exponential Variable (FiniteNatExp 2)]])
......@@ -337,8 +339,6 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
refineSpec :: Spec
refineSpec = describe "refining" $ do
let morphp fexpr input = snd <$> parseMorphisms (Functor 1 fexpr) EnableSanityChecks "" input
it "distinguishes constants" $ do
let Right enc = morphp (mkPoly [[c ["a", "b"]]]) "x: inj 0 (a)\ny: inj 0 (b)"
part <- stToIO (refine (Proxy @(Desorted Polynomial)) enc True)
......@@ -389,3 +389,6 @@ f1 s v = PolyF1 s v . VU.fromList
v :: [a] -> Vector a
v = V.fromList
mkLabel :: Sorted (Label Polynomial) -> Label (Desorted Polynomial)
mkLabel = mkDesortedLabel @Polynomial
\ No newline at end of file
......@@ -8,6 +8,7 @@ import Copar.Functors.Powerset
import Copar.Coalgebra.Parser
import Copar.FunctorExpression.Type
import Copar.FunctorExpression.Sorts (Sorted(..))
import Copar.FunctorExpression.Desorting
spec :: Spec
......@@ -20,7 +21,10 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
(snd <$> parseMorphisms (Functor 1 (Powerset Variable)) EnableSanityChecks "" "x: {x, y}\ny: {}") `shouldParse`
(encoding
[(Sorted 1 True), (Sorted 1 False)]
[(0, (Sorted 1 ()), 0), (0, (Sorted 1 ()), 1)])
[ (0, mkDesortedLabel @Powerset (Sorted 1 ()), 0)
, (0, mkDesortedLabel @Powerset (Sorted 1 ()), 1)
]
)
it "errors on duplicate edges" $
parseMorphisms (Functor 1 (Powerset Variable)) EnableSanityChecks "" `shouldFailOn` "x: {x, x}"
Markdown is supported
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