예제 #1
0
def test_const():
    assert bool(EXPRZERO) is False
    assert bool(EXPRONE) is True
    assert int(EXPRZERO) == 0
    assert int(EXPRONE) == 1
    assert str(EXPRZERO) == '0'
    assert str(EXPRONE) == '1'

    assert not EXPRZERO.support
    assert not EXPRONE.support

    assert EXPRZERO.top is None
    assert EXPRONE.top is None

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

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

    assert EXPRZERO.simplify() is EXPRZERO
    assert EXPRONE.simplify() is EXPRONE
    assert EXPRZERO.factor() is EXPRZERO
    assert EXPRONE.factor() is EXPRONE

    assert EXPRZERO.depth == 0
    assert EXPRONE.depth == 0
예제 #2
0
파일: test_expr.py 프로젝트: e42s/pyeda
def test_const():
    assert bool(EXPRZERO) is False
    assert bool(EXPRONE) is True
    assert int(EXPRZERO) == 0
    assert int(EXPRONE) == 1
    assert str(EXPRZERO) == '0'
    assert str(EXPRONE) == '1'

    assert not EXPRZERO.support
    assert not EXPRONE.support

    assert EXPRZERO.top is None
    assert EXPRONE.top is None

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

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

    assert EXPRZERO.simplify() is EXPRZERO
    assert EXPRONE.simplify() is EXPRONE
    assert EXPRZERO.to_nnf() is EXPRZERO
    assert EXPRONE.to_nnf() is EXPRONE

    assert EXPRZERO.depth == 0
    assert EXPRONE.depth == 0
예제 #3
0
def test_satisfy():
    # Typical cases
    f = a & ~b & c & ~d
    assert EXPRZERO.satisfy_one() is None
    assert EXPRONE.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

    # 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}
예제 #4
0
파일: test_expr.py 프로젝트: e42s/pyeda
def test_satisfy():
    # Typical cases
    f = a & ~b & c & ~d
    assert EXPRZERO.satisfy_one() is None
    assert EXPRONE.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

    # 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}
예제 #5
0
def test_satisfy():
    # Typical cases
    f = a * -b * c * -d
    assert EXPRZERO.satisfy_one() is None
    assert EXPRONE.satisfy_one() == {}
    assert f.satisfy_one() == {a: 1, b: 0, c: 1, d: 0}
    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