def test_visit_power(self): node = PowerNode(sum_node_for_num(20), sum_node_for_num(5)) traverse_pre(node, self.visitor) self.assertEqual(self.visitor.counts, [ 'power', 'sum', 'mult', 'power', 'func_', 'number_20', 'sum', 'mult', 'power', 'func_', 'number_5' ])
def test_visit_sum(self): node = SumNode(mult_node_for_num(30), SumSub(SignNode('+'), sum_node_for_num(50))) traverse_pre(node, self.visitor) self.assertEqual(self.visitor.counts, [ 'sum', 'mult', 'power', 'func_', 'number_30', 'sum-sub', 'sign', 'sum', 'mult', 'power', 'func_', 'number_50' ])
def test_visit_power(self): node = PowerNode(funcall(20), sum_node_for_num(4)) traverse_post(node, self.visitor) print(self.visitor.counts) self.assertEqual(self.visitor.counts, [ 'number_20', 'func_', 'number_4', 'func_', 'power', 'mult', 'sum', 'power' ])
def test_visit_funcall(self): node = FuncallNode(NameNode('sin'), sum_node_for_num(40)) traverse_post(node, self.visitor) self.assertEqual( self.visitor.counts, ['name', 'number_40', 'func_', 'power', 'mult', 'sum', 'func_sin'])
def test_visit_sum(self): node = SumNode(mult_node_for_num(30), SumSub('+', sum_node_for_num(50))) node.accept(self.visitor) self.assertEqual(self.visitor.counts, {'sum': 1})
def test_visit_power(self): node = PowerNode(sum_node_for_num(20), sum_node_for_num(5)) node.accept(self.visitor) self.assertEqual(self.visitor.counts, {'power': 1})
def test_visit_funcall(self): node = FuncallNode('sin', sum_node_for_num(30)) node.accept(self.visitor) self.assertEqual(self.visitor.counts, {'func': 1})
def test_sum_value(self): node = sum_node_for_num(30) self.assertEqual(30, node.get_value())