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_eq6(self): node1 = MultNode(funcall(20), MultSub(SignNode('*'), power(23)), MultSub(SignNode('/'), power(10))) node2 = MultNode(funcall(20), MultSub(SignNode('*'), power(20)), MultSub(SignNode('/'), power(10))) self.assertNotEqual(node1, node2)
def test_eq5(self): node1 = NumberNode(20) node2 = MultNode(funcall(20), MultSub('*', 25), MultSub('/', 10)) self.assertNotEqual(node1, node2)
def test_eq2(self): node1 = funcall(30) node2 = funcall(30) self.assertEqual(node1, node2)
def test_skip_power(self): visitor = SkipPowerNodes() node = PowerNode(funcall(20), expr(10, [mult_sub('*', 3)])) traverse_pre(node, visitor) self.assertEqual(visitor.counts, ['power', 'func_', 'number_20'])
def test_substitute_number2(self): node = funcall(10) new_node = map_post(node, Num2NumSubstitutor()) self.assertEqual(new_node, funcall(30)) self.assertEqual(node, funcall(10))
def test_mult_value2(self): node = MultNode(funcall(20), MultSub(SignNode('*'), funcall(25)), MultSub(SignNode('/'), funcall(10))) self.assertEqual(50, node.get_value())
def test_funcall_value(self): node = funcall(30) self.assertEqual(30, node.get_value())