Skip to content

Commit

Permalink
Add constructvariable! test
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Apr 16, 2018
1 parent 326b62b commit a418b68
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/variable.jl
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a418b68

Please sign in to comment.