Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Test/UnitTests/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,33 @@ function solve_zero_one_with_bounds_3(model::MOI.ModelLike, config::TestConfig)
end
end
unittests["solve_zero_one_with_bounds_3"] = solve_zero_one_with_bounds_3

# Taken from https://github.com/jump-dev/Ipopt.jl/pull/230/files#
"""
add_constraint_nan(model::MOI.ModelLike, config::TestConfig)

Add a NaN constraint. This should throw a proper error message.
"""
function add_constraint_checks(model::MOI.ModelLike, config::TestConfig)
@testset "first isnan check" begin
MOI.empty!(model)
x = MOI.add_variable(model)
@test_throws ErrorException MOI.add_constraint(model, x, MOI.EqualTo(NaN))
end

@testset "first has_lower_bound check" begin
MOI.empty!(model)
x = MOI.add_variable(model)
MOI.add_constraint(model, x, MOI.GreaterThan(5.0))
@test_throws MOI.LowerBoundAlreadySet MOI.add_constraint(model, x, MOI.EqualTo(5.0))
end

@testset "first has_upper_bound check" begin
MOI.empty!(model)
x = MOI.add_variable(model)
MOI.add_constraint(model, x, MOI.LessThan(5.0))
@test_throws MOI.UpperBoundAlreadySet MOI.add_constraint(model, x, MOI.EqualTo(5.0))
end
end
unittests["add_constraint_checks"] = add_constraint_checks

5 changes: 5 additions & 0 deletions test/Test/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ end
"solve_zero_one_with_bounds_1",
"solve_zero_one_with_bounds_2",
"solve_zero_one_with_bounds_3",
"add_constraint_checks",
"solve_unbounded_model",
"solve_single_variable_dual_min",
"solve_single_variable_dual_max",
Expand Down Expand Up @@ -337,6 +338,10 @@ end
MOIT.solve_zero_one_with_bounds_3(mock, config)
end

@testset "add_constraint_checks" begin
MOIT.add_constraint_checks(mock, config)
end

@testset "solve_unbounded_model" begin
MOIU.set_mock_optimize!(mock,
(mock::MOIU.MockOptimizer) -> begin
Expand Down