Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code coverage of src/print.jl #3867

Merged
merged 2 commits into from
Nov 5, 2024
Merged
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
39 changes: 39 additions & 0 deletions test/test_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ using JuMP
using LinearAlgebra
using Test

include("JuMPExtension.jl")

# Helper function to test IO methods work correctly
function _io_test_show(::MIME"text/plain", obj, exp_str)
@test sprint(show, obj) == exp_str
Expand Down Expand Up @@ -1136,4 +1138,41 @@ function test_small_number_latex()
return
end

function test_print_summary()
model = JuMPExtension.MyModel()
@variable(model, x)
@objective(model, Min, x)
@test occursin("Minimization problem with:", sprint(show, model))
return
end

function test_show_objective_summary()
model = Model()
@variable(model, x)
@objective(model, Min, x)
@test sprint(show_objective_function_summary, model) ==
"Objective function type: JuMP.VariableRef\n"
@NLobjective(model, Min, x)
@test sprint(show_objective_function_summary, model) ==
"Objective function type: Nonlinear\n"
return
end

function test_show_constraints_summary()
model = Model()
@variable(model, x)
@constraint(model, x >= 1)
@NLconstraint(model, sin(x) == 1)
@test sprint(show_constraints_summary, model) ==
"`JuMP.AffExpr`-in-`MathOptInterface.GreaterThan{Float64}`: 1 constraint\nNonlinear: 1 constraint\n"
return
end

function test_show_backend_summary()
model = Model()
@test sprint(show_backend_summary, model) ==
"Model mode: AUTOMATIC\nCachingOptimizer state: NO_OPTIMIZER\nSolver name: No optimizer attached."
return
end

end # TestPrint
Loading