Skip to content

Commit 9e33fcd

Browse files
committed
Fix coverage
1 parent 82438a1 commit 9e33fcd

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

test/test_nlp_expr.jl

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,21 +1384,33 @@ end
13841384
function test_scalar_nonlinear_moi_function()
13851385
model = Model()
13861386
@variable(model, x)
1387-
y = atan(x, 2)
1388-
y_moi = MOI.ScalarNonlinearFunction(:atan, Any[index(x), 2])
1389-
z = cos(y)
1390-
z_moi = MOI.ScalarNonlinearFunction(:cos, Any[y_moi])
1391-
@test isapprox(moi_function(y), y_moi)
1387+
y1 = atan(x, 2)
1388+
y1_moi = MOI.ScalarNonlinearFunction(:atan, Any[index(x), 2])
1389+
y2 = y1 + y1
1390+
y2_moi = MOI.ScalarNonlinearFunction(:+, Any[y1_moi, y1_moi])
1391+
y3 = exp(y2)
1392+
y3_moi = MOI.ScalarNonlinearFunction(:exp, Any[y2_moi])
1393+
# Test y1
1394+
@test isapprox(moi_function(y1), y1_moi)
13921395
@test isempty(model.subexpressions)
1393-
@test isapprox(moi_function(model, y), y_moi)
1396+
@test isapprox(moi_function(model, y1), y1_moi)
13941397
@test length(model.subexpressions) == 1
1395-
@test isapprox(model.subexpressions[objectid(y)], y_moi)
1396-
@test isapprox(moi_function(z), z_moi)
1398+
@test isapprox(model.subexpressions[objectid(y1)], y1_moi)
1399+
# Test y2
1400+
@test isapprox(moi_function(y2), y2_moi)
13971401
@test length(model.subexpressions) == 1
1398-
@test isapprox(moi_function(model, z), z_moi)
1402+
@test isapprox(moi_function(model, y2), y2_moi)
13991403
@test length(model.subexpressions) == 2
1400-
@test isapprox(model.subexpressions[objectid(y)], y_moi)
1401-
@test isapprox(model.subexpressions[objectid(z)], z_moi)
1404+
@test isapprox(model.subexpressions[objectid(y1)], y1_moi)
1405+
@test isapprox(model.subexpressions[objectid(y2)], y2_moi)
1406+
# Test y3
1407+
@test isapprox(moi_function(y3), y3_moi)
1408+
@test length(model.subexpressions) == 2
1409+
@test isapprox(moi_function(model, y3), y3_moi)
1410+
@test length(model.subexpressions) == 3
1411+
@test isapprox(model.subexpressions[objectid(y1)], y1_moi)
1412+
@test isapprox(model.subexpressions[objectid(y2)], y2_moi)
1413+
@test isapprox(model.subexpressions[objectid(y3)], y3_moi)
14021414
return
14031415
end
14041416

0 commit comments

Comments
 (0)