From 5498698d6b7bb788b1b5eb300d06f0db484d64a3 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 5 Nov 2024 12:14:58 +1300 Subject: [PATCH 1/2] Improve code coverage of src/print.jl --- test/test_print.jl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/test_print.jl b/test/test_print.jl index 8e758a61097..c2905b7a40b 100644 --- a/test/test_print.jl +++ b/test/test_print.jl @@ -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 @@ -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: 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) == + "`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 From f71bb097e057ba419768eaf2de6dfeedc43eb86f Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 5 Nov 2024 12:51:34 +1300 Subject: [PATCH 2/2] Update --- test/test_print.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_print.jl b/test/test_print.jl index c2905b7a40b..20d2c3ba358 100644 --- a/test/test_print.jl +++ b/test/test_print.jl @@ -1151,7 +1151,7 @@ function test_show_objective_summary() @variable(model, x) @objective(model, Min, x) @test sprint(show_objective_function_summary, model) == - "Objective function type: VariableRef\n" + "Objective function type: JuMP.VariableRef\n" @NLobjective(model, Min, x) @test sprint(show_objective_function_summary, model) == "Objective function type: Nonlinear\n" @@ -1164,7 +1164,7 @@ function test_show_constraints_summary() @constraint(model, x >= 1) @NLconstraint(model, sin(x) == 1) @test sprint(show_constraints_summary, model) == - "`AffExpr`-in-`MathOptInterface.GreaterThan{Float64}`: 1 constraint\nNonlinear: 1 constraint\n" + "`JuMP.AffExpr`-in-`MathOptInterface.GreaterThan{Float64}`: 1 constraint\nNonlinear: 1 constraint\n" return end