Skip to content
Merged
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
91 changes: 57 additions & 34 deletions test/attributes.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
@testset "Attributes" begin
@testset "is_set_by_optimize" begin
@test MOI.is_set_by_optimize(MOI.TerminationStatus())
@test !MOI.is_set_by_optimize(MOI.ConstraintSet())
@test !MOI.is_set_by_optimize(MOI.ObjectiveSense())
@test MOI.is_set_by_optimize(MOI.CallbackNodeStatus(1))
end
@testset "is_copyable" begin
@test !MOI.is_copyable(MOI.TerminationStatus())
@test !MOI.is_copyable(MOI.ConstraintSet())
@test MOI.is_copyable(MOI.ObjectiveSense())
end
@testset "supports" begin
model = DummyModel()
@test_throws ArgumentError MOI.supports(model, MOI.TerminationStatus())
@test_throws ArgumentError begin
MOI.supports(
model,
MOI.ConstraintSet(),
MOI.ConstraintIndex{MOI.SingleVariable,MOI.EqualTo{Float64}},
)
end
@test MOI.supports(model, MOI.ObjectiveSense())
end
@testset "set vector" begin
attr = MOI.VariablePrimalStart()
err = DimensionMismatch(
"Number of indices (1) does not match the " *
"number of values (2) set to `$attr`.",
module TestAttributes

using Test
using MathOptInterface
const MOI = MathOptInterface

include("dummy.jl")

function test_attributes_is_set_by_optimize()
@test MOI.is_set_by_optimize(MOI.TerminationStatus())
@test !MOI.is_set_by_optimize(MOI.ConstraintSet())
@test !MOI.is_set_by_optimize(MOI.ObjectiveSense())
@test MOI.is_set_by_optimize(MOI.CallbackNodeStatus(1))
end

function test_attributes_is_copyable()
@test !MOI.is_copyable(MOI.TerminationStatus())
@test !MOI.is_copyable(MOI.ConstraintSet())
@test MOI.is_copyable(MOI.ObjectiveSense())
end

function test_attributes_supports()
model = DummyModel()
@test_throws ArgumentError MOI.supports(model, MOI.TerminationStatus())
@test_throws ArgumentError begin
MOI.supports(
model,
MOI.ConstraintSet(),
MOI.ConstraintIndex{MOI.SingleVariable,MOI.EqualTo{Float64}},
)
model = DummyModel()
x = MOI.VariableIndex(1)
@test_throws err MOI.set(model, MOI.VariablePrimalStart(), [x], ones(2))
end
@test MOI.supports(model, MOI.ObjectiveSense())
end

@testset "test_integration_compute_conflict" begin
function test_attributes_set_vector()
attr = MOI.VariablePrimalStart()
err = DimensionMismatch(
"Number of indices (1) does not match the " *
"number of values (2) set to `$attr`.",
)
model = DummyModel()
x = MOI.VariableIndex(1)
@test_throws err MOI.set(model, MOI.VariablePrimalStart(), [x], ones(2))
end

function test_attributes_integration_compute_conflict_1()
optimizer = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.Model{Float64}(),
Expand Down Expand Up @@ -90,7 +99,7 @@ MOI.Utilities.@model(
()
)

@testset "test_integration_compute_conflict" begin
function test_attributes_integration_compute_conflict_2()
optimizer = MOI.Utilities.MockOptimizer(OnlyScalarConstraints{Float64}())
model = MOI.Bridges.full_bridge_optimizer(optimizer, Float64)
x = MOI.add_variable(model)
Expand All @@ -107,3 +116,17 @@ MOI.Utilities.@model(
@test MOI.get(model, MOI.ConflictStatus()) == MOI.CONFLICT_FOUND
@test_throws ArgumentError MOI.get(model, MOI.ConstraintConflictStatus(), c)
end

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
end

end

TestAttributes.runtests()
25 changes: 21 additions & 4 deletions test/constraints.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module TestConstraints

using Test
using MathOptInterface
const MOI = MathOptInterface

function constant_not_zero_test(::Type{T}) where {T}
function _constant_not_zero_test(::Type{T}) where {T}
S = MOI.EqualTo{T}
x = MOI.VariableIndex(1)
fx = MOI.SingleVariable(x)
Expand All @@ -17,7 +19,22 @@ function constant_not_zero_test(::Type{T}) where {T}
@test nothing === MOI.throw_if_scalar_and_constant_not_zero(func, MOI.Zeros)
end

@testset "Constant not zero" begin
constant_not_zero_test(Int)
constant_not_zero_test(Float64)
function test_constraints_ConstantNotZero()
_constant_not_zero_test(Int)
_constant_not_zero_test(Float64)
return
end

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
end

end

TestConstraints.runtests()
22 changes: 19 additions & 3 deletions test/deprecate.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module TestDeprecate

using Test
using MathOptInterface
const MOI = MathOptInterface

@testset "deprecations" begin
function test_deprecations_N()
attr = MOI.VariablePrimal()
@test_deprecated begin
@test MOI._result_index_field(attr) == 1
Expand All @@ -26,16 +28,30 @@ const MOI = MathOptInterface
end
end

@testset "ScalarAffineTerm" begin
function test_deprecations_ScalarAffineTerm()
x = MOI.VariableIndex(1)
t = MOI.ScalarAffineTerm(1.0, x)
@test_logs (:warn,) t.variable_index == x
end

@testset "ScalarQuadraticTerm" begin
function test_deprecations_ScalarQuadraticTerm()
x = MOI.VariableIndex(1)
y = MOI.VariableIndex(2)
t = MOI.ScalarQuadraticTerm(1.0, x, y)
@test_logs (:warn,) t.variable_index_1 == x
@test_logs (:warn,) t.variable_index_2 == y
end

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
end

end

TestDeprecate.runtests()
Loading