From faee6d9d55d65526e68202813e6c4a6e7cd0d57e Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 27 Apr 2018 16:28:49 +1200 Subject: [PATCH 01/10] Change order of tests --- src/Test/modellike.jl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Test/modellike.jl b/src/Test/modellike.jl index 7f5c2d6b91..c696feb6d9 100644 --- a/src/Test/modellike.jl +++ b/src/Test/modellike.jl @@ -44,12 +44,6 @@ function nametest(model::MOI.ModelLike) MOI.set!(model, MOI.VariableName(), v, ["VarX","Var2"]) @test MOI.get(model, MOI.VariableName(), v) == ["VarX", "Var2"] - if MOI.candelete(model, v[2]) - MOI.delete!(model, v[2]) - @test !MOI.canget(model, MOI.VariableIndex, "Var2") - @test_throws KeyError MOI.get(model, MOI.VariableIndex, "Var2") - end - @test MOI.canaddconstraint(model, MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}) c = MOI.addconstraint!(model, MOI.ScalarAffineFunction(v, [1.0,1.0], 0.0), MOI.LessThan(1.0)) @test MOI.canaddconstraint(model, MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) @@ -68,7 +62,6 @@ function nametest(model::MOI.ModelLike) MOI.set!(model, MOI.ConstraintName(), [c], ["Con1"]) @test MOI.get(model, MOI.ConstraintName(), [c]) == ["Con1"] - @test MOI.canget(model, MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},MOI.LessThan{Float64}}, "Con1") @test !MOI.canget(model, MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},MOI.LessThan{Float64}}, "Con2") @test MOI.canget(model, MOI.ConstraintIndex, "Con1") @@ -79,6 +72,12 @@ function nametest(model::MOI.ModelLike) @test MOI.get(model, MOI.ConstraintIndex, "Con1") == c @test_throws KeyError MOI.get(model, MOI.ConstraintIndex, "Con2") + if MOI.candelete(model, v[2]) + MOI.delete!(model, v[2]) + @test !MOI.canget(model, MOI.VariableIndex, "Var2") + @test_throws KeyError MOI.get(model, MOI.VariableIndex, "Var2") + end + if MOI.candelete(model, c) MOI.delete!(model, c) @test !MOI.canget(model, MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},MOI.LessThan{Float64}}, "Con1") From fb97f1f0abe6425636a86eb18059e9881d7eb5d9 Mon Sep 17 00:00:00 2001 From: odow Date: Sat, 28 Apr 2018 18:37:10 +1200 Subject: [PATCH 02/10] Start some atomic tests --- src/Test/Test.jl | 2 + src/Test/atomic_tests.jl | 132 +++++++++++++++++++++++++++++++++++++++ src/indextypes.jl | 13 +++- 3 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 src/Test/atomic_tests.jl diff --git a/src/Test/Test.jl b/src/Test/Test.jl index f66edc2f88..a49e105599 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -18,4 +18,6 @@ include("intconic.jl") include("nlp.jl") +include("atomic_tests.jl") + end # module diff --git a/src/Test/atomic_tests.jl b/src/Test/atomic_tests.jl new file mode 100644 index 0000000000..7d9007bed8 --- /dev/null +++ b/src/Test/atomic_tests.jl @@ -0,0 +1,132 @@ +""" + This function tests adding a single variable. +""" +function add_variable(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canaddvariable(model) + @test MOI.get(model, MOI.NumberOfVariables()) == 0 + v = MOI.addvariable!(model) + @test MOI.get(model, MOI.NumberOfVariables()) == 1 +end + +""" + This function tests adding multiple variables. +""" +function add_variables(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canaddvariable(model) + @test MOI.get(model, MOI.NumberOfVariables()) == 0 + v = MOI.addvariables!(model, 2) + @test MOI.get(model, MOI.NumberOfVariables()) == 2 +end + +""" + This function tests adding, and then deleting, + a single variable. +""" +function delete_variable(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canaddvariable(model) + @test MOI.get(model, MOI.NumberOfVariables()) == 0 + v = MOI.addvariable!(model) + @test MOI.get(model, MOI.NumberOfVariables()) == 1 + @test MOI.candelete(model, v) + MOI.delete!(model, v) + @test MOI.get(model, MOI.NumberOfVariables()) == 0 +end + +""" + This function tests adding, and then deleting, + multiple variables. +""" +function delete_variables(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canaddvariable(model) + @test MOI.get(model, MOI.NumberOfVariables()) == 0 + v = MOI.addvariables!(model, 2) + @test MOI.get(model, MOI.NumberOfVariables()) == 2 + @test MOI.candelete(model, v) + MOI.delete!(model, v) + @test MOI.get(model, MOI.NumberOfVariables()) == 0 + v = MOI.addvariables!(model, 2) + @test MOI.get(model, MOI.NumberOfVariables()) == 2 + @test MOI.candelete(model, v[1]) + MOI.delete!(model, v[1]) + @test MOI.get(model, MOI.NumberOfVariables()) == 1 + @test !MOI.candelete(model, v[1]) + @test MOI.candelete(model, v[2]) + @test !MOI.isvalid(model, v[1]) + @test MOI.isvalid(model, v[2]) +end + +""" + Set objective to MaxSense +""" +function max_sense(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canset(model, MOI.ObjectiveSense()) + MOI.set!(model, MOI.ObjectiveSense(), MOI.MaxSense) + @test MOI.canget(model, MOI.ObjectiveSense()) + @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MaxSense +end + +""" + Set objective to MinSense +""" +function min_sense(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canset(model, MOI.ObjectiveSense()) + MOI.set!(model, MOI.ObjectiveSense(), MOI.MinSense) + @test MOI.canget(model, MOI.ObjectiveSense()) + @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MinSense +end + +""" + Test the setting of an upper bound +""" +function upperbound(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.supportsconstraint(model, + MOI.SingleVariable, + MOI.LessThan{Float64} + ) + v = MOI.addvariable!(model) + @test MOI.canaddconstraint(model, MOI.SingleVariable, MOI.LessThan{Float64}) + c = MOI.addconstraint!(model, + MOI.SingleVariable(v), + MOI.LessThan(1.0) + ) + @test MOI.get(model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{Float64}}() + ) == 1 + + @test MOI.canset(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()) + MOI.set!(model, + MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), + MOI.ScalarAffineFunction([v], [1.0], 0.0) + ) + @test MOI.canset(model, MOI.ObjectiveSense()) + MOI.set!(model, MOI.ObjectiveSense(), MOI.MaxSense) + + if config.solve + + end +end + +const atomictests = Dict( + "add_variable" => add_variable, + "add_variables" => add_variables, + "delete_variable" => delete_variable, + "delete_variables" => delete_variables, + "min_sense" => min_sense, + "max_sense" => max_sense, + "upperbound" => upperbound +) +@moitestset atomic diff --git a/src/indextypes.jl b/src/indextypes.jl index ca3823654e..67144d44b5 100644 --- a/src/indextypes.jl +++ b/src/indextypes.jl @@ -41,15 +41,22 @@ isvalid(model::ModelLike, ref::Index) = false delete!(model::ModelLike, index::Index) Delete the referenced object from the model. +""" +Base.delete!(model::ModelLike, index::Index) = throw(MethodError(Base.delete!, (model, index))) + +""" + candelete(model::ModelLike, indices::Vector{<:Index})::Bool +Return a `Bool` indicating whether all the objects referred to by `indices` can be removed from the model `model`. +""" +candelete(model::ModelLike, indices::Vector{<:Index}) = all(candelete.(model, indices)) + +""" delete!{R}(model::ModelLike, indices::Vector{R<:Index}) Delete the referenced objects in the vector `indices` from the model. It may be assumed that `R` is a concrete type. """ -Base.delete!(model::ModelLike, index::Index) = throw(MethodError(Base.delete!, (model, index))) - -candelete(model::ModelLike, indices::Vector{<:Index}) = all(candelete.(model, indices)) function Base.delete!(model::ModelLike, indices::Vector{<:Index}) for index in indices Base.delete!(model, index) From 10f8cfd1aafaae43820231bec00b3070e9432775 Mon Sep 17 00:00:00 2001 From: odow Date: Sat, 28 Apr 2018 19:30:10 +1200 Subject: [PATCH 03/10] more tests --- src/MathOptInterface.jl | 2 +- src/Test/Test.jl | 1 + src/Test/atomic_tests.jl | 102 ++++++++++++++++++++++++++++++--------- 3 files changed, 81 insertions(+), 24 deletions(-) diff --git a/src/MathOptInterface.jl b/src/MathOptInterface.jl index b4959f6f1d..97955d0318 100644 --- a/src/MathOptInterface.jl +++ b/src/MathOptInterface.jl @@ -157,8 +157,8 @@ include("variables.jl") include("nlp.jl") # submodules -include("Test/Test.jl") # MOI.Test include("Utilities/Utilities.jl") # MOI.Utilities +include("Test/Test.jl") # MOI.Test include("Bridges/Bridges.jl") # MOI.Bridges end diff --git a/src/Test/Test.jl b/src/Test/Test.jl index a49e105599..a6f44899ba 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -2,6 +2,7 @@ module Test using MathOptInterface const MOI = MathOptInterface +const MOIU = MOI.Utilities using Base.Test diff --git a/src/Test/atomic_tests.jl b/src/Test/atomic_tests.jl index 7d9007bed8..6dc94c4fb2 100644 --- a/src/Test/atomic_tests.jl +++ b/src/Test/atomic_tests.jl @@ -91,33 +91,86 @@ end Test the setting of an upper bound """ function upperbound(model::MOI.ModelLike, config::TestConfig) + atol, rtol = config.atol, config.rtol MOI.empty!(model) @test MOI.isempty(model) - @test MOI.supportsconstraint(model, - MOI.SingleVariable, - MOI.LessThan{Float64} - ) - v = MOI.addvariable!(model) - @test MOI.canaddconstraint(model, MOI.SingleVariable, MOI.LessThan{Float64}) - c = MOI.addconstraint!(model, - MOI.SingleVariable(v), - MOI.LessThan(1.0) - ) - @test MOI.get(model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{Float64}}() - ) == 1 + MOIU.loadfromstring!(model,""" + variables: x + maxobjective: 2.0x + c1: x <= 1.0 + c2: x >= 0.0 + """) + MOI.optimize!(model) + @test MOI.get(model, MOI.PrimalStatus()) == MOI.FeasiblePoint + v = MOI.get(model, MOI.VariableIndex, "x") + @test MOI.get(model, MOI.VariablePrimal(), v) ≈ 1 atol=atol rtol=rtol + if config.duals + @test MOI.get(model, MOI.DualStatus()) == MOI.FeasiblePoint + c1 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable,MOI.LessThan{Float64}}, "c1") + @test MOI.get(model, MOI.ConstraintDual(), c1) ≈ -2.0 atol=atol rtol=rtol + c2 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable,MOI.GreaterThan{Float64}}, "c2") + @test MOI.get(model, MOI.ConstraintDual(), c2) ≈ 0.0 atol=atol rtol=rtol + end +end - @test MOI.canset(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()) - MOI.set!(model, - MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), - MOI.ScalarAffineFunction([v], [1.0], 0.0) - ) - @test MOI.canset(model, MOI.ObjectiveSense()) - MOI.set!(model, MOI.ObjectiveSense(), MOI.MaxSense) +""" + Test the setting of an lower bound +""" +function lowerbound(model::MOI.ModelLike, config::TestConfig) + atol, rtol = config.atol, config.rtol + MOI.empty!(model) + @test MOI.isempty(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: 2.0x + c1: x >= 1.0 + c2: x <= 2.0 + """) + MOI.optimize!(model) + @test MOI.get(model, MOI.PrimalStatus()) == MOI.FeasiblePoint + v = MOI.get(model, MOI.VariableIndex, "x") + @test MOI.get(model, MOI.VariablePrimal(), v) ≈ 1 atol=atol rtol=rtol + if config.duals + @test MOI.get(model, MOI.DualStatus()) == MOI.FeasiblePoint + c1 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable,MOI.GreaterThan{Float64}}, "c1") + @test MOI.get(model, MOI.ConstraintDual(), c1) ≈ 2.0 atol=atol rtol=rtol + c2 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable,MOI.LessThan{Float64}}, "c2") + @test MOI.get(model, MOI.ConstraintDual(), c2) ≈ 0.0 atol=atol rtol=rtol + end +end + +function getvariable(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: 2.0x + c1: x >= 1.0 + c2: x <= 2.0 + """) + @test MOI.canget(model, MOI.VariableIndex, "x") + x = MOI.get(model, MOI.VariableIndex, "x") + @test MOI.isvalid(model, x) +end - if config.solve +function getconstraint(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: 2.0x + c1: x >= 1.0 + c2: x <= 2.0 + """) + @test MOI.canget(model, MOI.ConstraintIndex, "c1") + @test MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c1") + @test !MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c1") + @test MOI.canget(model, MOI.ConstraintIndex, "c2") + @test !MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c2") + @test MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") - end + c1 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c1") + @test MOI.isvalid(model, c1) + c2 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") + @test MOI.isvalid(model, c2) end const atomictests = Dict( @@ -127,6 +180,9 @@ const atomictests = Dict( "delete_variables" => delete_variables, "min_sense" => min_sense, "max_sense" => max_sense, - "upperbound" => upperbound + "upperbound" => upperbound, + "lowerbound" => lowerbound, + "getvariable" => getvariable, + "getconstraint" => getconstraint ) @moitestset atomic From e89135cbc7d6da99a045132861d00f807b8177fa Mon Sep 17 00:00:00 2001 From: odow Date: Sat, 28 Apr 2018 19:47:33 +1200 Subject: [PATCH 04/10] Objective tests --- src/Test/atomic_tests.jl | 45 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/Test/atomic_tests.jl b/src/Test/atomic_tests.jl index 6dc94c4fb2..45b7f4c003 100644 --- a/src/Test/atomic_tests.jl +++ b/src/Test/atomic_tests.jl @@ -87,6 +87,38 @@ function min_sense(model::MOI.ModelLike, config::TestConfig) @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MinSense end +""" + Test constant in objective. +""" +function constantobj(model::MOI.ModelLike, config::TestConfig) + atol, rtol = config.atol, config.rtol + MOI.empty!(model) + @test MOI.isempty(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: 2.0x + 1.0 + c: x >= 1.0 + """) + MOI.optimize!(model) + @test MOI.get(model, MOI.ObjectiveValue()) ≈ 3.0 atol=atol rtol=rtol +end + +""" + Test blank objective. +""" +function blankobj(model::MOI.ModelLike, config::TestConfig) + atol, rtol = config.atol, config.rtol + MOI.empty!(model) + @test MOI.isempty(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: 0.0x + 0.0 + c: x >= 1.0 + """) + MOI.optimize!(model) + @test MOI.get(model, MOI.ObjectiveValue()) ≈ 0.0 atol=atol rtol=rtol +end + """ Test the setting of an upper bound """ @@ -139,6 +171,9 @@ function lowerbound(model::MOI.ModelLike, config::TestConfig) end end +""" + Test getting variables by name. +""" function getvariable(model::MOI.ModelLike, config::TestConfig) MOI.empty!(model) MOIU.loadfromstring!(model,""" @@ -148,10 +183,14 @@ function getvariable(model::MOI.ModelLike, config::TestConfig) c2: x <= 2.0 """) @test MOI.canget(model, MOI.VariableIndex, "x") + @test !MOI.canget(model, MOI.VariableIndex, "y") x = MOI.get(model, MOI.VariableIndex, "x") @test MOI.isvalid(model, x) end +""" + Test getting constraints by name. +""" function getconstraint(model::MOI.ModelLike, config::TestConfig) MOI.empty!(model) MOIU.loadfromstring!(model,""" @@ -160,13 +199,13 @@ function getconstraint(model::MOI.ModelLike, config::TestConfig) c1: x >= 1.0 c2: x <= 2.0 """) + @test !MOI.canget(model, MOI.ConstraintIndex, "c3") @test MOI.canget(model, MOI.ConstraintIndex, "c1") @test MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c1") @test !MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c1") @test MOI.canget(model, MOI.ConstraintIndex, "c2") @test !MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c2") @test MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") - c1 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c1") @test MOI.isvalid(model, c1) c2 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") @@ -183,6 +222,8 @@ const atomictests = Dict( "upperbound" => upperbound, "lowerbound" => lowerbound, "getvariable" => getvariable, - "getconstraint" => getconstraint + "getconstraint" => getconstraint, + "constantobj" => constantobj, + "blankobj" => blankobj ) @moitestset atomic From b04d8588547c49c360d61791ecd3e1848e1f5f0f Mon Sep 17 00:00:00 2001 From: odow Date: Sat, 28 Apr 2018 22:03:52 +1200 Subject: [PATCH 05/10] Test setting variable name --- src/Test/atomic_tests.jl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Test/atomic_tests.jl b/src/Test/atomic_tests.jl index 45b7f4c003..cbc455b2d2 100644 --- a/src/Test/atomic_tests.jl +++ b/src/Test/atomic_tests.jl @@ -212,6 +212,20 @@ function getconstraint(model::MOI.ModelLike, config::TestConfig) @test MOI.isvalid(model, c2) end +function variablenames(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + v = MOI.addvariable!(model) + @test MOI.get(model, MOI.VariableName(), v) == "" + @test MOI.canset(model, MOI.VariableName(), typeof(v)) + MOI.set!(model, MOI.VariableName(), v, "x") + @test MOI.get(model, MOI.VariableName(), v) == "x" + MOI.set!(model, MOI.VariableName(), v, "y") + @test MOI.get(model, MOI.VariableName(), v) == "y" + x = MOI.addvariable!(model) + MOI.set!(model, MOI.VariableName(), x, "x") + @test MOI.get(model, MOI.VariableName(), x) == "x" +end + const atomictests = Dict( "add_variable" => add_variable, "add_variables" => add_variables, @@ -224,6 +238,7 @@ const atomictests = Dict( "getvariable" => getvariable, "getconstraint" => getconstraint, "constantobj" => constantobj, - "blankobj" => blankobj + "blankobj" => blankobj, + "variablenames" => variablenames ) @moitestset atomic From 710510ce27c68a2350dd7a168ae94364d1bc4135 Mon Sep 17 00:00:00 2001 From: odow Date: Sun, 29 Apr 2018 10:30:01 +1200 Subject: [PATCH 06/10] reorganize and add test for SingleVariable --- src/Test/AtomicTests/atomic_tests.jl | 12 ++ src/Test/AtomicTests/constraints.jl | 24 +++ src/Test/AtomicTests/objectives.jl | 105 +++++++++++ .../variables.jl} | 164 ++++++------------ src/Test/Test.jl | 2 +- 5 files changed, 191 insertions(+), 116 deletions(-) create mode 100644 src/Test/AtomicTests/atomic_tests.jl create mode 100644 src/Test/AtomicTests/constraints.jl create mode 100644 src/Test/AtomicTests/objectives.jl rename src/Test/{atomic_tests.jl => AtomicTests/variables.jl} (61%) diff --git a/src/Test/AtomicTests/atomic_tests.jl b/src/Test/AtomicTests/atomic_tests.jl new file mode 100644 index 0000000000..1a0d71d276 --- /dev/null +++ b/src/Test/AtomicTests/atomic_tests.jl @@ -0,0 +1,12 @@ +#= + These tests aim to minimally test each expected feature in MOI, in addition + to the full end-to-end tests in contlinear.jl etc +=# + +const atomictests = Dict{String, Function}() + +include("variables.jl") +include("objectives.jl") +include("constraints.jl") + +@moitestset atomic diff --git a/src/Test/AtomicTests/constraints.jl b/src/Test/AtomicTests/constraints.jl new file mode 100644 index 0000000000..e090a546a2 --- /dev/null +++ b/src/Test/AtomicTests/constraints.jl @@ -0,0 +1,24 @@ +""" + Test getting constraints by name. +""" +function getconstraint(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: 2.0x + c1: x >= 1.0 + c2: x <= 2.0 + """) + @test !MOI.canget(model, MOI.ConstraintIndex, "c3") + @test MOI.canget(model, MOI.ConstraintIndex, "c1") + @test MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c1") + @test !MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c1") + @test MOI.canget(model, MOI.ConstraintIndex, "c2") + @test !MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c2") + @test MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") + c1 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c1") + @test MOI.isvalid(model, c1) + c2 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") + @test MOI.isvalid(model, c2) +end +atomictests["getconstraint"] = getconstraint diff --git a/src/Test/AtomicTests/objectives.jl b/src/Test/AtomicTests/objectives.jl new file mode 100644 index 0000000000..c3cccae85c --- /dev/null +++ b/src/Test/AtomicTests/objectives.jl @@ -0,0 +1,105 @@ +#= + Functions in this file test functionality relating to objectives in MOI. + +### Requires + - optimize! + +### Functionality currently tested + - get/set ObjectiveSense + - a constant in a affine objective + - a blank objective + +### Functionality not yet tested + - Quadratic Objectives + - Modifications +=# + +""" + Set objective to MaxSense +""" +function max_sense(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canset(model, MOI.ObjectiveSense()) + MOI.set!(model, MOI.ObjectiveSense(), MOI.MaxSense) + @test MOI.canget(model, MOI.ObjectiveSense()) + @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MaxSense +end +atomictests["max_sense"] = max_sense + +""" + Set objective to MinSense +""" +function min_sense(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canset(model, MOI.ObjectiveSense()) + MOI.set!(model, MOI.ObjectiveSense(), MOI.MinSense) + @test MOI.canget(model, MOI.ObjectiveSense()) + @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MinSense +end +atomictests["min_sense"] = min_sense + +""" + Set objective to FeasibilitySense +""" +function feasibility_sense(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + @test MOI.isempty(model) + @test MOI.canset(model, MOI.ObjectiveSense()) + MOI.set!(model, MOI.ObjectiveSense(), MOI.FeasibilitySense) + @test MOI.canget(model, MOI.ObjectiveSense()) + @test MOI.get(model, MOI.ObjectiveSense()) == MOI.FeasibilitySense +end +atomictests["feasibility_sense"] = feasibility_sense + +""" + Test constant in objective. +""" +function constant_obj(model::MOI.ModelLike, config::TestConfig) + atol, rtol = config.atol, config.rtol + MOI.empty!(model) + @test MOI.isempty(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: 2.0x + 1.0 + c: x >= 1.0 + """) + MOI.optimize!(model) + @test MOI.get(model, MOI.ObjectiveValue()) ≈ 3.0 atol=atol rtol=rtol +end +atomictests["constant_obj"] = constant_obj + +""" + Test blank objective. +""" +function blank_obj(model::MOI.ModelLike, config::TestConfig) + atol, rtol = config.atol, config.rtol + MOI.empty!(model) + @test MOI.isempty(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: 0.0x + 0.0 + c: x >= 1.0 + """) + MOI.optimize!(model) + @test MOI.get(model, MOI.ObjectiveValue()) ≈ 0.0 atol=atol rtol=rtol +end +atomictests["blank_obj"] = blank_obj + +""" + Test SingleVariable objective. +""" +function singlevariable_obj(model::MOI.ModelLike, config::TestConfig) + atol, rtol = config.atol, config.rtol + MOI.empty!(model) + @test MOI.isempty(model) + MOIU.loadfromstring!(model,""" + variables: x + minobjective: x + c: x >= 1.0 + """) + MOI.optimize!(model) + @test MOI.get(model, MOI.ObjectiveValue()) ≈ 1.0 atol=atol rtol=rtol +end +atomictests["singlevariable_obj"] = singlevariable_obj diff --git a/src/Test/atomic_tests.jl b/src/Test/AtomicTests/variables.jl similarity index 61% rename from src/Test/atomic_tests.jl rename to src/Test/AtomicTests/variables.jl index cbc455b2d2..345058acb0 100644 --- a/src/Test/atomic_tests.jl +++ b/src/Test/AtomicTests/variables.jl @@ -1,3 +1,23 @@ +#= + Functions in this file test functionality relating to variables in MOI. + +### Functionality currently tested + - canaddvariable + - addvariables! + - addvariable! + - deleting variables + - get/set! VariableName + - isvalid for VariableIndex + - get VariableIndex by name + - NumberOfVariables + +### Functionality not yet tested + - VariablePrimalStart + - VariablePrimal + - VariableBasisStatus + - ListOfVariableIndices +=# + """ This function tests adding a single variable. """ @@ -9,6 +29,7 @@ function add_variable(model::MOI.ModelLike, config::TestConfig) v = MOI.addvariable!(model) @test MOI.get(model, MOI.NumberOfVariables()) == 1 end +atomictests["add_variable"] = add_variable """ This function tests adding multiple variables. @@ -21,6 +42,7 @@ function add_variables(model::MOI.ModelLike, config::TestConfig) v = MOI.addvariables!(model, 2) @test MOI.get(model, MOI.NumberOfVariables()) == 2 end +atomictests["add_variables"] = add_variables """ This function tests adding, and then deleting, @@ -37,6 +59,7 @@ function delete_variable(model::MOI.ModelLike, config::TestConfig) MOI.delete!(model, v) @test MOI.get(model, MOI.NumberOfVariables()) == 0 end +atomictests["delete_variable"] = delete_variable """ This function tests adding, and then deleting, @@ -62,62 +85,43 @@ function delete_variables(model::MOI.ModelLike, config::TestConfig) @test !MOI.isvalid(model, v[1]) @test MOI.isvalid(model, v[2]) end +atomictests["delete_variables"] = delete_variable """ - Set objective to MaxSense -""" -function max_sense(model::MOI.ModelLike, config::TestConfig) - MOI.empty!(model) - @test MOI.isempty(model) - @test MOI.canset(model, MOI.ObjectiveSense()) - MOI.set!(model, MOI.ObjectiveSense(), MOI.MaxSense) - @test MOI.canget(model, MOI.ObjectiveSense()) - @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MaxSense -end - -""" - Set objective to MinSense -""" -function min_sense(model::MOI.ModelLike, config::TestConfig) - MOI.empty!(model) - @test MOI.isempty(model) - @test MOI.canset(model, MOI.ObjectiveSense()) - MOI.set!(model, MOI.ObjectiveSense(), MOI.MinSense) - @test MOI.canget(model, MOI.ObjectiveSense()) - @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MinSense -end - -""" - Test constant in objective. + Test getting variables by name. """ -function constantobj(model::MOI.ModelLike, config::TestConfig) - atol, rtol = config.atol, config.rtol +function getvariable(model::MOI.ModelLike, config::TestConfig) MOI.empty!(model) - @test MOI.isempty(model) MOIU.loadfromstring!(model,""" variables: x - minobjective: 2.0x + 1.0 - c: x >= 1.0 + minobjective: 2.0x + c1: x >= 1.0 + c2: x <= 2.0 """) - MOI.optimize!(model) - @test MOI.get(model, MOI.ObjectiveValue()) ≈ 3.0 atol=atol rtol=rtol + @test MOI.canget(model, MOI.VariableIndex, "x") + @test !MOI.canget(model, MOI.VariableIndex, "y") + x = MOI.get(model, MOI.VariableIndex, "x") + @test MOI.isvalid(model, x) end +atomictests["getvariable"] = getvariable """ - Test blank objective. + Test getting and setting varaible names. """ -function blankobj(model::MOI.ModelLike, config::TestConfig) - atol, rtol = config.atol, config.rtol +function variablenames(model::MOI.ModelLike, config::TestConfig) MOI.empty!(model) - @test MOI.isempty(model) - MOIU.loadfromstring!(model,""" - variables: x - minobjective: 0.0x + 0.0 - c: x >= 1.0 - """) - MOI.optimize!(model) - @test MOI.get(model, MOI.ObjectiveValue()) ≈ 0.0 atol=atol rtol=rtol + v = MOI.addvariable!(model) + @test MOI.get(model, MOI.VariableName(), v) == "" + @test MOI.canset(model, MOI.VariableName(), typeof(v)) + MOI.set!(model, MOI.VariableName(), v, "x") + @test MOI.get(model, MOI.VariableName(), v) == "x" + MOI.set!(model, MOI.VariableName(), v, "y") + @test MOI.get(model, MOI.VariableName(), v) == "y" + x = MOI.addvariable!(model) + MOI.set!(model, MOI.VariableName(), x, "x") + @test MOI.get(model, MOI.VariableName(), x) == "x" end +atomictests["variablenames"] = variablenames """ Test the setting of an upper bound @@ -144,6 +148,7 @@ function upperbound(model::MOI.ModelLike, config::TestConfig) @test MOI.get(model, MOI.ConstraintDual(), c2) ≈ 0.0 atol=atol rtol=rtol end end +atomictests["upperbound"] = upperbound """ Test the setting of an lower bound @@ -170,75 +175,4 @@ function lowerbound(model::MOI.ModelLike, config::TestConfig) @test MOI.get(model, MOI.ConstraintDual(), c2) ≈ 0.0 atol=atol rtol=rtol end end - -""" - Test getting variables by name. -""" -function getvariable(model::MOI.ModelLike, config::TestConfig) - MOI.empty!(model) - MOIU.loadfromstring!(model,""" - variables: x - minobjective: 2.0x - c1: x >= 1.0 - c2: x <= 2.0 - """) - @test MOI.canget(model, MOI.VariableIndex, "x") - @test !MOI.canget(model, MOI.VariableIndex, "y") - x = MOI.get(model, MOI.VariableIndex, "x") - @test MOI.isvalid(model, x) -end - -""" - Test getting constraints by name. -""" -function getconstraint(model::MOI.ModelLike, config::TestConfig) - MOI.empty!(model) - MOIU.loadfromstring!(model,""" - variables: x - minobjective: 2.0x - c1: x >= 1.0 - c2: x <= 2.0 - """) - @test !MOI.canget(model, MOI.ConstraintIndex, "c3") - @test MOI.canget(model, MOI.ConstraintIndex, "c1") - @test MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c1") - @test !MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c1") - @test MOI.canget(model, MOI.ConstraintIndex, "c2") - @test !MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c2") - @test MOI.canget(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") - c1 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}, "c1") - @test MOI.isvalid(model, c1) - c2 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") - @test MOI.isvalid(model, c2) -end - -function variablenames(model::MOI.ModelLike, config::TestConfig) - MOI.empty!(model) - v = MOI.addvariable!(model) - @test MOI.get(model, MOI.VariableName(), v) == "" - @test MOI.canset(model, MOI.VariableName(), typeof(v)) - MOI.set!(model, MOI.VariableName(), v, "x") - @test MOI.get(model, MOI.VariableName(), v) == "x" - MOI.set!(model, MOI.VariableName(), v, "y") - @test MOI.get(model, MOI.VariableName(), v) == "y" - x = MOI.addvariable!(model) - MOI.set!(model, MOI.VariableName(), x, "x") - @test MOI.get(model, MOI.VariableName(), x) == "x" -end - -const atomictests = Dict( - "add_variable" => add_variable, - "add_variables" => add_variables, - "delete_variable" => delete_variable, - "delete_variables" => delete_variables, - "min_sense" => min_sense, - "max_sense" => max_sense, - "upperbound" => upperbound, - "lowerbound" => lowerbound, - "getvariable" => getvariable, - "getconstraint" => getconstraint, - "constantobj" => constantobj, - "blankobj" => blankobj, - "variablenames" => variablenames -) -@moitestset atomic +atomictests["lowerbound"] = lowerbound diff --git a/src/Test/Test.jl b/src/Test/Test.jl index a6f44899ba..35728fa01d 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -19,6 +19,6 @@ include("intconic.jl") include("nlp.jl") -include("atomic_tests.jl") +include("AtomicTests/atomic_tests.jl") end # module From c387d55cba4cab3bf90010a650a50894c8160291 Mon Sep 17 00:00:00 2001 From: odow Date: Sun, 29 Apr 2018 15:10:26 +1200 Subject: [PATCH 07/10] Add atomic to tests --- test/Test/atomic.jl | 14 +++++++++++ test/{ => Test}/config.jl | 0 test/{ => Test}/contconic.jl | 0 test/{ => Test}/contlinear.jl | 0 test/{ => Test}/contquadratic.jl | 0 test/{ => Test}/intconic.jl | 0 test/{ => Test}/intlinear.jl | 0 test/runtests.jl | 43 ++++++++++++++++++-------------- 8 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 test/Test/atomic.jl rename test/{ => Test}/config.jl (100%) rename test/{ => Test}/contconic.jl (100%) rename test/{ => Test}/contlinear.jl (100%) rename test/{ => Test}/contquadratic.jl (100%) rename test/{ => Test}/intconic.jl (100%) rename test/{ => Test}/intlinear.jl (100%) diff --git a/test/Test/atomic.jl b/test/Test/atomic.jl new file mode 100644 index 0000000000..26b0b6213c --- /dev/null +++ b/test/Test/atomic.jl @@ -0,0 +1,14 @@ +@testset "Atomic Tests" begin + mock = MOIU.MockOptimizer(Model{Float64}()) + config = MOIT.TestConfig() + MOIT.atomictest(mock, config, [ + "constant_obj", + "getvariable", + "getconstraint", + "blank_obj", + "lowerbound", + "upperbound", + "singlevariable_obj", + "variablenames" + ]) +end diff --git a/test/config.jl b/test/Test/config.jl similarity index 100% rename from test/config.jl rename to test/Test/config.jl diff --git a/test/contconic.jl b/test/Test/contconic.jl similarity index 100% rename from test/contconic.jl rename to test/Test/contconic.jl diff --git a/test/contlinear.jl b/test/Test/contlinear.jl similarity index 100% rename from test/contlinear.jl rename to test/Test/contlinear.jl diff --git a/test/contquadratic.jl b/test/Test/contquadratic.jl similarity index 100% rename from test/contquadratic.jl rename to test/Test/contquadratic.jl diff --git a/test/intconic.jl b/test/Test/intconic.jl similarity index 100% rename from test/intconic.jl rename to test/Test/intconic.jl diff --git a/test/intlinear.jl b/test/Test/intlinear.jl similarity index 100% rename from test/intlinear.jl rename to test/Test/intlinear.jl diff --git a/test/runtests.jl b/test/runtests.jl index 3570c36634..5449ab9d73 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,25 +24,30 @@ MOIU.@model(Model, @MOIU.model ModelForMock (ZeroOne, Integer) (EqualTo, GreaterThan, LessThan, Interval) (Zeros, Nonnegatives, Nonpositives, SecondOrderCone) () (SingleVariable,) (ScalarAffineFunction,) (VectorOfVariables,) (VectorAffineFunction,) # Utilities submodule tests -include("functions.jl") -include("sets.jl") -include("model.jl") -include("universalfallback.jl") -include("parser.jl") -include("mockoptimizer.jl") -include("cachingoptimizer.jl") -include("copy.jl") +@testset "MOI.Utilities" begin + include("functions.jl") + include("sets.jl") + include("model.jl") + include("universalfallback.jl") + include("parser.jl") + include("mockoptimizer.jl") + include("cachingoptimizer.jl") + include("copy.jl") +end # Test submodule tests # It tests that the ConstraintPrimal value requested in the tests is consistent with the VariablePrimal -include("config.jl") - -include("contlinear.jl") -include("contconic.jl") -include("contquadratic.jl") - -include("intlinear.jl") -include("intconic.jl") - -# Bridges submodule tests -include("bridge.jl") +@testset "MOI.Test" begin + include("Test/config.jl") + include("Test/atomic.jl") + include("Test/contlinear.jl") + include("Test/contconic.jl") + include("Test/contquadratic.jl") + include("Test/intlinear.jl") + include("Test/intconic.jl") +end + +@testset "MOI.Bridges" begin + # Bridges submodule tests + include("bridge.jl") +end From 496b98db80791ad12dbab47e215648895c0377cd Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 1 May 2018 08:50:31 +1200 Subject: [PATCH 08/10] Address mlubin's comments --- src/Test/Test.jl | 2 +- .../{AtomicTests => UnitTests}/constraints.jl | 2 +- .../{AtomicTests => UnitTests}/objectives.jl | 18 ++++++++--------- .../unit_tests.jl} | 4 ++-- .../{AtomicTests => UnitTests}/variables.jl | 20 +++++++++---------- test/Test/atomic.jl | 14 ------------- test/Test/unit.jl | 14 +++++++++++++ 7 files changed, 37 insertions(+), 37 deletions(-) rename src/Test/{AtomicTests => UnitTests}/constraints.jl (95%) rename src/Test/{AtomicTests => UnitTests}/objectives.jl (83%) rename src/Test/{AtomicTests/atomic_tests.jl => UnitTests/unit_tests.jl} (77%) rename src/Test/{AtomicTests => UnitTests}/variables.jl (90%) delete mode 100644 test/Test/atomic.jl create mode 100644 test/Test/unit.jl diff --git a/src/Test/Test.jl b/src/Test/Test.jl index 35728fa01d..617300a5af 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -19,6 +19,6 @@ include("intconic.jl") include("nlp.jl") -include("AtomicTests/atomic_tests.jl") +include("UnitTests/unit_tests.jl") end # module diff --git a/src/Test/AtomicTests/constraints.jl b/src/Test/UnitTests/constraints.jl similarity index 95% rename from src/Test/AtomicTests/constraints.jl rename to src/Test/UnitTests/constraints.jl index e090a546a2..de4e7d3436 100644 --- a/src/Test/AtomicTests/constraints.jl +++ b/src/Test/UnitTests/constraints.jl @@ -21,4 +21,4 @@ function getconstraint(model::MOI.ModelLike, config::TestConfig) c2 = MOI.get(model, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "c2") @test MOI.isvalid(model, c2) end -atomictests["getconstraint"] = getconstraint +unittests["getconstraint"] = getconstraint diff --git a/src/Test/AtomicTests/objectives.jl b/src/Test/UnitTests/objectives.jl similarity index 83% rename from src/Test/AtomicTests/objectives.jl rename to src/Test/UnitTests/objectives.jl index c3cccae85c..a9bc65f8f8 100644 --- a/src/Test/AtomicTests/objectives.jl +++ b/src/Test/UnitTests/objectives.jl @@ -25,7 +25,7 @@ function max_sense(model::MOI.ModelLike, config::TestConfig) @test MOI.canget(model, MOI.ObjectiveSense()) @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MaxSense end -atomictests["max_sense"] = max_sense +unittests["max_sense"] = max_sense """ Set objective to MinSense @@ -38,7 +38,7 @@ function min_sense(model::MOI.ModelLike, config::TestConfig) @test MOI.canget(model, MOI.ObjectiveSense()) @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MinSense end -atomictests["min_sense"] = min_sense +unittests["min_sense"] = min_sense """ Set objective to FeasibilitySense @@ -51,12 +51,12 @@ function feasibility_sense(model::MOI.ModelLike, config::TestConfig) @test MOI.canget(model, MOI.ObjectiveSense()) @test MOI.get(model, MOI.ObjectiveSense()) == MOI.FeasibilitySense end -atomictests["feasibility_sense"] = feasibility_sense +unittests["feasibility_sense"] = feasibility_sense """ Test constant in objective. """ -function constant_obj(model::MOI.ModelLike, config::TestConfig) +function solve_constant_obj(model::MOI.ModelLike, config::TestConfig) atol, rtol = config.atol, config.rtol MOI.empty!(model) @test MOI.isempty(model) @@ -68,12 +68,12 @@ function constant_obj(model::MOI.ModelLike, config::TestConfig) MOI.optimize!(model) @test MOI.get(model, MOI.ObjectiveValue()) ≈ 3.0 atol=atol rtol=rtol end -atomictests["constant_obj"] = constant_obj +unittests["solve_constant_obj"] = solve_constant_obj """ Test blank objective. """ -function blank_obj(model::MOI.ModelLike, config::TestConfig) +function solve_blank_obj(model::MOI.ModelLike, config::TestConfig) atol, rtol = config.atol, config.rtol MOI.empty!(model) @test MOI.isempty(model) @@ -85,12 +85,12 @@ function blank_obj(model::MOI.ModelLike, config::TestConfig) MOI.optimize!(model) @test MOI.get(model, MOI.ObjectiveValue()) ≈ 0.0 atol=atol rtol=rtol end -atomictests["blank_obj"] = blank_obj +unittests["solve_blank_obj"] = solve_blank_obj """ Test SingleVariable objective. """ -function singlevariable_obj(model::MOI.ModelLike, config::TestConfig) +function solve_singlevariable_obj(model::MOI.ModelLike, config::TestConfig) atol, rtol = config.atol, config.rtol MOI.empty!(model) @test MOI.isempty(model) @@ -102,4 +102,4 @@ function singlevariable_obj(model::MOI.ModelLike, config::TestConfig) MOI.optimize!(model) @test MOI.get(model, MOI.ObjectiveValue()) ≈ 1.0 atol=atol rtol=rtol end -atomictests["singlevariable_obj"] = singlevariable_obj +unittests["solve_singlevariable_obj"] = solve_singlevariable_obj diff --git a/src/Test/AtomicTests/atomic_tests.jl b/src/Test/UnitTests/unit_tests.jl similarity index 77% rename from src/Test/AtomicTests/atomic_tests.jl rename to src/Test/UnitTests/unit_tests.jl index 1a0d71d276..0da080ef88 100644 --- a/src/Test/AtomicTests/atomic_tests.jl +++ b/src/Test/UnitTests/unit_tests.jl @@ -3,10 +3,10 @@ to the full end-to-end tests in contlinear.jl etc =# -const atomictests = Dict{String, Function}() +const unittests = Dict{String, Function}() include("variables.jl") include("objectives.jl") include("constraints.jl") -@moitestset atomic +@moitestset unit diff --git a/src/Test/AtomicTests/variables.jl b/src/Test/UnitTests/variables.jl similarity index 90% rename from src/Test/AtomicTests/variables.jl rename to src/Test/UnitTests/variables.jl index 345058acb0..0a70759e93 100644 --- a/src/Test/AtomicTests/variables.jl +++ b/src/Test/UnitTests/variables.jl @@ -29,7 +29,7 @@ function add_variable(model::MOI.ModelLike, config::TestConfig) v = MOI.addvariable!(model) @test MOI.get(model, MOI.NumberOfVariables()) == 1 end -atomictests["add_variable"] = add_variable +unittests["add_variable"] = add_variable """ This function tests adding multiple variables. @@ -42,7 +42,7 @@ function add_variables(model::MOI.ModelLike, config::TestConfig) v = MOI.addvariables!(model, 2) @test MOI.get(model, MOI.NumberOfVariables()) == 2 end -atomictests["add_variables"] = add_variables +unittests["add_variables"] = add_variables """ This function tests adding, and then deleting, @@ -59,7 +59,7 @@ function delete_variable(model::MOI.ModelLike, config::TestConfig) MOI.delete!(model, v) @test MOI.get(model, MOI.NumberOfVariables()) == 0 end -atomictests["delete_variable"] = delete_variable +unittests["delete_variable"] = delete_variable """ This function tests adding, and then deleting, @@ -85,7 +85,7 @@ function delete_variables(model::MOI.ModelLike, config::TestConfig) @test !MOI.isvalid(model, v[1]) @test MOI.isvalid(model, v[2]) end -atomictests["delete_variables"] = delete_variable +unittests["delete_variables"] = delete_variable """ Test getting variables by name. @@ -103,7 +103,7 @@ function getvariable(model::MOI.ModelLike, config::TestConfig) x = MOI.get(model, MOI.VariableIndex, "x") @test MOI.isvalid(model, x) end -atomictests["getvariable"] = getvariable +unittests["getvariable"] = getvariable """ Test getting and setting varaible names. @@ -121,12 +121,12 @@ function variablenames(model::MOI.ModelLike, config::TestConfig) MOI.set!(model, MOI.VariableName(), x, "x") @test MOI.get(model, MOI.VariableName(), x) == "x" end -atomictests["variablenames"] = variablenames +unittests["variablenames"] = variablenames """ Test the setting of an upper bound """ -function upperbound(model::MOI.ModelLike, config::TestConfig) +function solve_with_upperbound(model::MOI.ModelLike, config::TestConfig) atol, rtol = config.atol, config.rtol MOI.empty!(model) @test MOI.isempty(model) @@ -148,12 +148,12 @@ function upperbound(model::MOI.ModelLike, config::TestConfig) @test MOI.get(model, MOI.ConstraintDual(), c2) ≈ 0.0 atol=atol rtol=rtol end end -atomictests["upperbound"] = upperbound +unittests["solve_with_upperbound"] = solve_with_upperbound """ Test the setting of an lower bound """ -function lowerbound(model::MOI.ModelLike, config::TestConfig) +function solve_with_lowerbound(model::MOI.ModelLike, config::TestConfig) atol, rtol = config.atol, config.rtol MOI.empty!(model) @test MOI.isempty(model) @@ -175,4 +175,4 @@ function lowerbound(model::MOI.ModelLike, config::TestConfig) @test MOI.get(model, MOI.ConstraintDual(), c2) ≈ 0.0 atol=atol rtol=rtol end end -atomictests["lowerbound"] = lowerbound +unittests["solve_with_lowerbound"] = solve_with_lowerbound diff --git a/test/Test/atomic.jl b/test/Test/atomic.jl deleted file mode 100644 index 26b0b6213c..0000000000 --- a/test/Test/atomic.jl +++ /dev/null @@ -1,14 +0,0 @@ -@testset "Atomic Tests" begin - mock = MOIU.MockOptimizer(Model{Float64}()) - config = MOIT.TestConfig() - MOIT.atomictest(mock, config, [ - "constant_obj", - "getvariable", - "getconstraint", - "blank_obj", - "lowerbound", - "upperbound", - "singlevariable_obj", - "variablenames" - ]) -end diff --git a/test/Test/unit.jl b/test/Test/unit.jl new file mode 100644 index 0000000000..eeb6d01ba2 --- /dev/null +++ b/test/Test/unit.jl @@ -0,0 +1,14 @@ +@testset "Unit Tests" begin + mock = MOIU.MockOptimizer(Model{Float64}()) + config = MOIT.TestConfig() + MOIT.unittest(mock, config, [ + "solve_blank_obj", + "solve_constant_obj", + "solve_singlevariable_obj", + "solve_with_lowerbound", + "solve_with_upperbound", + "getconstraint", + "getvariable", + "variablenames" + ]) +end From 218d5bcdcf8eaa740e67cc2d069f8751f626167d Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 1 May 2018 10:39:48 +1200 Subject: [PATCH 09/10] Update filename --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 5449ab9d73..75fbad5c68 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,7 +39,7 @@ end # It tests that the ConstraintPrimal value requested in the tests is consistent with the VariablePrimal @testset "MOI.Test" begin include("Test/config.jl") - include("Test/atomic.jl") + include("Test/unit.jl") include("Test/contlinear.jl") include("Test/contconic.jl") include("Test/contquadratic.jl") From 026c0e37090a8e028e1480b1ff86f5dbba5a05a3 Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 2 May 2018 09:46:12 +1200 Subject: [PATCH 10/10] Update doc strings --- src/Test/UnitTests/variables.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Test/UnitTests/variables.jl b/src/Test/UnitTests/variables.jl index 0a70759e93..297fb56c1e 100644 --- a/src/Test/UnitTests/variables.jl +++ b/src/Test/UnitTests/variables.jl @@ -124,7 +124,8 @@ end unittests["variablenames"] = variablenames """ - Test the setting of an upper bound + Test setting the upper bound of a variable, confirm that it solves correctly, + and if `config.duals=true`, check that the dual is computed correctly. """ function solve_with_upperbound(model::MOI.ModelLike, config::TestConfig) atol, rtol = config.atol, config.rtol @@ -151,7 +152,8 @@ end unittests["solve_with_upperbound"] = solve_with_upperbound """ - Test the setting of an lower bound + Test setting the lower bound of a variable, confirm that it solves correctly, + and if `config.duals=true`, check that the dual is computed correctly. """ function solve_with_lowerbound(model::MOI.ModelLike, config::TestConfig) atol, rtol = config.atol, config.rtol