diff --git a/test/Project.toml b/test/Project.toml index 25d5e35c..4adebdb2 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -3,6 +3,7 @@ HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" JuMP = "4076af6c-e467-56ae-b986-b466b2749572" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" ParametricOptInterface = "0ce4ce61-57bf-432b-a095-efac525d185e" SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/no_free_model.jl b/test/no_free_model.jl deleted file mode 100644 index 35919a2a..00000000 --- a/test/no_free_model.jl +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2020: Tomás Gutierrez and contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -MOI.Utilities.@model( - NoFreeVariablesModel, - (), - (), - (MOI.Nonnegatives,), - (), - (), - (), - (MOI.VectorOfVariables,), - (), -) - -function MOI.supports_constraint( - ::NoFreeVariablesModel, - ::Type{MOI.VectorOfVariables}, - ::Type{MOI.Reals}, -) - return false -end - -function MOI.supports_add_constrained_variable( - ::NoFreeVariablesModel{T}, - ::Type{MOI.LessThan{T}}, -) where {T} - return true -end - -function MOI.supports_add_constrained_variables( - ::NoFreeVariablesModel, - ::Type{MOI.Nonnegatives}, -) - return true -end - -function MOI.supports_add_constrained_variables( - ::NoFreeVariablesModel, - ::Type{MOI.Reals}, -) - return false -end diff --git a/test/runtests.jl b/test/runtests.jl index fbf8dc44..501b9abd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,31 +3,8 @@ # Use of this source code is governed by an MIT-style license that can be found # in the LICENSE.md file or at https://opensource.org/licenses/MIT. -using JuMP using Test -import HiGHS -import Ipopt -import SCS - -import LinearAlgebra -import ParametricOptInterface - -const POI = ParametricOptInterface - -const ATOL = 1e-4 - -function canonical_compare(f1, f2) - return MOI.Utilities.canonical(f1) ≈ MOI.Utilities.canonical(f2) -end - -include("moi_tests.jl") -include("jump_tests.jl") - -for name in names(@__MODULE__; all = true) - if startswith("$name", "test_") - @testset "$(name)" begin - getfield(@__MODULE__, name)() - end - end +@testset "$file" for file in filter!(startswith("test_"), readdir(@__DIR__)) + include(joinpath(@__DIR__, file)) end diff --git a/test/jump_tests.jl b/test/test_JuMP.jl similarity index 98% rename from test/jump_tests.jl rename to test/test_JuMP.jl index 7f390942..a44cbb44 100644 --- a/test/jump_tests.jl +++ b/test/test_JuMP.jl @@ -3,6 +3,34 @@ # Use of this source code is governed by an MIT-style license that can be found # in the LICENSE.md file or at https://opensource.org/licenses/MIT. +module TestJuMPTests + +using Test +using JuMP + +import HiGHS +import Ipopt +import LinearAlgebra +import ParametricOptInterface as POI +import SCS + +const ATOL = 1e-4 + +function runtests() + for name in names(@__MODULE__; all = true) + if startswith("$name", "test_") + @testset "$(name)" begin + getfield(@__MODULE__, name)() + end + end + end + return +end + +function canonical_compare(f1, f2) + return MOI.Utilities.canonical(f1) ≈ MOI.Utilities.canonical(f2) +end + function test_jump_direct_affine_parameters() optimizer = POI.Optimizer(HiGHS.Optimizer()) model = direct_model(optimizer) @@ -446,7 +474,7 @@ function test_jump_direct_get_parameter_value() end function test_jump_get_parameter_value() - model = Model(() -> ParametricOptInterface.Optimizer(HiGHS.Optimizer())) + model = Model(() -> POI.Optimizer(HiGHS.Optimizer())) @variable(model, x, lower_bound = 0.0, upper_bound = 10.0) @variable(model, y, binary = true) @variable(model, z, set = MOI.Parameter(10)) @@ -852,7 +880,7 @@ function test_jump_dual_delete_constraint_3() end function test_jump_nlp() - model = Model(() -> ParametricOptInterface.Optimizer(Ipopt.Optimizer())) + model = Model(() -> POI.Optimizer(Ipopt.Optimizer())) @variable(model, x) @variable(model, z in MOI.Parameter(10.0)) @constraint(model, x >= z) @@ -1814,3 +1842,7 @@ function test_ListOfConstraintAttributesSet() @test ret == [] return end + +end # module + +TestJuMPTests.runtests() diff --git a/test/moi_tests.jl b/test/test_MathOptInterface.jl similarity index 98% rename from test/moi_tests.jl rename to test/test_MathOptInterface.jl index 9bae2f2f..268e1b5f 100644 --- a/test/moi_tests.jl +++ b/test/test_MathOptInterface.jl @@ -3,6 +3,74 @@ # Use of this source code is governed by an MIT-style license that can be found # in the LICENSE.md file or at https://opensource.org/licenses/MIT. +module TestMathOptInterfaceTests + +using Test + +import HiGHS +import Ipopt +import MathOptInterface as MOI +import ParametricOptInterface as POI +import SCS + +const ATOL = 1e-4 + +function runtests() + for name in names(@__MODULE__; all = true) + if startswith("$name", "test_") + @testset "$(name)" begin + getfield(@__MODULE__, name)() + end + end + end + return +end + +function canonical_compare(f1, f2) + return MOI.Utilities.canonical(f1) ≈ MOI.Utilities.canonical(f2) +end + +MOI.Utilities.@model( + NoFreeVariablesModel, + (), + (), + (MOI.Nonnegatives,), + (), + (), + (), + (MOI.VectorOfVariables,), + (), +) + +function MOI.supports_constraint( + ::NoFreeVariablesModel, + ::Type{MOI.VectorOfVariables}, + ::Type{MOI.Reals}, +) + return false +end + +function MOI.supports_add_constrained_variable( + ::NoFreeVariablesModel{T}, + ::Type{MOI.LessThan{T}}, +) where {T} + return true +end + +function MOI.supports_add_constrained_variables( + ::NoFreeVariablesModel, + ::Type{MOI.Nonnegatives}, +) + return true +end + +function MOI.supports_add_constrained_variables( + ::NoFreeVariablesModel, + ::Type{MOI.Reals}, +) + return false +end + function test_basic_tests() """ min x₁ + y @@ -2160,8 +2228,6 @@ function test_constrained_variable_HiGHS() return end -include("no_free_model.jl") - function test_constrained_variable_no_free() optimizer = POI.Optimizer(NoFreeVariablesModel{Float64}()) set = MOI.LessThan(1.0) @@ -2387,3 +2453,7 @@ function test_multiplicative_dual_error() @test_throws ErrorException MOI.get(model, MOI.ConstraintDual(), pc) return end + +end # module + +TestMathOptInterfaceTests.runtests()