diff --git a/src/nlp_expr.jl b/src/nlp_expr.jl index 84b4c6f2bb3..373d63611a6 100644 --- a/src/nlp_expr.jl +++ b/src/nlp_expr.jl @@ -724,7 +724,7 @@ function Base.convert( if !iszero(x.constant) || isempty(args) push!(args, x.constant) end - if length(args) == 1 + if length(args) == 1 && args[1] isa GenericNonlinearExpr{V} return args[1] end return GenericNonlinearExpr{V}(:+, args) @@ -752,7 +752,7 @@ function Base.convert( if !iszero(x.aff.constant) || isempty(args) push!(args, x.aff.constant) end - if length(args) == 1 + if length(args) == 1 && args[1] isa GenericNonlinearExpr{V} return args[1] end return GenericNonlinearExpr{V}(:+, args) diff --git a/test/Kokako.jl b/test/Kokako.jl index d780cb5e433..ffbd349b7e7 100644 --- a/test/Kokako.jl +++ b/test/Kokako.jl @@ -131,8 +131,10 @@ end function include_modules_to_test(dir::String, files::Vector{String}) modules = Pair{String,Module}[] for file in files - @info "Loading $file" - push!(modules, file => Base.include(Main, joinpath(dir, file))) + if isfile(joinpath(dir, file)) + @info "Loading $file" + push!(modules, file => Base.include(Main, joinpath(dir, file))) + end end return modules end diff --git a/test/test_nlp_expr.jl b/test/test_nlp_expr.jl index 747ce29d344..12132407b54 100644 --- a/test/test_nlp_expr.jl +++ b/test/test_nlp_expr.jl @@ -233,8 +233,8 @@ function test_extension_aff_expr_convert( model = ModelType() @variable(model, x) _to_string(x) = string(convert(GenericNonlinearExpr{VariableRefType}, x)) - @test _to_string(AffExpr(0.0)) == "0.0" - @test _to_string(AffExpr(1.0)) == "1.0" + @test _to_string(AffExpr(0.0)) == "+(0.0)" + @test _to_string(AffExpr(1.0)) == "+(1.0)" @test _to_string(x + 1) == "x + 1.0" @test _to_string(2x + 1) == "(2.0 * x) + 1.0" @test _to_string(2x) == "2.0 * x" @@ -248,8 +248,8 @@ function test_extension_quad_expr_convert( model = ModelType() @variable(model, x) _to_string(x) = string(convert(GenericNonlinearExpr{VariableRefType}, x)) - @test _to_string(QuadExpr(AffExpr(0.0))) == "0.0" - @test _to_string(QuadExpr(AffExpr(1.0))) == "1.0" + @test _to_string(QuadExpr(AffExpr(0.0))) == "+(0.0)" + @test _to_string(QuadExpr(AffExpr(1.0))) == "+(1.0)" @test _to_string(x^2 + 1) == "(x * x) + 1.0" @test _to_string(2x^2 + 1) == "(2.0 * x * x) + 1.0" @test _to_string(2x^2) == "2.0 * x * x" @@ -1010,4 +1010,13 @@ function test_printing_truncation() return end +function test_convert_vector_aff_expr() + model = Model() + @variable(model, x) + @test [sin(x), x] isa Vector{NonlinearExpr} + @test [sin(x), x + 1] isa Vector{NonlinearExpr} + @test [sin(x), convert(AffExpr, x)] isa Vector{NonlinearExpr} + return +end + end # module