Skip to content

Commit 01276ea

Browse files
committed
Adding tests and fixing bugs.
1 parent d4433b6 commit 01276ea

18 files changed

+47
-15
lines changed

src/Backend/ASTtoIASTConverter.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ data BasisState =
4040
BasisStateMinusI
4141
deriving (Eq, Ord, Show, Read)
4242

43-
data ControlBasisState = CtrlBasisState BasisState
43+
newtype ControlBasisState = CtrlBasisState BasisState
4444
deriving (Eq, Ord, Show, Read)
4545

4646
data ControlBasisStates = CtrlBasisStates BasisState [BasisState]

test/Backend/ASTtoIASTConverterSpec.hs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,30 @@ spec = do
8383

8484
context "when provided with a small program fragment" $ do
8585
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
86-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_0.lq"
86+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_0.lq"
8787
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
8888
result `shouldSatisfy` (\str -> "TypeUnit" `isInfixOf` str)
8989
result `shouldSatisfy` (\str -> "TermUnit" `isInfixOf` str)
9090

9191
context "when provided with a small program fragment" $ do
9292
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
93-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_1.lq"
93+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_1.lq"
9494
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
9595
result `shouldSatisfy` (\str -> "TypeBit" `isInfixOf` str)
9696
result `shouldSatisfy` (\str -> "TermBit" `isInfixOf` str)
9797
result `shouldSatisfy` (\str -> "BitValue 1" `isInfixOf` str)
9898

9999
context "when provided with a small program fragment" $ do
100100
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
101-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_2.lq"
101+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_2.lq"
102102
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
103103
result `shouldSatisfy` (\str -> "TypeNonLinear TypeBit" `isInfixOf` str)
104104
result `shouldSatisfy` (\str -> "TermBit" `isInfixOf` str)
105105
result `shouldSatisfy` (\str -> "BitValue 1" `isInfixOf` str)
106106

107107
context "when provided with a small program fragment" $ do
108108
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
109-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_3.lq"
109+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_3.lq"
110110
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
111111
result `shouldSatisfy` (\str -> "TypeQbit" `isInfixOf` str)
112112
result `shouldSatisfy` (\str -> "TermApply" `isInfixOf` str)
@@ -115,7 +115,7 @@ spec = do
115115

116116
context "when provided with a small program fragment" $ do
117117
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
118-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_4.lq"
118+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_4.lq"
119119
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
120120
result `shouldSatisfy` (\str -> "TypeBit" `isInfixOf` str)
121121
result `shouldSatisfy` (\str -> "TermApply (TermMeasure (2,7)" `isInfixOf` str)
@@ -124,7 +124,7 @@ spec = do
124124

125125
context "when provided with a small program fragment" $ do
126126
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
127-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_5.lq"
127+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_5.lq"
128128
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
129129
result `shouldSatisfy` (\str -> "TypeNonLinear (TypeNonLinear TypeBit)" `isInfixOf` str)
130130
result `shouldSatisfy` (\str -> "TermApply (TermMeasure (2,7)" `isInfixOf` str)
@@ -133,7 +133,7 @@ spec = do
133133

134134
context "when provided with a small program fragment" $ do
135135
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
136-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_6.lq"
136+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_6.lq"
137137
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
138138
result `shouldSatisfy` (\str -> "TypeBit" `isInfixOf` str)
139139
result `shouldSatisfy` (\str -> "TermApply (TermMeasure (2,7)" `isInfixOf` str)
@@ -143,7 +143,7 @@ spec = do
143143

144144
context "when provided with a small program fragment" $ do
145145
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
146-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_7.lq"
146+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_7.lq"
147147
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
148148
result `shouldSatisfy` (\str -> "TypeNonLinear TypeBit" `isInfixOf` str)
149149
result `shouldSatisfy` (\str -> "TermApply (TermMeasure (2,7)" `isInfixOf` str)
@@ -154,7 +154,7 @@ spec = do
154154
-- TODO: fix
155155
-- context "when provided with a small program fragment" $ do
156156
-- it "returns a syntax tree processed in the intermediate syntax tree format" $ do
157-
-- result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_8.lq"
157+
-- result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_8.lq"
158158
-- result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
159159
-- result `shouldSatisfy` (\str -> "TypeNonLinear TypeBit" `isInfixOf` str)
160160
-- result `shouldSatisfy` (\str -> "TermApply (TermMeasure (2,7)" `isInfixOf` str)
@@ -164,7 +164,7 @@ spec = do
164164

165165
context "when provided with a small program fragment" $ do
166166
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
167-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_9.lq"
167+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_9.lq"
168168
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
169169
result `shouldSatisfy` (\str -> "TypeNonLinear TypeBit" `isInfixOf` str)
170170
result `shouldSatisfy` (\str -> "TermLetMultiple" `isInfixOf` str)
@@ -173,7 +173,7 @@ spec = do
173173

174174
context "when provided with a small program fragment" $ do
175175
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
176-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_10.lq"
176+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_10.lq"
177177
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
178178
result `shouldSatisfy` (\str -> "TypeNonLinear TypeBit" `isInfixOf` str)
179179
result `shouldSatisfy` (\str -> "TermLetMultiple" `isInfixOf` str)
@@ -183,17 +183,40 @@ spec = do
183183

184184
context "when provided with a small program fragment" $ do
185185
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
186-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_11.lq"
186+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_11.lq"
187187
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
188188
result `shouldSatisfy` (\str -> "TypeNonLinear TypeBit" `isInfixOf` str)
189189
result `shouldSatisfy` (\str -> "TermLetSugarMultiple (TermTuple (TermApply (TermNew (2,18)) (TermBasisState BasisStateOne)) (TermApply (TermNew (2,26)) (TermBasisState BasisStateZero)))" `isInfixOf` str)
190190
result `shouldSatisfy` (\str -> "TermBit (BitValue 1)" `isInfixOf` str)
191191

192192
context "when provided with a small program fragment" $ do
193193
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
194-
result <- testProgramAndShowResults "test/programs/ast-conversion/program_fragment_12.lq"
194+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_12.lq"
195195
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
196196
result `shouldSatisfy` (\str -> "TypeNonLinear TypeBit" `isInfixOf` str)
197197
result `shouldSatisfy` (\str -> "TermLetSugarMultiple (TermTuple (TermApply (TermNew (2,18)) (TermBasisState BasisStateOne)) (TermApply (TermNew (2,26)) (TermBasisState BasisStateZero)))" `isInfixOf` str)
198198
result `shouldSatisfy` (\str -> "TermVariable (Var ((3,38),gate))" `isInfixOf` str)
199-
result `shouldSatisfy` (\str -> "(TermGate GateX)) (TermVariable (Var ((3,45),q2)))" `isInfixOf` str)
199+
result `shouldSatisfy` (\str -> "(TermGate GateX)) (TermVariable (Var ((3,45),q2)))" `isInfixOf` str)
200+
201+
context "when provided with a small program fragment" $ do
202+
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
203+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_13.lq"
204+
result `shouldSatisfy` (\str -> "Function fun (2,1) TypeBit" `isInfixOf` str)
205+
result `shouldSatisfy` (\str -> "TermTuple (TermApply (TermNew (2,27)) (TermBasisState BasisStateOne)) (TermTuple (TermApply (TermNew (2,35)) (TermBasisState BasisStateZero)) (TermApply (TermNew (2,43)) (TermBasisState BasisStateOne))" `isInfixOf` str)
206+
result `shouldSatisfy` (\str -> "TermQuantumCtrlsGate TermVariable (Var ((3,22),q1)),TermVariable (Var ((3,28),q2)) BasisStateOne,BasisStatePlusI)" `isInfixOf` str)
207+
result `shouldSatisfy` (\str -> "(TermGate GateX)) (TermVariable (Var ((3,58),q3)))" `isInfixOf` str)
208+
209+
context "when provided with a small program fragment" $ do
210+
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
211+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_14.lq"
212+
result `shouldSatisfy` (\str -> "Function fun (2,1) TypeBit" `isInfixOf` str)
213+
result `shouldSatisfy` (\str -> "(TermLetSugarMultiple (TermTuple (TermApply (TermNew (2,26)) (TermBasisState BasisStateZero)) (TermTuple (TermApply (TermNew (2,34)) (TermBasisState BasisStateZero)) (TermTuple (TermApply (TermNew (2,42)) (TermBasisState BasisStateZero)) (TermApply (TermNew (2,50)) (TermBasisState BasisStateZero)))))" `isInfixOf` str)
214+
result `shouldSatisfy` (\str -> "TermQuantumCtrlsGate TermVariable (Var ((3,22),q1)),TermVariable (Var ((3,28),q3)),TermVariable (Var ((3,34),q4)) BasisStateOne,BasisStateOne,BasisStateOne)" `isInfixOf` str)
215+
result `shouldSatisfy` (\str -> "(TermGate GateY)) (TermVariable (Var ((3,67),q2)))" `isInfixOf` str)
216+
217+
context "when provided with a small program fragment" $ do
218+
it "returns a syntax tree processed in the intermediate syntax tree format" $ do
219+
result <- testProgramAndShowResults "test/programs/code-fragments/program_fragment_15.lq"
220+
result `shouldSatisfy` (\str -> "Function fun (2,1)" `isInfixOf` str)
221+
result `shouldSatisfy` (\str -> "TypeQbit" `isInfixOf` str)
222+
result `shouldSatisfy` (\str -> "TermApply (TermNew (2,7)) (TermBasisState BasisStateZero)" `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 (q1, q2, q3) = (new @1, new @0, new @1) in
3+
measr (with [ (q1), (q2) ] ctrl [ @1, @+i ] gate X q3) --TODO: fix grammar and remove paranthesis
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fun :: Bit
2+
fun = q1, q2, q3, q4 <- (new @0, new @0, new @0, new @0);
3+
measr (with [ (q1), (q3), (q4) ] ctrl [ @1, @1, @1 ] gate Y q2) --TODO: fix grammar and remove paranthesis
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+

0 commit comments

Comments
 (0)