From a418b688bca723144119895f3667bc988a711cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 16 Apr 2018 10:22:10 +0200 Subject: [PATCH] Add constructvariable! test --- test/variable.jl | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/variable.jl b/test/variable.jl index 382a2b60234..487f2a3d8d9 100644 --- a/test/variable.jl +++ b/test/variable.jl @@ -14,6 +14,21 @@ using JuMP import JuMP.repl using Base.Test +mutable struct MyVariable + haslb::Bool + lowerbound::Number + hasub::Bool + upperbound::Number + hasfix::Bool + fixedvalue::Number + binary::Bool + integer::Bool + name::String + hasstart::Bool + start::Number + test_kw::Int +end + @testset "Variables" begin @testset "constructors" begin # Constructors @@ -311,6 +326,44 @@ end @test JuMP.numvar(m) == 4 end + @testset "Extension of @variable with constructvariable! #1029" begin + JuMP.variabletype(m::Model, ::Type{MyVariable}) = MyVariable + function JuMP.constructvariable!(m::Model, ::Type{MyVariable}, _error::Function, args...; test_kw::Int = 0) + MyVariable(args..., test_kw) + end + m = Model() + @variable(m, 1 <= x <= 2, MyVariable, binary = true, test_kw = 1, start = 3) + @test isa(x, MyVariable) + @test x.haslb + @test x.lowerbound == 1 + @test x.hasub + @test x.upperbound == 2 + @test !x.hasfix + @test isnan(x.fixedvalue) + @test x.binary + @test !x.integer + @test x.name == "x" + @test x.hasstart + @test x.start == 3 + @test x.test_kw == 1 + @variable(m, y[1:3] >= 0, MyVariable, test_kw = 2) + @test isa(y, Vector{MyVariable}) + for i in 1:3 + @test y[i].haslb + @test y[i].lowerbound == 0 + @test !y[i].hasub + @test y[i].upperbound == Inf + @test !y[i].hasfix + @test isnan(y[i].fixedvalue) + @test !y[i].binary + @test !y[i].integer + @test y[i].name == "y[$i]" + @test !y[i].hasstart + @test isnan(y[i].start) + @test y[i].test_kw == 2 + end + end + # TODO decide what to do here # @testset "getstart on sparse array (#889)" begin # m = Model()