def test_smooth_minmax_default_sense(): # Test that smooth_minmax defaults to maximise assert smooth_minmax( 1, 2, 0, ) == 2
def test_smooth_minmax_expr(simple_model): # Test that smooth_minmax works with Pyomo components assert value(smooth_minmax(simple_model.a, simple_model.b, 0, sense='max')) == 4.0 assert value(smooth_minmax(simple_model.a, simple_model.b, 0, sense='min')) == -4.0 assert value(smooth_minmax(simple_model.a, simple_model.b, sense='max')) == pytest.approx(4.0, abs=1e-4) assert value(smooth_minmax(simple_model.a, simple_model.b, sense='min')) == pytest.approx(-4.0, abs=1e-4) assert value(smooth_minmax(simple_model.a, simple_model.b, simple_model.e, sense='max')) == pytest.approx(4.0, abs=1e-4) assert value(smooth_minmax(simple_model.a, simple_model.b, simple_model.e, sense='min')) == pytest.approx(-4.0, abs=1e-4)
def test_smooth_minmax_maths(): # Test basic smooth_minmax functionality assert smooth_minmax(1, 2, 0, sense='max') == 2 assert smooth_minmax(1, 2, 0, sense='min') == 1 assert smooth_minmax(5.0, 3, 0.0, sense='max') == 5 assert smooth_minmax(5.0, 3, 0.0, sense='min') == 3 assert (smooth_minmax(2.0, 12.0, 1e-4, 'max') == pytest.approx(12.0, abs=1e-4)) assert (smooth_minmax(2.0, 12.0, 1e-4, 'min') == pytest.approx(2.0, abs=1e-4)) assert (smooth_minmax(32.0, 12.0, sense='max') == pytest.approx(32.0, abs=1e-4)) assert (smooth_minmax(32.0, 12.0, sense='min') == pytest.approx(12.0, abs=1e-4))
def test_smooth_minmax_sense_errors(): # Test that smooth_abs returns meaningful errors when given invalid sense with pytest.raises(ValueError): smooth_minmax(1.0, 1.0, sense="foo") with pytest.raises(ValueError): smooth_minmax(1.0, 1.0, sense=1.0) with pytest.raises(ValueError): smooth_minmax(1.0, 1.0, sense=[1.0])
def test_smooth_minmax_eps_errors(): # Test that smooth_abs returns meaningful errors when given invalid eps with pytest.raises(TypeError): smooth_minmax(1.0, 1.0, "foo") with pytest.raises(TypeError): smooth_minmax(1.0, 1.0, [1, 2, 3])