Exemplo n.º 1
0
 def test_dont_replace_macro_argument(self):
     let_dict = {Identifier.parse("a"): 3.14}
     parser = make_lark_parser(start="macro_definition")
     text = "macro foo a { g a }"
     exp_tree = parser.parse(text)
     act_tree = resolve_let(exp_tree, let_dict)
     self.assertEqual(exp_tree, act_tree)
Exemplo n.º 2
0
 def test_replace_register_statement(self):
     let_dict = {Identifier.parse("a"): 1}
     parser = make_lark_parser(start="register_statement")
     text = "register q[a]"
     exp_text = "register q[1]"
     exp_tree = parser.parse(exp_text)
     act_tree = resolve_let(parser.parse(text), let_dict)
     self.assertEqual(exp_tree, act_tree)
Exemplo n.º 3
0
 def test_replace_loop_count(self):
     let_dict = {Identifier.parse("a"): 1}
     parser = make_lark_parser(start="loop_statement")
     text = "loop a { g }"
     exp_text = "loop 1 { g }"
     exp_tree = parser.parse(exp_text)
     act_tree = resolve_let(parser.parse(text), let_dict)
     self.assertEqual(exp_tree, act_tree)
Exemplo n.º 4
0
 def test_replace_array_index(self):
     let_dict = {Identifier.parse("a"): 1}
     parser = make_lark_parser(start="gate_statement")
     text = "g arr[a]"
     exp_text = "g arr[1]"
     exp_tree = parser.parse(exp_text)
     act_tree = resolve_let(parser.parse(text), let_dict)
     self.assertEqual(exp_tree, act_tree)
Exemplo n.º 5
0
 def test_replace_gate_arg(self):
     """Test replacing a single gate argument."""
     let_dict = {Identifier.parse("a"): 1}
     parser = make_lark_parser(start="gate_statement")
     text = "g a"
     exp_text = "g 1"
     exp_tree = parser.parse(exp_text)
     act_tree = resolve_let(parser.parse(text), let_dict)
     self.assertEqual(exp_tree, act_tree)
Exemplo n.º 6
0
 def test_replace_map_statement(self):
     let_dict = {
         Identifier.parse("a"): 1,
         Identifier.parse("b"): 10,
         Identifier.parse("c"): 2,
     }
     parser = make_lark_parser(start="map_statement")
     text = "map arr q[a:b:c]"
     exp_text = "map arr q[1:10:2]"
     exp_tree = parser.parse(exp_text)
     act_tree = resolve_let(parser.parse(text), let_dict)
     self.assertEqual(exp_tree, act_tree)
Exemplo n.º 7
0
 def test_reject_non_integer_register_statement(self):
     let_dict = {Identifier.parse("a"): 3.14}
     parser = make_lark_parser(start="register_statement")
     text = "register q[a]"
     with self.assertRaises(Exception):
         resolve_let(parser.parse(text), let_dict)
Exemplo n.º 8
0
 def test_reject_non_integer_loop_count(self):
     let_dict = {Identifier.parse("a"): 12.34}
     parser = make_lark_parser(start="loop_statement")
     text = "loop a { g }"
     with self.assertRaises(Exception):
         resolve_let(parser.parse(text), let_dict)