Пример #1
0
def test_constraint_creation():
    """Test constraints creation and methods.

    """
    v = Variable('foo')
    c = Constraint(v + 1, '==')

    assert c.strength() == strength.required and c.op() == '=='
    e = c.expression()
    t = e.terms()
    assert (e.constant() == 1 and len(t) == 1 and t[0].variable() is v
            and t[0].coefficient() == 1)

    assert str(c) == '1 * foo + 1 == 0 | strength = 1.001e+09'

    for s in ('weak', 'medium', 'strong', 'required'):
        c = Constraint(v + 1, '>=', s)
        assert c.strength() == getattr(strength, s)
Пример #2
0
def test_constraint_creation():
    """Test constraints creation and methods.

    """
    v = Variable('foo')
    c = Constraint(v + 1, '==')

    assert c.strength() == strength.required and c.op() == '=='
    e = c.expression()
    t = e.terms()
    assert (e.constant() == 1 and
            len(t) == 1 and t[0].variable() is v and t[0].coefficient() == 1)

    assert str(c) == '1 * foo + 1 == 0 | strength = 1.001e+09'

    for s in ('weak', 'medium', 'strong', 'required'):
        c = Constraint(v + 1, '>=', s)
        assert c.strength() == getattr(strength, s)
Пример #3
0
def test_constraint_creation(op):
    """Test constraints creation and methods.

    """
    v = Variable('foo')
    c = Constraint(v + 1, op)

    assert c.strength() == strength.required and c.op() == op
    e = c.expression()
    t = e.terms()
    assert (e.constant() == 1 and
            len(t) == 1 and t[0].variable() is v and t[0].coefficient() == 1)

    constraint_format = r'1 \* foo \+ 1 %s 0 | strength = 1.001e\+[0]+9' % op
    assert re.match(constraint_format, str(c))

    for s in ('weak', 'medium', 'strong', 'required'):
        c = Constraint(v + 1, op, s)
        assert c.strength() == getattr(strength, s)

    # Ensure we test garbage collection.
    del c
    gc.collect()
Пример #4
0
def test_constraint_creation(op):
    """Test constraints creation and methods.

    """
    v = Variable('foo')
    c = Constraint(v + 1, op)

    assert c.strength() == strength.required and c.op() == op
    e = c.expression()
    t = e.terms()
    assert (e.constant() == 1 and
            len(t) == 1 and t[0].variable() is v and t[0].coefficient() == 1)

    constraint_format = '1 \* foo \+ 1 %s 0 | strength = 1.001e\+[0]+9' % op
    assert re.match(constraint_format, str(c))

    for s in ('weak', 'medium', 'strong', 'required'):
        c = Constraint(v + 1, op, s)
        assert c.strength() == getattr(strength, s)

    # Ensure we test garbage collection.
    del c
    gc.collect()