Example #1
0
 def run_test(self, setup_text, gate_text, exp_result):
     parser = make_lark_parser()
     map_dict, register_dict = extract_map(parser.parse(setup_text))
     act_tree = resolve_map(parser.parse(gate_text), map_dict,
                            register_dict)
     act_result = self.simplify_tree(act_tree)
     self.assertEqual(exp_result, act_result)
Example #2
0
 def test_forbid_mapping_whole_register(self):
     """Test that we throw an error when using a mapping in a context where a register element is expected."""
     setup_text = "register r[7]; map a r"
     gate_text = "foo a"
     with self.assertRaises(Exception):
         parser = make_lark_parser()
         map_dict, register_dict = extract_map(parser.parse(setup_text))
         resolve_map(parser.parse(gate_text), map_dict, register_dict)
Example #3
0
 def test_forbid_nonexistent_mapping(self):
     """Test that we throw an error when attempting to map to a nonexistent register."""
     setup_text = "register r[7]; map a q[1]"
     gate_text = "foo a"
     with self.assertRaises(Exception):
         parser = make_lark_parser()
         map_dict, register_dict = extract_map(parser.parse(setup_text))
         resolve_map(parser.parse(gate_text), map_dict, register_dict)
Example #4
0
 def run_test(self, text, exp_result):
     parser = make_lark_parser()
     tree = parser.parse(text)
     act_result, _ = extract_map(tree)
     self.assertEqual(exp_result, act_result)
Example #5
0
 def test_no_existing_register(self):
     text = "map a q"
     parser = make_lark_parser()
     tree = parser.parse(text)
     with self.assertRaises(Exception):
         extract_map(tree)