def test_parse_ordering_of_expression(self): root = AssociativeSet('*') expression_result = parse("foo bar", root) self.assertEqual(len(root.comprehend("foo", "0")), 1) # Should get ONE hit. position_relation = root.comprehend("foo", "0")[0] self.assertTrue("position" in position_relation.contents) position_tags = [x for x in position_relation.contents.values() if "position" in x.contents] self.assertTrue(position_tags, "Should be able to see the position relation marked as such.")
def test_parse_nested_expression(self): root = AssociativeSet('*') parse_text = "foo bar (baz berz)" parse(parse_text, root) # Expected: foo, bar, (baz berz), baz, berz, outer expression, inner expression (parenthetical) # Plus outer ordinals: 0, 1, 2 (which should be shared w/ inner ordinals) and 5 relations to # support them, and the 'position' category. # self.assertEqual( len(root.contents), 15) self.assertTrue("foo" in root.contents) self.assertTrue("bar" in root.contents) relations = root.comprehend("baz", "berz") self.assertTrue( len(relations) > 0, "Should get a relation back for the inner expression") inner_expression = relations[0] self.assertNotEqual(inner_expression.name, '*', "Shouldn't get root back as our match") self.assertTrue("baz" in inner_expression, "Can't see first item in nested expression.") self.assertTrue("berz" in inner_expression, "Can't see second item in nested expression.")
def test_parse_nested_expression(self): root = AssociativeSet('*') parse_text = "foo bar (baz berz)" parse(parse_text, root) # Expected: foo, bar, (baz berz), baz, berz, outer expression, inner expression (parenthetical) # Plus outer ordinals: 0, 1, 2 (which should be shared w/ inner ordinals) and 5 relations to # support them, and the 'position' category. # self.assertEqual( len(root.contents), 15) self.assertTrue( "foo" in root.contents ) self.assertTrue( "bar" in root.contents ) relations = root.comprehend("baz", "berz") self.assertTrue(len(relations) > 0, "Should get a relation back for the inner expression") inner_expression = relations[0] self.assertNotEqual( inner_expression.name, '*', "Shouldn't get root back as our match") self.assertTrue("baz" in inner_expression, "Can't see first item in nested expression.") self.assertTrue("berz" in inner_expression, "Can't see second item in nested expression.")
def test_parse_ordering_of_expression(self): root = AssociativeSet('*') expression_result = parse("foo bar", root) self.assertEqual(len(root.comprehend("foo", "0")), 1) # Should get ONE hit. position_relation = root.comprehend("foo", "0")[0] self.assertTrue("position" in position_relation.contents) position_tags = [ x for x in position_relation.contents.values() if "position" in x.contents ] self.assertTrue( position_tags, "Should be able to see the position relation marked as such.")
from associative_tools import AssociativeSet # This should be a proper unit test. def expect(expected, msg=""): if not expected: print "Fail: %s" % msg else: print ".", s = AssociativeSet("*") # * essentially means "root" or "this namespace" s.associate("foo", "bar") expect("foo" in s.comprehend("bar")[0], "Can't associate properly?") expect("bar" in s.comprehend("foo")[0], "Can't associate properly a second time?") s = AssociativeSet("*") s.associate("foo", "bar", "baz") expect(set(["bar", "baz"]).issubset(s.comprehend("foo")[0].terms), "Multiple associations aren't working.") expect(set(["baz"]).issubset(s.comprehend("foo", "bar")[0].terms), "Multiple comprehensions aren't working.") s = AssociativeSet("*") s.associate("foo", "bar", "baz")