diff --git a/tests_rete/test_initialize.py b/tests_rete/test_initialize.py index 452330a..ba51cb7 100644 --- a/tests_rete/test_initialize.py +++ b/tests_rete/test_initialize.py @@ -93,3 +93,6 @@ def test_canonical_label_two_edges(self): channels = rn.get_channels(target=node2.core) self.assertEqual(set(map(attrgetter('num'),channels)),set(node2.data.channels.keys())) + + self.assertTrue('keysep' in node2.data) + self.assertEqual(node2.data.keysep,{'lhs':['b'],'common':['a'],'rhs':['c']}) \ No newline at end of file diff --git a/tests_rete/test_node_functions.py b/tests_rete/test_node_functions.py index f092b93..24dbce2 100644 --- a/tests_rete/test_node_functions.py +++ b/tests_rete/test_node_functions.py @@ -94,4 +94,59 @@ def test_function_node_canonical_label_single_node(self): self.assertEqual(len(node.state.outgoing),3) self.assertEqual(len(node.state.cache.filter(dict(a=x1))),0) self.assertEqual(len(node.state.cache.filter(dict(a=x2))),1) + + def test_function_node_canonical_label_two_edges(self): + rn = ReteNet().initialize_start() + m, L, G = get_canonical_label('two_edges') + rn.initialize_canonical_label(L,G) + + node1,node2 = sorted(rn.get_nodes(type='canonical_label'),key=lambda n: len(n.core.names)) + ch1, ch2 = sorted(rn.get_channels(type='transform',target=L),key=lambda ch: ch.num) + self.assertEqual(node1.state.cache.fields,['a','b']) + X,Y = node1.core.classes + x1, y1, y2 = X('x1'), Y('y1'), Y('y2') + + node1.state.cache.insert({'a':x1,'b':y1}) + token = ch1.data.transformer.transform(CacheToken(data={'a':x1,'b':y1},action='AddEntry'),channel=ch1.num) + self.assertEqual(token.data,{'a':x1,'b':y1}) + rn.function_node_canonical_label(node2,token) + token = ch2.data.transformer.transform(CacheToken(data={'a':x1,'b':y1},action='AddEntry'),channel=ch2.num) + self.assertEqual(token.data,{'a':x1,'c':y1}) + rn.function_node_canonical_label(node2,token) + + self.assertEqual(len(node1.state.cache),1) + self.assertEqual(len(node2.state.cache),0) + + node1.state.cache.insert({'a':x1,'b':y2}) + token = ch1.data.transformer.transform(CacheToken(data={'a':x1,'b':y2},action='AddEntry'),channel=ch1.num) + self.assertEqual(token.data,{'a':x1,'b':y2}) + rn.function_node_canonical_label(node2,token) + token = ch2.data.transformer.transform(CacheToken(data={'a':x1,'b':y2},action='AddEntry'),channel=ch2.num) + self.assertEqual(token.data,{'a':x1,'c':y2}) + rn.function_node_canonical_label(node2,token) + + self.assertEqual(len(node1.state.cache),2) + self.assertEqual(len(node2.state.cache),2) + self.assertEqual(len(node2.state.cache.filter({'a':x1,'b':y1,'c':y2})), 1) + self.assertEqual(len(node2.state.cache.filter({'a':x1,'b':y2,'c':y1})), 1) + + + x1, y1, y2 = X('x2'), Y('y3'), Y('y4') + node1.state.cache.insert({'a':x1,'b':y1}) + token = ch1.data.transformer.transform(CacheToken(data={'a':x1,'b':y1},action='AddEntry'),channel=ch1.num) + rn.function_node_canonical_label(node2,token) + token = ch2.data.transformer.transform(CacheToken(data={'a':x1,'b':y1},action='AddEntry'),channel=ch2.num) + rn.function_node_canonical_label(node2,token) + + self.assertEqual(len(node1.state.cache),3) + self.assertEqual(len(node2.state.cache),2) + + node1.state.cache.insert({'a':x1,'b':y2}) + token = ch1.data.transformer.transform(CacheToken(data={'a':x1,'b':y2},action='AddEntry'),channel=ch1.num) + rn.function_node_canonical_label(node2,token) + token = ch2.data.transformer.transform(CacheToken(data={'a':x1,'b':y2},action='AddEntry'),channel=ch2.num) + rn.function_node_canonical_label(node2,token) + + self.assertEqual(len(node1.state.cache),4) + self.assertEqual(len(node2.state.cache),4) \ No newline at end of file diff --git a/wc_rules/matcher/node_functions.py b/wc_rules/matcher/node_functions.py index ebd43aa..7046896 100644 --- a/wc_rules/matcher/node_functions.py +++ b/wc_rules/matcher/node_functions.py @@ -43,6 +43,7 @@ def function_node_canonical_label_single_edge(self,node,token): return self def function_node_canonical_label_general_case(self,node,token): + entries = [] if token.action=='AddPartialEntry': channels,caches,keysep = [node.data[x] for x in ['channels','caches','keysep']] chA = channels[token.channel]