Commit f45a0ba5 authored by Bastian Kauschke's avatar Bastian Kauschke
Browse files

update tests

parent 5e8a310c
......@@ -116,7 +116,7 @@ parseFunctor name input =
id
(parse (functorExpressionParser identity functorParsers <* eof) name input)
where
functorParsers = map dynFunctorExprParser (L.sortBy (compare `on` dynPrecedence) registeredFunctors)
functorParsers = map dynFunctorExprParser (reverse (L.sortBy (compare `on` dynPrecedence) registeredFunctors))
-- | Options for coalgebra parsing.
......@@ -188,7 +188,7 @@ parseCoalgebra config name input =
name
input
)
where functorParsers = map dynFunctorExprParser (L.sortBy (compare `on` dynPrecedence) registeredFunctors)
where functorParsers = map dynFunctorExprParser (reverse (L.sortBy (compare `on` dynPrecedence) registeredFunctors))
-- | Read coalgebra from file. See 'parseCoalgebra' for details.
......
......@@ -111,8 +111,8 @@ instance Eq1 SomeFunctor where
instance Show1 SomeFunctor where
liftShowsPrec show' showList' prec (SomeFunctor f) = liftShowsPrec show' showList' prec f
functors :: [[FunctorParser SomeFunctor]]
functors = [[transParser SomeFunctor prefixParser], [transParser SomeFunctor postfixParser]]
functors :: [FunctorParser SomeFunctor]
functors = [transParser SomeFunctor prefixParser, transParser SomeFunctor postfixParser]
-- Helpers
......
......@@ -25,11 +25,11 @@ spec = do
functorExpressionSpec :: Spec
functorExpressionSpec = describe "functorExpression" $ do
it "parses a normal B correctly" $
parseFunctorExpression [[functorExprParser bag]] "" "BX" `shouldParse` (Functor 1 (Bag Variable))
parseFunctorExpression [functorExprParser @Bag] "" "BX" `shouldParse` (Functor 1 (Bag Variable))
it "parses a unicode B (Ɓ) correctly" $
parseFunctorExpression [[functorExprParser bag]] "" "ƁX" `shouldParse` (Functor 1 (Bag Variable))
parseFunctorExpression [functorExprParser @Bag] "" "ƁX" `shouldParse` (Functor 1 (Bag Variable))
parseMorphismPointSpec :: Spec
parseMorphismPointSpec = describe "parseMorphismPoint" $ do
......
......@@ -27,10 +27,10 @@ spec = do
functorExpressionSpec :: Spec
functorExpressionSpec = describe "functorExpression" $ do
it "parses a normal D correctly" $
parseFunctorExpression [[functorExprParser distribution]] "" "DX" `shouldParse` (Functor 1 (Distribution Variable))
parseFunctorExpression [functorExprParser @Distribution] "" "DX" `shouldParse` (Functor 1 (Distribution Variable))
it "parses a unicode D (Ɗ) correctly" $
parseFunctorExpression [[functorExprParser distribution]] "" "ƊX" `shouldParse` (Functor 1 (Distribution Variable))
parseFunctorExpression [functorExprParser @Distribution] "" "ƊX" `shouldParse` (Functor 1 (Distribution Variable))
parseMorphismPointSpec :: Spec
parseMorphismPointSpec = describe "parseMorphismPoint" $ do
......
......@@ -27,7 +27,7 @@ spec = do
parseIntSpec :: Spec
parseIntSpec = describe "Int-valued parser" $ do
it "parses Z^X" $
parseFunctorExpression [[functorExprParser intValued]] "" "Z^X"
parseFunctorExpression [functorExprParser @IntValued] "" "Z^X"
`shouldParse` (Functor 1 (GroupValued Variable))
parseMorphismPointIntSpec :: Spec
......
......@@ -53,7 +53,7 @@ spec = do
maxIntParseSpec :: Spec
maxIntParseSpec = describe "maxInt parsing" $ do
makeFunctorParseSpec maxIntValued ("Z", Just "ℤ") "max"
makeFunctorParseSpec @(Max Int) ("Z", Just "ℤ") "max"
let p = makeMorphParser @(Max Int)
......@@ -70,7 +70,7 @@ maxIntParseSpec = describe "maxInt parsing" $ do
minIntParseSpec :: Spec
minIntParseSpec = describe "minIntParse" $ do
makeFunctorParseSpec minIntValued ("Z", Just "ℤ") "min"
makeFunctorParseSpec @(Min Int) ("Z", Just "ℤ") "min"
let p = makeMorphParser @(Min Int)
......@@ -89,7 +89,7 @@ minIntParseSpec = describe "minIntParse" $ do
maxIntRefineSpec :: Spec
maxIntRefineSpec = describe "maxInt refine" $ do
let p = makeMorphParser @(Max Int)
proxy = Proxy @(Desorted (SlowMonoidValued (Max Int)))
proxy = Proxy @(Desorted MaxIntValued)
it "it distinguishes different maximas with equal sums" $ do
let Right enc = p "x: {x: 1, y: 3}\ny: {x: 2, y: 2}"
......@@ -105,7 +105,7 @@ maxIntRefineSpec = describe "maxInt refine" $ do
minIntRefineSpec :: Spec
minIntRefineSpec = describe "minInt refine" $ do
let p = makeMorphParser @(Min Int)
proxy = Proxy @(Desorted (SlowMonoidValued (Min Int)))
proxy = Proxy @(Desorted MinIntValued)
it "it distinguishes different minimas with equal sums" $ do
let Right enc = p "x: {x: 1, y: 3}\ny: {x: 2, y: 2}"
......@@ -120,7 +120,7 @@ minIntRefineSpec = describe "minInt refine" $ do
maxRealParseSpec :: Spec
maxRealParseSpec = describe "maxReal parsing" $ do
makeFunctorParseSpec maxRealValued ("R", Just "ℝ") "max"
makeFunctorParseSpec @MaxDouble ("R", Just "ℝ") "max"
let p = makeMorphParser @MaxDouble
......@@ -138,7 +138,7 @@ maxRealParseSpec = describe "maxReal parsing" $ do
minRealParseSpec :: Spec
minRealParseSpec = describe "minReal parsing" $ do
makeFunctorParseSpec minRealValued ("R", Just "ℝ") "min"
makeFunctorParseSpec @MinDouble ("R", Just "ℝ") "min"
let p = makeMorphParser @MinDouble
......@@ -157,7 +157,7 @@ minRealParseSpec = describe "minReal parsing" $ do
maxRealRefineSpec :: Spec
maxRealRefineSpec = describe "maxReal refine" $ do
let p = makeMorphParser @MaxDouble
proxy = Proxy @(Desorted (SlowMonoidValued MaxDouble))
proxy = Proxy @(Desorted MaxDoubleValued)
it "it distinguishes different maximas with equal sums" $ do
let Right enc = p "x: {x: 1.1, y: 3.1}\ny: {x: 2.1, y: 2.1}"
......@@ -188,7 +188,7 @@ minRealRefineSpec = describe "minReal refine" $ do
andWordParseSpec :: Spec
andWordParseSpec = describe "bit-and parsing" $ do
makeFunctorParseSpec andWordValued ("Word", Nothing) "and"
makeFunctorParseSpec @(BitAnd Word64) ("Word", Nothing) "and"
let p = makeMorphParser @(BitAnd Word64)
......@@ -220,7 +220,7 @@ andWordRefineSpec = describe "andWord refine" $ do
orWordParseSpec :: Spec
orWordParseSpec = describe "bit-or parsing" $ do
makeFunctorParseSpec orWordValued ("Word", Nothing) "or"
makeFunctorParseSpec @(BitOr Word64) ("Word", Nothing) "or"
let p = makeMorphParser @(BitOr Word64)
......@@ -250,14 +250,14 @@ orWordRefineSpec = describe "orWord refine" $ do
(Part.toBlocks part) `shouldMatchList` [[0, 1]]
makeFunctorParseSpec :: FunctorDescription (SlowMonoidValued m)
-> (Text, Maybe Text)
-> Text
-> Spec
makeFunctorParseSpec functor (setAscii, setUnicode) operation = do
makeFunctorParseSpec :: forall m. FunctorDescription (SlowMonoidValued m)
=> (Text, Maybe Text)
-> Text
-> Spec
makeFunctorParseSpec (setAscii, setUnicode) operation = do
let expr = syntax setAscii operation "X"
it ("can parse " <> T.unpack expr <> " as functor expression")
$ parseFunctorExpression [[functorExprParser functor]] "" expr
$ parseFunctorExpression [functorExprParser @(SlowMonoidValued m)] "" expr
`shouldParse` (Functor 1 (SlowMonoidValued Variable))
case setUnicode of
......@@ -265,11 +265,11 @@ makeFunctorParseSpec functor (setAscii, setUnicode) operation = do
Just set -> do
let expr = syntax set operation "X"
it ("can parse " <> T.unpack expr <> " as functor expression")
$ parseFunctorExpression [[functorExprParser functor]] "" expr
$ parseFunctorExpression [functorExprParser @(SlowMonoidValued m)] "" expr
`shouldParse` (Functor 1 (SlowMonoidValued Variable))
it "nests correctly in functor expressions"
$ parseFunctorExpression [[functorExprParser functor]]
$ parseFunctorExpression [functorExprParser @(SlowMonoidValued m)]
""
(syntax setAscii operation ("(" <> syntax setAscii operation "X" <> ")"))
`shouldParse` (Functor
......@@ -278,9 +278,9 @@ makeFunctorParseSpec functor (setAscii, setUnicode) operation = do
)
it "still parses parenthesis in functor expressions correctly" $ do
parseFunctorExpression [[functorExprParser functor]] "" ("(" <> syntax setAscii operation "X" <> ")")
parseFunctorExpression [functorExprParser @(SlowMonoidValued m)] "" ("(" <> syntax setAscii operation "X" <> ")")
`shouldParse` (Functor 1 (SlowMonoidValued Variable))
parseFunctorExpression [[functorExprParser functor]] "" (syntax setAscii operation "(X)")
parseFunctorExpression [functorExprParser @(SlowMonoidValued m)] "" (syntax setAscii operation "(X)")
`shouldParse` (Functor 1 (SlowMonoidValued Variable))
where syntax set op power = "(" <> set <> ", " <> op <> ")^" <> power
......
......@@ -36,7 +36,7 @@ spec = do
functorExpressionSpec :: Spec
functorExpressionSpec = describe "functorExpression" $ do
let p = parseFunctorExpression [[functorExprParser polynomial]] ""
let p = parseFunctorExpression [functorExprParser @Polynomial] ""
ident = Identity Variable
it "parses a constant" $
......@@ -70,15 +70,15 @@ functorExpressionSpec = describe "functorExpression" $ do
, [ident, c ["d"], ident]]))
it "correctly parses a single subfunctor" $ do
parseFunctorExpression [ [transParser SomeFunctor prefixParser]
, [transParser SomeFunctor (functorExprParser polynomial)]
parseFunctorExpression [ transParser SomeFunctor prefixParser
, transParser SomeFunctor (functorExprParser @Polynomial)
]
""
"P X" `shouldParse` (Functor 2 (SomeFunctor (PrefixFunctor Variable)))
it "parses a product of two subfunctors" $ do
parseFunctorExpression [ [transParser SomeFunctor prefixParser]
, [transParser SomeFunctor (functorExprParser polynomial)]
parseFunctorExpression [ transParser SomeFunctor prefixParser
, transParser SomeFunctor (functorExprParser @Polynomial)
]
""
"PX x PX"
......@@ -90,8 +90,8 @@ functorExpressionSpec = describe "functorExpression" $ do
]])))
it "parses a co-product of two subfunctors" $ do
parseFunctorExpression [ [transParser SomeFunctor prefixParser]
, [transParser SomeFunctor (functorExprParser polynomial)]
parseFunctorExpression [ transParser SomeFunctor prefixParser
, transParser SomeFunctor (functorExprParser @Polynomial)
]
""
"PX + PX"
......
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