@@ -175,6 +175,7 @@ const MOIU = MOI.Utilities
175175 @testset " Affine" begin
176176 @testset " zero" begin
177177 f = @inferred MOIU. zero (MOI. ScalarAffineFunction{Float64})
178+ @test iszero (f)
178179 @test MOIU. isapprox_zero (f, 1e-16 )
179180 end
180181 @testset " promote_operation" begin
@@ -187,17 +188,24 @@ const MOIU = MOI.Utilities
187188 MOI. ScalarAffineFunction{Int},
188189 MOI. ScalarAffineFunction{Int}) == MOI. ScalarAffineFunction{Int}
189190 end
190- @testset " Comparison tolerance " begin
191+ @testset " Comparison" begin
191192 @test MOIU. operate (+ , Float64, MOI. SingleVariable (x),
192193 MOI. SingleVariable (z)) + 1.0 ≈
193194 MOI. ScalarAffineFunction (MOI. ScalarAffineTerm .([1 , 1e-7 , 1 ], [x, y, z]), 1.0 ) atol= 1e-6
194195 f1 = MOI. ScalarAffineFunction ([MOI. ScalarAffineTerm (1.0 , x), MOI. ScalarAffineTerm (1e-7 , y)], 1.0 )
195196 f2 = MOI. ScalarAffineFunction ([MOI. ScalarAffineTerm (1.0 , x)], 1.0 )
196197 @test f1 ≈ f2 atol= 1e-6
197198 fdiff = f1 - f2
198- MOIU. canonicalize! (fdiff)
199- @test ! MOIU. isapprox_zero (fdiff, 1e-8 )
200- @test MOIU. isapprox_zero (fdiff, 1e-6 )
199+ @testset " With iszero" begin
200+ @test ! iszero (fdiff)
201+ @test iszero (f1 - f1)
202+ @test iszero (f2 - f2)
203+ end
204+ @testset " With tolerance" begin
205+ MOIU. canonicalize! (fdiff)
206+ @test ! MOIU. isapprox_zero (fdiff, 1e-8 )
207+ @test MOIU. isapprox_zero (fdiff, 1e-6 )
208+ end
201209 end
202210 @testset " canonical" begin
203211 f = MOIU. canonical (MOI. ScalarAffineFunction (MOI. ScalarAffineTerm .([2 , 1 , 3 , - 2 , - 3 ], [y, x, z, x, z]), 5 ))
@@ -290,14 +298,21 @@ const MOIU = MOI.Utilities
290298 f = 7 + 3 fx + 1 fx * fx + 2 fy * fy + 3 fx * fy
291299 MOIU. canonicalize! (f)
292300 @test MOI. output_dimension (f) == 1
293- @testset " isapprox_zero" begin
294- @test ! MOIU. isapprox_zero (f, 1e-8 )
295- # Test isapprox_zero with zero terms
296- @test MOIU. isapprox_zero (0 * f, 1e-8 )
297- g = 1.0 fx * fy - (1 + 1e-6 ) * fy * fx
298- MOIU. canonicalize! (g)
299- @test MOIU. isapprox_zero (g, 1e-5 )
300- @test ! MOIU. isapprox_zero (g, 1e-7 )
301+ @testset " Comparison" begin
302+ @testset " With iszero" begin
303+ @test ! iszero (f)
304+ @test iszero (0 * f)
305+ @test iszero (f - f)
306+ end
307+ @testset " With tolerance" begin
308+ @test ! MOIU. isapprox_zero (f, 1e-8 )
309+ # Test isapprox_zero with zero terms
310+ @test MOIU. isapprox_zero (0 * f, 1e-8 )
311+ g = 1.0 fx * fy - (1 + 1e-6 ) * fy * fx
312+ MOIU. canonicalize! (g)
313+ @test MOIU. isapprox_zero (g, 1e-5 )
314+ @test ! MOIU. isapprox_zero (g, 1e-7 )
315+ end
301316 end
302317 @testset " convert" begin
303318 @test_throws InexactError convert (MOI. SingleVariable, f)
0 commit comments