Fixed #49 : working

This commit is contained in:
2021-03-18 11:49:48 +01:00
parent 27bc6c4ba1
commit 36515aebb7
5 changed files with 153 additions and 63 deletions
+30 -1
View File
@@ -134,7 +134,7 @@ class TestReteNetwork(TestUsingMemoryBasedSheerka):
def test_adding_obj_when_requested_attribute_is_not_found(self):
"""
When a rule with attribute constraint, we only add the requested attributes
There is no error when an attribute does not exits
"""
network = ReteNetwork()
ret = ReturnValueConcept("test", True, "value")
@@ -218,6 +218,35 @@ class TestReteNetwork(TestUsingMemoryBasedSheerka):
assert matches[0].pnode.rules == [rule]
assert network.facts == {'f-00000': ret}
def test_i_can_add_obj_and_match_obj_when_value_is_sheerka(self):
sheerka, context, greetings = self.init_concepts(
Concept("greetings", definition="hello a", definition_type=DEFINITION_TYPE_DEF).def_var("a")
)
network = ReteNetwork()
rule = RuleForTestingRete(AndConditions([Condition(V("ret"), "__name__", "__ret"),
Condition(V("ret"), "body", V("body")),
Condition(V("body"), "name", "greetings"),
Condition(V("body"), "a", "__sheerka__"),
]))
network.add_rule(rule)
hello_concept = sheerka.new(greetings, a=sheerka)
ret = ReturnValueConcept("test", True, hello_concept)
network.add_obj("__ret", ret)
assert network.working_memory == {
WME("f-00000", "__name__", "__ret"),
WME("f-00000", "body", "f-00000.body"),
WME("f-00000.body", "name", "greetings"),
WME("f-00000.body", "a", "__sheerka__"),
}
# sanity check that the WME produced match the condition
matches = list(network.matches)
assert len(matches) == 1
assert matches[0].pnode.rules == [rule]
assert network.facts == {'f-00000': ret}
def test_i_can_distinguish_objects_with_different_value(self):
network = ReteNetwork()
rule = RuleForTestingRete(AndConditions([