Successfully built n-ary graph drawer.

parent d9474ea0
This diff is collapsed.
...@@ -16,59 +16,76 @@ class TestGraph(unittest.TestCase): ...@@ -16,59 +16,76 @@ class TestGraph(unittest.TestCase):
def test_simple_unary(self): def test_simple_unary(self):
uminus = Node('-', self.l1) uminus = Node('-', self.l1)
g = generate_graph(uminus, Node) g = generate_graph(uminus, Node)
expect = self.strip(""" self.assertEqualGraphs(g, """
- -
1 1
""") """)
assert g == expect
def test_simple_binary(self): def test_simple_binary(self):
plus = Node('+', self.l0, self.l1) plus = Node('+', self.l0, self.l1)
g = generate_graph(plus, Node) g = generate_graph(plus, Node)
expect = self.strip(""" self.assertEqualGraphs(g, """
+ +
╭┴╮ ╭┴╮
0 1 0 1
""") """)
assert g == expect
def test_multichar_unary(self): def test_multichar_unary(self):
uminus = Node('-', self.multi) uminus = Node('-', self.multi)
g = generate_graph(uminus, Node) g = generate_graph(uminus, Node)
expect = self.strip(""" self.assertEqualGraphs(g, """
- -
test test
""") """)
print g
print expect
assert g == expect
def test_multichar_binary(self): def test_multichar_binary(self):
plus = Node('+', self.multi, self.l1) plus = Node('+', self.multi, self.l1)
g = generate_graph(plus, Node) g = generate_graph(plus, Node)
expect = self.strip(""" self.assertEqualGraphs(g, """
+ +
╭───┴╮ ──┴╮
test 1 test 1
""") """)
assert g == expect
def test_function(self): def test_ternary(self):
exp = Leaf('x')
inf = Leaf('o')
minus_inf = Node('-', Leaf('L'))
integral = Node('n', exp, minus_inf, inf)
g = generate_graph(integral, Node, verbose=True)
self.assertEqualGraphs(g, """
n
╭─┼─╮
x - o
L
""")
def test_ternary_multichar(self):
exp = Leaf('x') exp = Leaf('x')
inf = Leaf('oo') inf = Leaf('oo')
minus_inf = Node('-', inf) minus_inf = Node('-', Leaf('LL'))
integral = Node('int', exp, minus_inf, inf) integral = Node('int', exp, minus_inf, inf)
g = generate_graph(integral, Node) g = generate_graph(integral, Node, verbose=True)
expect = self.strip(""" self.assertEqualGraphs(g, """
int int
╭─┼──╮ ╭─┼──╮
x - oo x - oo
oo LL
""") """)
assert g == expect
def strip(self, str): def strip(self, str):
return str.replace('\n ', '\n')[1:-1] return str.replace('\n ', '\n')[1:-1]
def assertEqualGraphs(self, g, expect):
expect = self.strip(expect)
if g != expect:
print 'Expected:'
print expect
print 'Got:'
print g
raise AssertionError('Graph does not match expected value')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment