Exemplo n.º 1
0
def test_smooth_abs_expr(simple_model):
    # Test that smooth_abs works with Pyomo components
    assert value(smooth_abs(simple_model.a, 0)) == 4.0
    assert value(smooth_abs(simple_model.b, 0)) == 4.0

    assert (value(smooth_abs(simple_model.a, simple_model.e)) ==
            pytest.approx(4.0, abs=1e-4))
    assert (value(smooth_abs(simple_model.b, simple_model.e)) ==
            pytest.approx(4.0, abs=1e-4))
Exemplo n.º 2
0
def test_smooth_abs_maths():
    # Test basic smooth_abs functionalliy
    assert smooth_abs(4, 0) == 4.0
    assert smooth_abs(-4, 0) == 4.0
    assert smooth_abs(10.0, 0.0) == 10.0
    assert smooth_abs(-10.0, 0.0) == 10.0

    assert smooth_abs(2, 1e-4) == pytest.approx(2.0, abs=1e-4)
    assert smooth_abs(-2, 1e-4) == pytest.approx(2.0, abs=1e-4)
    assert smooth_abs(10) == pytest.approx(10.0, abs=1e-4)
    assert smooth_abs(-10) == pytest.approx(10.0, abs=1e-4)
Exemplo n.º 3
0
def test_smooth_abs_eps_errors():
    # Test that smooth_abs returns meaningful errors when given invalid eps
    with pytest.raises(TypeError):
        smooth_abs(1.0, "a")
    with pytest.raises(TypeError):
        smooth_abs(1.0, [1, 2, 3])
Exemplo n.º 4
0
def test_smooth_abs_a_errors():
    # Test that smooth_abs returns meaningful errors when given invalid arg
    with pytest.raises(TypeError):
        smooth_abs("foo")
    with pytest.raises(TypeError):
        smooth_abs([1, 2, 3])