def test_str__has_addsub(self): node = MulDiv([Value(3), AddSub([Value(4), Value(6)], [])], [Value(5), AddSub([Value(7), Value(8)], [])]) assert str(node) == "3*(4+6)/5/(7+8)"
def test_eval(self): node = Value(10) assert node.eval() == 10
def test_str(self): node = MulDiv([Value(3), Value(4)], [Value(5), Value(7)]) assert str(node) == "3*4/5/7"
def test_eval(self): node = AddSub([Value(1), Value(2)], [Value(5), Value(9)]) assert node.eval() == -11
def test_eq__noteq(self): node1 = AddSub([Value(3)], [Value(4)]) node2 = AddSub([Value(4)], [Value(4)]) assert not (node1 == node2)
def test_str(self): node = AddSub([Value(3), Value(4)], [Value(5), Value(7)]) assert str(node) == "3+4-5-7"
def test_str__has_muldiv(self): node = AddSub([Value(3), MulDiv([Value(4), Value(6)], [])], [Value(5), MulDiv([Value(7), Value(8)], [])]) assert str(node) == "3+4*6-5-7*8"
def wrapvalue(args): for x in args: if isinstance(x, float) or isinstance(x, int): yield Value(x) else: yield x
def test_str(self): node = Value(3) assert str(node) == "3"
def test_hash(self): node1 = Value(3) assert Value(3) in set([node1]) assert Value(4) not in set([node1])
def test_single_exprs__1sub1_2_3(): terms = [Value(2), Value(3), sub(1, 1)] # 0となる項を含むので乗算のみ生成 assert set(single_exprs(terms)) == set( [MulDiv([Value(2), Value(3), sub(1, 1)], [])])
def test_eq__not_equal(self): node1 = Value(3) node2 = Value(4) assert not (node1 == node2)
def test_build_exprs__single_atom() -> None: actual = list(build_exprs([3])) assert actual == [Value(3)]
def test_eq(self): node1 = Value(3) node2 = Value(3) assert node1 == node2
def test_eq__noteq(self): node1 = MulDiv([Value(3)], [Value(4)]) node2 = MulDiv([Value(4)], [Value(4)]) assert not (node1 == node2)
def test_eval(self): node = MulDiv([Value(6), Value(10)], [Value(5), Value(3)]) assert node.eval() == 4