Esempio n. 1
0
def test_basic():
    assert DisjNormalForm(set()) == 0
    assert ConjNormalForm(set()) == 1

    f = -a * b + a * -b
    g = (a + b) * (-a + -b)
    dnf = expr2nfexpr(f)
    cnf = expr2nfexpr(g)

    assert str(dnf) == "a' * b + a * b'"
    assert str(cnf) == "(a + b) * (a' + b')"

    assert repr(dnf) == "a' * b + a * b'"
    assert repr(cnf) == "(a + b) * (a' + b')"

    assert dnf.support == {a, b}
    assert cnf.support == {a, b}
    assert dnf.inputs == [a, b]
    assert cnf.inputs == [a, b]

    assert isinstance(-dnf, ConjNormalForm)
    assert nfexpr2expr(-dnf).equivalent(-f)

    assert isinstance(-cnf, DisjNormalForm)
    assert nfexpr2expr(-cnf).equivalent(-g)
Esempio n. 2
0
def test_conversion():
    f = -a * b + a * -b
    g = (a + b) * (-a + -b)

    nose.tools.assert_raises(TypeError, expr2nfexpr, Xor(a, b))
    nose.tools.assert_raises(TypeError, nfexpr2expr, "what?")

    nfexpr2expr(expr2nfexpr(f)).equivalent(f)
    nfexpr2expr(expr2nfexpr(g)).equivalent(g)