def test_wrap_type(self): mark = 'm' t1 = origin.UFGround(1, "t", None) t2 = origin.UFGround(1, "t", ('n', None)) t3 = origin.UFDisj((t1, t2)) t4 = origin.UFConj(( t1, origin.UFConj((t2, t1)), origin.UFBot(), t3)) e1 = origin.UFGround(1, "t", (mark, None)) e2 = origin.UFGround(1, "t", (mark, ('n', None))) e3 = origin.UFDisj((e1, e2)) e4 = origin.UFConj(( e1, origin.UFConj((e2, e1)), origin.UFBot(), e3)) self.assertEqual(e4, origin.wrap_type(t4, mark))
def test_initialize_types_and_get_atom_types(self): rules = parser.wrapped_parse(prog0) atom_t = rules[0].head atom_z = ast.Atom('z', []) external = {'q': ['int', 'int'], 'p': ['int']} unfold = origin.Origin(rules, external) unfold.initialize_types() self.assertEqual( [origin.UFBot(), origin.UFGround(1, "t", None)], unfold.table_types['t']) self.assertEqual( origin.UFBot(), unfold.get_atom_type(atom_t, 0)) self.assertEqual(None, unfold.get_atom_type(atom_t, 3)) self.assertEqual(None, unfold.get_atom_type(atom_z, 0))
def test_weight_type(self): t1 = origin.UFGround(1, "t", ('m', None)) t2 = origin.UFBot() t3 = origin.UFDisj((t1, t2)) t4 = origin.UFConj((t1, t2, t1)) self.assertEqual((0, 1), origin.weight_type(t1)) self.assertEqual((2, 0), origin.weight_type(t2)) self.assertEqual((1, 2), origin.weight_type(t3)) self.assertEqual((1, 3), origin.weight_type(t4))
def test_reduce_disj(self): t1 = origin.UFGround(1, "t", None) t2 = origin.UFGround(2, "u", None) t3 = origin.UFBot() t4 = origin.UFDisj((t1, t2)) t5 = origin.UFDisj((t1, t3)) t6 = origin.UFDisj((t1, origin.top)) result = origin.reduce_disj([t4, t1, t5]) self.assertIsInstance(result, origin.UFDisj) self.assertEqual(3, len(result.args)) self.assertEqual(origin.top, origin.reduce_disj([t4, t1, t6]))
def test_simplify_to_ground_types(self): t1 = origin.UFGround(1, "t", None) t2 = origin.UFGround(1, "t", None) t3 = origin.UFDisj((t1, t2)) t4 = origin.UFConj(( t1, origin.UFConj((t2, t1)), origin.UFBot(), t3)) expected = [t1, t2, t1, t3] self.assertEqual( expected, origin.simplify_to_ground_types(t4))