Skip to content

Commit 06c2e51

Browse files
committed
Adding tests.
1 parent e4861c1 commit 06c2e51

File tree

7 files changed

+66
-6
lines changed

7 files changed

+66
-6
lines changed

test/Backend/ASTtoIASTConverterSpec.hs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,57 @@ spec = do
214214
result `shouldSatisfy` (\str -> "TermQuantumCtrlsGate TermVariable (Var ((3,22),q1)),TermVariable (Var ((3,28),q3)),TermVariable (Var ((3,34),q4)) BasisStateOne,BasisStateOne,BasisStateOne)" `isInfixOf` str)
215215
result `shouldSatisfy` (\str -> "(TermGate GateY)) (TermVariable (Var ((3,67),q2)))" `isInfixOf` str)
216216

217-
-- do let single
218-
-- do let sugar single
219-
-- do let multiple
220217

221218
context "when provided with a small program fragment" $ do
222219
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
223-
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_18.lq"
220+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_15.lq"
221+
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
222+
result `shouldSatisfy` (\str -> "TypeBit" `isInfixOf` str)
223+
result `shouldSatisfy` (\str -> "TermApply (TermNew (2,16)) (TermBasisState BasisStateMinusI)" `isInfixOf` str)
224+
result `shouldSatisfy` (\str -> "TermMeasure (3,7)" `isInfixOf` str)
225+
result `shouldSatisfy` (\str -> "(TermVariable (Var ((3,14),gate))) (TermGate GateX))" `isInfixOf` str)
226+
result `shouldSatisfy` (\str -> "TermVariable (Var ((3,21),q)))" `isInfixOf` str)
227+
228+
context "when provided with a small program fragment" $ do
229+
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
230+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_16.lq"
231+
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
232+
result `shouldSatisfy` (\str -> "TypeBit" `isInfixOf` str)
233+
result `shouldSatisfy` (\str -> "(TermApply (TermNew (2,12)) (TermBasisState BasisStateZero)" `isInfixOf` str)
234+
result `shouldSatisfy` (\str -> "TermMeasure (3,7)" `isInfixOf` str)
235+
result `shouldSatisfy` (\str -> "(TermVariable (Var ((3,14),gate))) (TermGate GateZ))" `isInfixOf` str)
236+
result `shouldSatisfy` (\str -> "TermVariable (Var ((3,21),q)))" `isInfixOf` str)
237+
238+
context "when provided with a small program fragment" $ do
239+
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
240+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_17.lq"
224241
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
225242
result `shouldSatisfy` (\str -> "TypeQbit" `isInfixOf` str)
226243
result `shouldSatisfy` (\str -> "TermApply (TermNew (2,7)) (TermBasisState BasisStateZero)" `isInfixOf` str)
227244

245+
context "when provided with a small program fragment" $ do
246+
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
247+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_18.lq"
248+
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
249+
result `shouldSatisfy` (\str -> "TypeQbit :**: 3" `isInfixOf` str)
250+
result `shouldSatisfy` (\str -> "TermTuple (TermApply (TermNew" `isInfixOf` str)
251+
result `shouldSatisfy` (\str -> "TermBasisState BasisStateZero" `isInfixOf` str)
252+
253+
context "when provided with a small program fragment" $ do
254+
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
255+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_19.lq"
256+
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
257+
result `shouldSatisfy` (\str -> "TypeQbit :*: TypeQbit" `isInfixOf` str)
258+
result `shouldSatisfy` (\str -> "TermTuple" `isInfixOf` str)
259+
result `shouldSatisfy` (\str -> "(TermApply (TermVariable (Var ((2,8),gate))) (TermGate GateH)) (TermNew (2,15))) (TermBasisState BasisStateZero))" `isInfixOf` str)
260+
261+
context "when provided with a small program fragment" $ do
262+
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
263+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_20.lq"
264+
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
265+
result `shouldSatisfy` (\str -> "TypeQbit" `isInfixOf` str)
266+
result `shouldSatisfy` (\str -> "TermLetSingle" `isInfixOf` str)
267+
result `shouldSatisfy` (\str -> "(TermMeasure (2,17)) (TermVariable (Var ((2,23),gate)))) (TermGate GateH)) (TermNew (2,30))) (TermBasisState BasisStateZero))" `isInfixOf` str)
268+
result `shouldSatisfy` (\str -> "TermIfElse (TermVariable (Var ((3,10),bit))" `isInfixOf` str)
269+
result `shouldSatisfy` (\str -> "TermApply (TermApply (TermApply (TermVariable (Var ((3,19),gate))) (TermGate GateH)) (TermNew (3,26))" `isInfixOf` str)
270+
result `shouldSatisfy` (\str -> "TermApply (TermNew (3,38)) (TermBasisState BasisStateOne)" `isInfixOf` str)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fun :: Bit
2+
fun = let q = (new @-i) in
3+
measr (gate X q)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fun :: Bit
2+
fun = q <- new @0;
3+
measr (gate Z q)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fun :: Qbit
2+
fun = new @0
3+
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
fun :: Qbit
2-
fun = new @0
1+
fun :: Qbit ** 3
2+
fun = (new @0, new @0, new @0)
33

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fun :: Qbit * Qbit
2+
fun = (gate H new @0, gate H new @0)
3+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fun :: Qbit
2+
fun = let bit = measr gate H new @0 in
3+
if bit then gate H new @0 else new @1
4+
5+

0 commit comments

Comments
 (0)