Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_degree(model):
m, x, y, z = model
expr = Expr()
assert expr.degree() == 0
expr = Expr() + 3.0
assert expr.degree() == 0
expr = x + 1
assert expr.degree() == 1
expr = x*x + y - 2
assert expr.degree() == 2
expr = (x + 1)*(y + 1)*(x - 1)
assert expr.degree() == 3
def test_degree(model):
m, x, y, z = model
expr = Expr()
assert expr.degree() == 0
expr = Expr() + 3.0
assert expr.degree() == 0
expr = x + 1
assert expr.degree() == 1
expr = x*x + y - 2
assert expr.degree() == 2
expr = (x + 1)*(y + 1)*(x - 1)
assert expr.degree() == 3
def test_upgrade(model):
m, x, y, z = model
expr = x + y
assert isinstance(expr, Expr)
expr += exp(z)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr -= exp(z)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr /= x
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr *= sqrt(x)
def test_upgrade(model):
m, x, y, z = model
expr = x + y
assert isinstance(expr, Expr)
expr += exp(z)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr -= exp(z)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr /= x
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr *= sqrt(x)
assert isinstance(expr, GenExpr)
expr = x + y
assert isinstance(expr, Expr)
expr **= 1.5
assert expr[x] == 1.0
assert expr[y] == 1.0
assert expr[z] == 0.0
expr = -x
assert isinstance(expr, Expr)
assert expr[x] == -1.0
assert expr[y] == 0.0
expr = x*4
assert isinstance(expr, Expr)
assert expr[x] == 4.0
assert expr[y] == 0.0
expr = 4*x
assert isinstance(expr, Expr)
assert expr[x] == 4.0
assert expr[y] == 0.0
expr = x + y + x
assert isinstance(expr, Expr)
assert expr[x] == 2.0
assert expr[y] == 1.0
expr = x + y - x
assert isinstance(expr, Expr)
assert expr[x] == 0.0
assert expr[y] == 1.0
expr = 3*x + 1.0
assert isinstance(expr, Expr)
assert expr[x] == 3.0
def test_operations_linear(model):
m, x, y, z = model
expr = x + y
assert isinstance(expr, Expr)
assert expr[x] == 1.0
assert expr[y] == 1.0
assert expr[z] == 0.0
expr = -x
assert isinstance(expr, Expr)
assert expr[x] == -1.0
assert expr[y] == 0.0
expr = x*4
assert isinstance(expr, Expr)
assert expr[x] == 4.0
assert expr[y] == 0.0
expr = 4*x
assert isinstance(expr, Expr)