aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-12-23 11:27:11 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-12-23 11:27:18 +0000
commit434c2828ab622c4b9d07a1f1a8a09ede0696f4e0 (patch)
tree4a8ff0f4b78640a596b5cea26725bf991c65f070 /tests
parent856034f1eaa0785cb9f29717fc32d0d6ed798460 (diff)
downloadverismith-434c2828ab622c4b9d07a1f1a8a09ede0696f4e0.tar.gz
verismith-434c2828ab622c4b9d07a1f1a8a09ede0696f4e0.zip
Add unit tests for the traversal
Diffstat (limited to 'tests')
-rw-r--r--tests/Property.hs2
-rw-r--r--tests/Test.hs2
-rw-r--r--tests/Unit.hs50
3 files changed, 46 insertions, 8 deletions
diff --git a/tests/Property.hs b/tests/Property.hs
index 88330bd..55b7f31 100644
--- a/tests/Property.hs
+++ b/tests/Property.hs
@@ -9,7 +9,7 @@ newtype TestGraph = TestGraph { getGraph :: Gr Gate () }
deriving (Show)
instance QC.Arbitrary TestGraph where
- arbitrary = TestGraph <$> randomDAG 100
+ arbitrary = TestGraph <$> randomDAG 30
simpleGraph = QC.testProperty "simple graph generation" $
\graph -> simp (graph :: TestGraph)
diff --git a/tests/Test.hs b/tests/Test.hs
index c234b90..08a4799 100644
--- a/tests/Test.hs
+++ b/tests/Test.hs
@@ -2,10 +2,10 @@ module Main where
import Property
import Test.Tasty
+import Test.VeriFuzz
import Unit
tests :: TestTree
tests = testGroup "Tests" [unitTests, propertyTests]
main = defaultMain tests
-
diff --git a/tests/Unit.hs b/tests/Unit.hs
index a04098b..976f23b 100644
--- a/tests/Unit.hs
+++ b/tests/Unit.hs
@@ -1,13 +1,51 @@
+{-# LANGUAGE OverloadedStrings #-}
+
module Unit (unitTests) where
+import Control.Lens
+import qualified Data.Graph.Inductive as G
+import Data.Text (Text)
+import qualified Data.Text as T
import Test.Tasty
import Test.Tasty.HUnit
+import Test.VeriFuzz
unitTests = testGroup "Unit tests"
- [ testCase "List comparison (different length)" $
- [1, 2, 3] `compare` [1,2] @?= GT
-
- -- the following test does not hold
- , testCase "List comparison (same length)" $
- [1, 2, 3] `compare` [1,2,2] @?= GT
+ [ testCase "Transformation of AST" $
+ assertEqual "Successful transformation" transformExpectedResult
+ (transformOf traverseExpr trans transformTestData)
]
+
+primExpr :: Text -> Expression
+primExpr = PrimExpr . PrimId . Identifier
+
+transformTestData :: Expression
+transformTestData = OpExpr (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
+ (OpExpr (primExpr "id1") BinAnd (primExpr "id2"))) BinAnd
+ (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
+ (OpExpr (primExpr "id1") BinAnd (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
+ (OpExpr (primExpr "id1") BinAnd (primExpr "id2")))))
+
+transformExpectedResult :: Expression
+transformExpectedResult = OpExpr (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")) BinAnd
+ (OpExpr (primExpr "id1") BinAnd (primExpr "Replaced"))) BinAnd
+ (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")) BinAnd
+ (OpExpr (primExpr "id1") BinAnd (OpExpr (OpExpr (primExpr "id1") BinAnd
+ (primExpr "Replaced")) BinAnd
+ (OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")))))
+
+trans e =
+ case e of
+ PrimExpr (PrimId id) -> if id == Identifier "id2" then
+ PrimExpr . PrimId $ Identifier "Replaced"
+ else PrimExpr (PrimId id)
+ _ -> e
+
+runMain = do
+ gr <- genRandomDAG 100 :: IO (G.Gr Gate ())
+-- _ <- runGraphviz (graphToDot quickParams $ emap (const "") gr) Png "output.png",
+-- T.putStrLn $ generate gr
+ --g <- QC.generate (QC.arbitrary :: QC.Gen SourceText)
+ let x = generateAST $ Circuit gr
+ let y = head . reverse $ x ^.. getSourceText . traverse . getDescription . moduleItems . traverse . _Assign . contAssignExpr
+ print $ transformOf traverseExpr trans y