Commit a17eec00 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

tests: Reduce code duplication

parent e34f4979
......@@ -151,6 +151,7 @@ test-suite spec
, Copar.Parser.LexerSpec
, Copar.Algorithm.InitializeSpec
, Copar.Algorithm.SplitSpec
, TestHelpers
default-language: Haskell2010
default-extensions: GADTs
, StandaloneDeriving
......
......@@ -4,6 +4,7 @@ module Copar.Coalgebra.ParserSpec (spec) where
import Test.Hspec
import Test.Hspec.Megaparsec
import TestHelpers
import Data.Void
import Control.Exception (evaluate)
......@@ -192,9 +193,3 @@ parsing :: (Functor f, ParseMorphism f) => FunctorExpression f Sort
-> Text
-> Either (ParseErrorBundle Text Void) (Encoding (Sorted (Label f)) (Sorted (F1 f)))
parsing expr = fmap snd . parseMorphisms expr EnableSanityChecks ""
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where
toEdge (from, lab, to) = Encoding.Edge from lab to
......@@ -3,6 +3,7 @@ module Copar.Functors.AbsorbingPolynomialSpec (spec) where
import Test.Hspec
import Test.Hspec.Megaparsec
import TestHelpers
import qualified Data.List.NonEmpty as NonEmpty
import Data.Bifunctor
......@@ -16,7 +17,6 @@ import qualified Data.Vector as V
import Data.Text ( Text )
import Data.MorphismEncoding ( Encoding )
import qualified Data.MorphismEncoding as Encoding
import Copar.Coalgebra.Parser
import Copar.FunctorExpression.Desorting
import Copar.FunctorExpression.Type
......@@ -282,8 +282,3 @@ f1 s v c = (s, V.fromList v, V.fromList c)
v :: [a] -> Vector a
v = V.fromList
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where toEdge (from, lab, to) = Encoding.Edge from lab to
......@@ -2,14 +2,11 @@ module Copar.Functors.BagSpec (spec) where
import Test.Hspec
import Test.Hspec.Megaparsec
import TestHelpers
import Data.Proxy
import Control.Monad.ST
import qualified Data.Vector as V
import Data.MorphismEncoding (Encoding)
import qualified Data.MorphismEncoding as Encoding
import qualified Data.Partition as Part
import Copar.Algorithm
import Copar.Coalgebra.Parser
......@@ -55,9 +52,3 @@ refineSpec = describe "refining" $ do
parseMorphisms f EnableSanityChecks "" "x: {x, x, y}\ny: {x, y}"
in stToIO (refine (Proxy @(Desorted Bag)) enc True)
`shouldReturn` (Part.fromBlocks [[0], [1]])
-- FIXME: Remove duplicate definition of this function
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where
toEdge (from, lab, to) = Encoding.Edge from lab to
......@@ -2,15 +2,12 @@ module Copar.Functors.DistributionSpec (spec) where
import Test.Hspec
import Test.Hspec.Megaparsec
import TestHelpers
import Data.Proxy
import Control.Monad.ST
import Data.Either
import qualified Data.Vector as V
import Data.MorphismEncoding (Encoding)
import qualified Data.MorphismEncoding as Encoding
import qualified Data.Partition as Part
import Copar.Algorithm
import Copar.Coalgebra.Parser
......@@ -85,9 +82,3 @@ refineSpec = describe "refining" $ do
x `shouldSatisfy` isRight
let Right (_, enc) = x
stToIO (refine (Proxy @(Desorted Distribution)) enc True) `shouldReturn` Part.fromBlocks [[0, 1, 2]]
-- FIXME: Remove duplicate definition of this function
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where
toEdge (from, lab, to) = Encoding.Edge from lab to
......@@ -2,21 +2,15 @@ module Copar.Functors.GroupValuedSpec (spec) where
import Test.Hspec
import Test.Hspec.Megaparsec
import TestHelpers
import Data.Complex
import qualified Data.Vector as V
import Data.Text ( Text )
import Copar.Functors.GroupValued
import Data.MorphismEncoding ( Encoding )
import qualified Data.MorphismEncoding as Encoding
import Copar.Coalgebra.Parser
import Copar.FunctorExpression.Type
import Copar.FunctorExpression.Sorts ( Sorted(..) )
import Data.Float.Utils ( EqDouble )
import Copar.Parser.Types
import Copar.RefinementInterface
spec :: Spec
......@@ -103,9 +97,3 @@ parseMorphismPointComplexSpec = describe "parseMorphismPoint (Complex)" $ do
[(0, Sorted 1 (c (-2.3) 0), 0)]
where c a b = OrderedComplex (a :+ b)
-- FIXME: Remove duplicate definition of this function
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where toEdge (from, lab, to) = Encoding.Edge from lab to
......@@ -4,6 +4,7 @@
module Copar.Functors.MonoidValuedSpec (spec) where
import Test.Hspec
import TestHelpers (encoding)
import Data.Semigroup ( Max(..)
, Min(..)
......@@ -12,15 +13,12 @@ import Control.Monad.ST
import Data.Proxy
import Test.Hspec.Megaparsec
import qualified Data.Vector as V
import Copar.FunctorExpression.Parser
import Copar.Functors.MonoidValued
import Copar.FunctorExpression.Type
import Copar.FunctorDescription
import Copar.Coalgebra.Parser
import Data.MorphismEncoding ( Encoding )
import qualified Data.MorphismEncoding as Encoding
import Copar.FunctorExpression.Sorts ( Sorted(..) )
import Copar.FunctorExpression.Desorting
import qualified Data.Partition as Part
......@@ -276,8 +274,3 @@ minRealRefineSpec = describe "minReal refine" $ do
let Right enc = p "x: {x: 1.1, y: 3.1}\ny: {x: 1.1, y: 2.1}"
part <- stToIO (refine proxy enc True)
(Part.toBlocks part) `shouldMatchList` [[0, 1]]
-- FIXME: Remove duplicate definition of this function
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where toEdge (from, lab, to) = Encoding.Edge from lab to
......@@ -2,6 +2,7 @@ module Copar.Functors.PolynomialSpec (spec) where
import Test.Hspec
import Test.Hspec.Megaparsec
import TestHelpers
import Data.List (isInfixOf)
import Control.Monad.ST
......@@ -19,8 +20,6 @@ import Data.Text (Text)
import qualified Copar.Parser.Lexer as L
import Copar.Algorithm
import qualified Data.Partition as Part
import Data.MorphismEncoding (Encoding)
import qualified Data.MorphismEncoding as Encoding
import Copar.Coalgebra.Parser
import Copar.FunctorExpression.Desorting
import Copar.FunctorExpression.Type
......@@ -389,8 +388,3 @@ f1 s v = PolyF1 s v . V.fromList
v :: [a] -> Vector a
v = V.fromList
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where
toEdge (from, lab, to) = Encoding.Edge from lab to
......@@ -2,12 +2,9 @@ module Copar.Functors.PowersetSpec (spec) where
import Test.Hspec
import Test.Hspec.Megaparsec
import qualified Data.Vector as V
import TestHelpers
import Copar.Functors.Powerset
import Data.MorphismEncoding (Encoding)
import qualified Data.MorphismEncoding as Encoding
import Copar.Coalgebra.Parser
import Copar.FunctorExpression.Type
import Copar.FunctorExpression.Sorts (Sorted(..))
......@@ -27,9 +24,3 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
it "errors on duplicate edges" $
parseMorphisms (Functor 1 (Powerset Variable)) EnableSanityChecks "" `shouldFailOn` "x: {x, x}"
-- FIXME: Remove duplicate definition of this function
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where
toEdge (from, lab, to) = Encoding.Edge from lab to
module TestHelpers (encoding) where
import Data.MorphismEncoding (Encoding)
import qualified Data.MorphismEncoding as Encoding
import qualified Data.Vector as V
encoding :: [f1] -> [(Int, l, Int)] -> Encoding l f1
encoding f1 es = Encoding.new (V.fromList f1) (V.fromList (map toEdge es))
where toEdge (from, lab, to) = Encoding.Edge from lab to
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