diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Property.hs | 16 | ||||
-rw-r--r-- | test/Unit.hs | 95 |
2 files changed, 76 insertions, 35 deletions
diff --git a/test/Property.hs b/test/Property.hs index 80c6f68..c6ca390 100644 --- a/test/Property.hs +++ b/test/Property.hs @@ -1,4 +1,7 @@ -module Property (propertyTests) where +module Property + ( propertyTests + ) +where import qualified Data.Graph.Inductive as G import Data.Graph.Inductive.PatriciaTree (Gr) @@ -19,16 +22,11 @@ instance QC.Arbitrary TestGraph where instance QC.Arbitrary AltTestGraph where arbitrary = AltTestGraph <$> QC.resize 100 V.randomDAG -simpleGraph = QC.testProperty "simple graph generation check" $ - \graph -> simp graph +simpleGraph = QC.testProperty "simple graph generation check" $ \graph -> simp graph where simp = G.isSimple . getGraph -simpleAltGraph = QC.testProperty "simple alternative graph generation check" $ - \graph -> simp graph +simpleAltGraph = QC.testProperty "simple alternative graph generation check" $ \graph -> simp graph where simp = G.isSimple . getAltGraph propertyTests :: TestTree -propertyTests = testGroup "Property Tests" - [ simpleGraph - , simpleAltGraph - ] +propertyTests = testGroup "Property Tests" [simpleGraph, simpleAltGraph] diff --git a/test/Unit.hs b/test/Unit.hs index 8bcc702..a72e188 100644 --- a/test/Unit.hs +++ b/test/Unit.hs @@ -1,4 +1,7 @@ -module Unit (unitTests) where +module Unit + ( unitTests + ) +where import Control.Lens import qualified Data.Graph.Inductive as G @@ -8,35 +11,75 @@ import Test.Tasty import Test.Tasty.HUnit import VeriFuzz -unitTests = testGroup "Unit tests" - [ testCase "Transformation of AST" $ - assertEqual "Successful transformation" transformExpectedResult +unitTests = testGroup + "Unit tests" + [ testCase "Transformation of AST" $ assertEqual + "Successful transformation" + transformExpectedResult (transformOf traverseExpr trans transformTestData) ] transformTestData :: Expr -transformTestData = BinOp (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd - (BinOp (Id "id1") BinAnd (Id "id2"))) BinAnd - (BinOp (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd - (BinOp (Id "id1") BinAnd (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd - (BinOp (Id "id1") BinAnd (Id "id2"))))) BinOr - (Concat [Concat [ Concat [Id "id1", Id "id2", Id "id2"], Id "id2", Id "id2" - , Concat [Id "id2", Id "id2", Concat [Id "id1", Id "id2"]] - , Id "id2"], Id "id1", Id "id2"])) +transformTestData = BinOp + (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd (BinOp (Id "id1") BinAnd (Id "id2"))) + BinAnd + (BinOp + (BinOp + (BinOp (Id "id1") BinAnd (Id "id2")) + BinAnd + (BinOp + (Id "id1") + BinAnd + (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd (BinOp (Id "id1") BinAnd (Id "id2"))) + ) + ) + BinOr + (Concat + [ Concat + [ Concat [Id "id1", Id "id2", Id "id2"] + , Id "id2" + , Id "id2" + , Concat [Id "id2", Id "id2", Concat [Id "id1", Id "id2"]] + , Id "id2" + ] + , Id "id1" + , Id "id2" + ] + ) + ) transformExpectedResult :: Expr -transformExpectedResult = BinOp (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) BinAnd - (BinOp (Id "id1") BinAnd (Id "Replaced"))) BinAnd - (BinOp (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) BinAnd - (BinOp (Id "id1") BinAnd (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) BinAnd - (BinOp (Id "id1") BinAnd (Id "Replaced"))))) BinOr - (Concat [Concat [ Concat [Id "id1", Id "Replaced", Id "Replaced"], Id "Replaced", Id "Replaced" - , Concat [Id "Replaced", Id "Replaced", Concat [Id "id1", Id "Replaced"]] - , Id "Replaced"], Id "id1", Id "Replaced"])) +transformExpectedResult = BinOp + (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) BinAnd (BinOp (Id "id1") BinAnd (Id "Replaced"))) + BinAnd + (BinOp + (BinOp + (BinOp (Id "id1") BinAnd (Id "Replaced")) + BinAnd + (BinOp + (Id "id1") + BinAnd + (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) + BinAnd + (BinOp (Id "id1") BinAnd (Id "Replaced")) + ) + ) + ) + BinOr + (Concat + [ Concat + [ Concat [Id "id1", Id "Replaced", Id "Replaced"] + , Id "Replaced" + , Id "Replaced" + , Concat [Id "Replaced", Id "Replaced", Concat [Id "id1", Id "Replaced"]] + , Id "Replaced" + ] + , Id "id1" + , Id "Replaced" + ] + ) + ) -trans e = - case e of - Id id -> if id == Identifier "id2" then - Id $ Identifier "Replaced" - else Id id - _ -> e +trans e = case e of + Id id -> if id == Identifier "id2" then Id $ Identifier "Replaced" else Id id + _ -> e |