def test_invalid_amount_of_operands(self): with pytest.raises(TypeError) as e: node = CombinationNode() node.append(PrimitiveNode(add)) node.eval() assert "combination needs to have at least two operands" in str(e.value)
def test_invalid_operator(self): with pytest.raises(TypeError) as e: node = CombinationNode() for i in range(3): node.append(PrimitiveNode(1)) node.eval() assert "operator not found" in str(e.value)
def test_eval_with_node(self): node = RootNode() combination = CombinationNode() combination.append(PrimitiveNode(add)) combination.append(PrimitiveNode(1)) combination.append(PrimitiveNode(2)) node.append(combination) assert 3 == node.eval()
class RootNode(Node): def __init__(self): self._node = CombinationNode() def eval(self): return self._node.eval() def append(self, node): self._node = node
def test_eval_without_nodes_should_return_none(self): node = CombinationNode() assert node.eval() is None
def test_eval_two_operands(self): node = CombinationNode() node.append(PrimitiveNode(add)) node.append(PrimitiveNode(1)) node.append(PrimitiveNode(2)) assert 3 == node.eval()
def __init__(self): self._node = CombinationNode()