Пример #1
0
def test_single_exprs__muldiv_of_sub_sub():
    # 1, 6, 7, 9 = (9-7)*(6-1) = (1-6)*(7-9)
    # しかし 1-6, 7-9 を項に持つ MulDiv は生成しない
    terms = [sub(1, 6), sub(7, 9)]
    assert set(t for t in single_exprs(terms)
               if isinstance(t, MulDiv)) == set()

    # 6-1, 9-7 を項に持つ MulDiv は生成する
    terms2 = [sub(6, 1), sub(9, 7)]
    assert set(t for t in single_exprs(terms2)
               if isinstance(t, MulDiv)) == set([
                   MulDiv([sub(6, 1), sub(9, 7)], []),
                   MulDiv([sub(6, 1)], [sub(9, 7)]),
                   MulDiv([sub(9, 7)], [sub(6, 1)]),
               ])
Пример #2
0
def test_single_exprs_1_2_3_5_5():
    terms = list(map(Value, [1, 2, 3, 5, 5]))
    addsubs = [t for t in single_exprs(terms) if isinstance(t, AddSub)]

    assert addsubs == [
        add(1, 2, 3, 5, 5),
        addsub([1, 2, 3, 5], [5]),
        addsub([1, 2, 3], [5, 5]),
        addsub([1, 2, 5, 5], [3]),
        addsub([1, 2, 5], [3, 5]),
        #addsub([1, 5, 5], [2, 3]),
        addsub([1, 2], [3, 5, 5]),
        addsub([1, 3, 5, 5], [2]),
        addsub([1, 3, 5], [2, 5]),
        addsub([1, 3], [2, 5, 5]),
        #addsub([1, 5], [2, 3, 5]),
        addsub([1], [2, 3, 5, 5]),
        addsub([2, 3, 5, 5], [1]),
        addsub([2, 3, 5], [1, 5]),
        addsub([2, 3], [1, 5, 5]),
        addsub([2, 5, 5], [1, 3]),
        addsub([2, 5], [1, 3, 5]),
        addsub([2], [1, 3, 5, 5]),

        #addsub([3, 5, 5], [1, 2]),
        #addsub([3, 5], [1, 2, 5]),
        #addsub([3], [1, 2, 5, 5]),
        #addsub([5, 5], [1, 2, 3]),
        #addsub([5], [1, 2, 3, 5]),
    ]
Пример #3
0
def test_single_exprs__1_2():
    terms = list(map(Value, [1, 2]))
    assert set(single_exprs(terms)) == set([
        add(1, 2),
        sub(1, 2),
        sub(2, 1),
        mul(1, 2),
        div(1, 2),
    ])
Пример #4
0
def test_single_exprs__2_3_4():
    terms = list(map(Value, [2, 3, 4]))
    assert set(single_exprs(terms)) == set([
        addsub([2, 3, 4], []),
        addsub([2, 3], [4]),
        addsub([2, 4], [3]),
        addsub([2], [3, 4]),
        addsub([3, 4], [2]),
        addsub([3], [2, 4]),
        addsub([4], [2, 3]),
        muldiv([2, 3, 4], []),
        muldiv([2, 3], [4]),
        muldiv([2, 4], [3]),
        muldiv([2], [3, 4]),
        muldiv([3, 4], [2]),
        muldiv([3], [2, 4]),
        muldiv([4], [2, 3]),
    ])
Пример #5
0
def test_single_exprs__1_2_3():
    terms = list(map(Value, [1, 2, 3]))
    assert set(single_exprs(terms)) == set([
        addsub([1, 2, 3], []),
        addsub([1, 2], [3]),
        addsub([1, 3], [2]),
        addsub([1], [2, 3]),
        addsub([2, 3], [1]),
        addsub([2], [1, 3]),
        # addsub([3], [1, 2]), 0 になる AddSub の重複排除により生成されない
        muldiv([1, 2, 3], []),
        muldiv([1, 2], [3]),
        # muldiv([2, 3], [1]),
        muldiv([1, 3], [2]),
        muldiv([1], [2, 3]),
        # muldiv([2], [1, 3]),
        # muldiv([3], [1, 2]),
    ])
Пример #6
0
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)], [])])