diff --git a/test/test_constraint.jl b/test/test_constraint.jl index 04214015ac4..cb63bb99e29 100644 --- a/test/test_constraint.jl +++ b/test/test_constraint.jl @@ -2171,4 +2171,51 @@ function test_constraint_by_name() return end +function test_shadow_price_errors() + model = Model() + @variable(model, x[1:2]) + c = @constraint(model, x in SOS1()) + @test_throws( + ErrorException( + "The shadow price is not defined or not implemented for this type " * + "of constraint.", + ), + shadow_price(c), + ) + err = ErrorException( + "The shadow price is not available because no dual result is " * + "available.", + ) + model = Model() + @variable(model, x) + c = @constraint(model, x <= 1) + @test_throws err shadow_price(c) + c = @constraint(model, x >= 1) + @test_throws err shadow_price(c) + c = @constraint(model, x == 1) + @test_throws err shadow_price(c) + + model = Model() + @variable(model, x >= 0) + set_optimizer( + model, + () -> MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()), + ) + optimize!(model) + mock = unsafe_backend(model) + MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL) + MOI.set(mock, MOI.PrimalStatus(), MOI.FEASIBLE_POINT) + MOI.set(mock, MOI.DualStatus(), MOI.FEASIBLE_POINT) + F, S = MOI.VariableIndex, MOI.GreaterThan{Float64} + xi = only(MOI.get(mock, MOI.ListOfVariableIndices())) + MOI.set(mock, MOI.ConstraintDual(), MOI.ConstraintIndex{F,S}(xi.value), 1.0) + @test_throws( + ErrorException( + "The shadow price is not available because the objective sense $FEASIBILITY_SENSE is not minimization or maximization.", + ), + shadow_price(LowerBoundRef(x)), + ) + return +end + end # module diff --git a/test/test_model.jl b/test/test_model.jl index ee4c193e383..6db3a692ed0 100644 --- a/test/test_model.jl +++ b/test/test_model.jl @@ -1364,4 +1364,29 @@ function test_optimizer_index() return end +function test_copy_nonlinear() + model = Model() + @variable(model, x) + @NLconstraint(model, x <= 1) + @test_throws( + ErrorException( + "copy is not supported yet for models with nonlinear constraints" * + " and/or nonlinear objective function", + ), + copy_model(model), + ) + return +end + +function test_deepcopy() + model = Model() + @test_throws( + ErrorException( + "`JuMP.Model` does not support `deepcopy` as the reference to the underlying solver cannot be deep copied, use `copy` instead.", + ), + deepcopy(model), + ) + return +end + end # module TestModels diff --git a/test/test_nlp.jl b/test/test_nlp.jl index fbbeea10edc..1c2d917f62e 100644 --- a/test/test_nlp.jl +++ b/test/test_nlp.jl @@ -1683,4 +1683,46 @@ function test_get_node_type_comparison() return end +function test_NL_dot() + model = Model() + @variable(model, x) + y = (; abc = x) + @NLexpression(model, ref, y.abc) + nlp = nonlinear_model(model) + @test MOI.Nonlinear.parse_expression(nlp, x) == nlp[index(ref)] + return +end + +function test_NL_adjoint() + model = Model() + @variable(model, x) + @NLexpression(model, ref, x') + nlp = nonlinear_model(model) + @test MOI.Nonlinear.parse_expression(nlp, x) == nlp[index(ref)] + return +end + +function test_NL_too_many_arguments_errors() + model = Model() + @test_throws_parsetime( + ErrorException( + "In `@NLexpression()`: To few arguments (0); must pass the model and nonlinear expression as arguments.", + ), + @NLexpression(), + ) + @test_throws_parsetime( + ErrorException( + "In `@NLexpression(model, ex, 1, 2)`: To many arguments (4).", + ), + @NLexpression(model, ex, 1, 2), + ) + @test_throws_parsetime( + ErrorException( + "In `@NLconstraint(model, ex, 1, 2)`: too many arguments.", + ), + @NLconstraint(model, ex, 1, 2), + ) + return +end + end