MCPcopy Index your code
hub / github.com/waleedka/hiddenlayer / test_basics

Method test_basics

tests/test_ge.py:104–167  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

102
103class TestPatterns(unittest.TestCase):
104 def test_basics(self):
105 g = hl.Graph()
106 a = hl.Node(uid="a", name="a", op="a")
107 b = hl.Node(uid="b", name="b", op="b")
108 c = hl.Node(uid="c", name="c", op="c")
109 d = hl.Node(uid="d", name="d", op="d")
110 e = hl.Node(uid="e", name="e", op="e")
111 g.add_node(a)
112 g.add_node(b)
113 g.add_node(c)
114 g.add_node(d)
115 g.add_node(e)
116 g.add_edge(a, b)
117 g.add_edge(b, c)
118 g.add_edge(b, d)
119 g.add_edge(c, e)
120 g.add_edge(d, e)
121
122 rule = ge.GEParser("a > b").parse()
123 self.assertIsInstance(rule, ge.SerialPattern)
124 match, following = rule.match(g, a)
125 self.assertTrue(match)
126 self.assertCountEqual(following, [c, d])
127 match, following = rule.match(g, b)
128 self.assertFalse(match)
129
130 rule = ge.GEParser("b > c").parse()
131 self.assertIsInstance(rule, ge.SerialPattern)
132 match, following = rule.match(g, b)
133 self.assertFalse(match)
134
135 rule = ge.GEParser("c | d").parse()
136 self.assertIsInstance(rule, ge.ParallelPattern)
137 match, following = rule.match(g, [c, d])
138 self.assertTrue(match)
139 self.assertEqual(following, e)
140 match, following = rule.match(g, [c])
141 self.assertTrue(match)
142 self.assertEqual(following, e)
143 match, following = rule.match(g, d)
144 self.assertTrue(match)
145 self.assertEqual(following, e)
146 match, following = rule.match(g, b)
147 self.assertFalse(match)
148
149 rule = ge.GEParser("a > b > (c | d)").parse()
150 self.assertIsInstance(rule, ge.SerialPattern)
151 match, following = rule.match(g, a)
152 self.assertTrue(match, following)
153
154 rule = ge.GEParser("(a > b) > (c | d)").parse()
155 self.assertIsInstance(rule, ge.SerialPattern)
156 match, following = rule.match(g, a)
157 self.assertTrue(match)
158
159 rule = ge.GEParser("a > b > (c | d) > e").parse()
160 self.assertIsInstance(rule, ge.SerialPattern)
161 match, following = rule.match(g, a)

Callers

nothing calls this directly

Calls 4

add_nodeMethod · 0.95
add_edgeMethod · 0.95
parseMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected