Beispiel #1
0
    def test_evaluate_deep_operator_node(self):
        node = OperatorNode(lambda x, y: x * y)
        left_node = OperatorNode(lambda x, y: x + y)
        node.left = left_node
        left_node.left = ValueNode(1)
        left_node.right = ValueNode(2)
        node.right = ValueNode(5)

        self.assertEqual(15, node.evaluate())
Beispiel #2
0
    def test_evaluate_shallow_node(self):
        node = OperatorNode(lambda x, y: x * y)
        node.left = ValueNode(3)
        node.right = ValueNode(2)

        self.assertEqual(6, node.evaluate())
Beispiel #3
0
 def __add_operator_node_from(self, token):
     operator_node = OperatorNode(self.__get_operation(token))
     operator_node.right = self.__buffer.pop()
     operator_node.left = self.__buffer.pop()
     self.__add_node_to_buffer(operator_node)