Exemplo n.º 1
0
def test_const():
    assert bool(Zero) is False
    assert bool(One) is True
    assert int(Zero) == 0
    assert int(One) == 1
    assert str(Zero) == '0'
    assert str(One) == '1'

    assert not Zero.support
    assert not One.support

    assert Zero.top is None
    assert One.top is None

    assert Zero.restrict({a: 0, b: 1, c: 0, d: 1}) is Zero
    assert One.restrict({a: 0, b: 1, c: 0, d: 1}) is One

    assert Zero.compose({a: 0, b: 1, c: 0, d: 1}) is Zero
    assert One.compose({a: 0, b: 1, c: 0, d: 1}) is One

    assert Zero.simplify() is Zero
    assert One.simplify() is One
    assert Zero.to_nnf() is Zero
    assert One.to_nnf() is One

    assert Zero.depth == 0
    assert One.depth == 0
Exemplo n.º 2
0
def test_const():
    assert bool(Zero) is False
    assert bool(One) is True
    assert int(Zero) == 0
    assert int(One) == 1
    assert str(Zero) == '0'
    assert str(One) == '1'

    assert not Zero.support
    assert not One.support

    assert Zero.top is None
    assert One.top is None

    assert Zero.restrict({a: 0, b: 1, c: 0, d: 1}) is Zero
    assert One.restrict({a: 0, b: 1, c: 0, d: 1}) is One

    assert Zero.compose({a: 0, b: 1, c: 0, d: 1}) is Zero
    assert One.compose({a: 0, b: 1, c: 0, d: 1}) is One

    assert Zero.simplify() is Zero
    assert One.simplify() is One
    assert Zero.to_nnf() is Zero
    assert One.to_nnf() is One

    assert Zero.depth == 0
    assert One.depth == 0
Exemplo n.º 3
0
def test_is_zero_one():
    assert Zero.is_zero()
    assert not One.is_zero()
    assert not a.is_zero()
    assert not (~a | b).is_zero()

    assert One.is_one()
    assert not Zero.is_one()
    assert not a.is_one()
    assert not (~a | b).is_one()
Exemplo n.º 4
0
def test_is_zero_one():
    assert Zero.is_zero()
    assert not One.is_zero()
    assert not a.is_zero()
    assert not (~a | b).is_zero()

    assert One.is_one()
    assert not Zero.is_one()
    assert not a.is_one()
    assert not (~a | b).is_one()
Exemplo n.º 5
0
def test_satisfy():
    # Typical cases
    f = a & ~b & c & ~d
    assert Zero.satisfy_one() is None
    assert One.satisfy_one() == {}
    assert f.satisfy_one() == {a: 1, b: 0, c: 1, d: 0}

    # PLE solution
    f = (a | b | c) & (~a | ~b | c)
    assert f.satisfy_one() == {a: 0, b: 0, c: 1}

    points = [p for p in Xor(a, b, c).satisfy_all()]
    assert points == [
        {
            a: 0,
            b: 0,
            c: 1
        },
        {
            a: 0,
            b: 1,
            c: 0
        },
        {
            a: 1,
            b: 0,
            c: 0
        },
        {
            a: 1,
            b: 1,
            c: 1
        },
    ]
    assert Xor(a, b, c).satisfy_count() == 4

    # CNF SAT UNSAT
    sat = Majority(a, b, c, conj=True)
    unsat = Zero.expand([a, b, c], conj=True)
    assert unsat.satisfy_one() is None
    assert not list(unsat.satisfy_all())
    assert list(sat.satisfy_all())

    # Assumptions
    f = OneHot(a, b, c)
    g = Xor(a, b, c)
    with a, ~b:
        assert f.satisfy_one() == {a: 1, b: 0, c: 0}
        assert g.satisfy_one() == {a: 1, b: 0, c: 0}
    with a & ~b:
        assert f.satisfy_one() == {a: 1, b: 0, c: 0}
        assert g.satisfy_one() == {a: 1, b: 0, c: 0}
Exemplo n.º 6
0
def test_satisfy():
    # Typical cases
    f = a & ~b & c & ~d
    assert Zero.satisfy_one() is None
    assert One.satisfy_one() == {}
    assert f.satisfy_one() == {a: 1, b: 0, c: 1, d: 0}

    # PLE solution
    f = (a | b | c) & (~a | ~b | c)
    assert f.satisfy_one() == {a: 0, b: 0, c: 1}

    points = [p for p in Xor(a, b, c).satisfy_all()]
    assert points == [
        {a: 0, b: 0, c: 1},
        {a: 0, b: 1, c: 0},
        {a: 1, b: 0, c: 0},
        {a: 1, b: 1, c: 1},
    ]
    assert Xor(a, b, c).satisfy_count() == 4

    # CNF SAT UNSAT
    sat = Majority(a, b, c, conj=True)
    unsat = Zero.expand([a, b, c], conj=True)
    assert unsat.satisfy_one() is None
    assert not list(unsat.satisfy_all())
    assert list(sat.satisfy_all())

    # Assumptions
    f = OneHot(a, b, c)
    g = Xor(a, b, c)
    with a, ~b:
        assert f.satisfy_one() == {a: 1, b: 0, c: 0}
        assert g.satisfy_one() == {a: 1, b: 0, c: 0}
    with a & ~b:
        assert f.satisfy_one() == {a: 1, b: 0, c: 0}
        assert g.satisfy_one() == {a: 1, b: 0, c: 0}