Skip to content

Commit

Permalink
Testing AddPartialEntry for CanonicalLabelGeneralCase
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsekar committed Mar 11, 2022
1 parent 8c6bb07 commit d1aeb42
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests_rete/test_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']})
55 changes: 55 additions & 0 deletions tests_rete/test_node_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

1 change: 1 addition & 0 deletions wc_rules/matcher/node_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d1aeb42

Please sign in to comment.