When testing a package I develop, I had an inconsistency in the result of the unit test of one of my functions between the testing framework TestItems.jl used within the VSCode UI and Test.jl.
Here is a code sample for reproducibility purpose
using TestItems using TestItemRunner @run_package_tests # For using ] test @testitem "Test" begin Δt = 1e-6 tf = 7e-2 t = 0.:Δt:tf Ft = zeros(length(t)) tb = 8e-3 duration = 5e-2 tm = (2tb + duration)/2. pos_beg = argmin((t .- tb).^2.) pos_m = argmin((t .- tm).^2.) pos_end = argmin((t .- tb .- duration).^2.) amp = 2/duration Ft[pos_beg:pos_m] = amp*(t[pos_beg:pos_m] .- tb) Ft[pos_m+1:pos_end] = 1. .- amp*(t[pos_m+1:pos_end] .- tm) @test sum(diff(Ft)) == 0. end
When using TestItems.jl within the VSCode UI, the test is successful (I have also checked this assertion in the REPL). However, when using
] test, the test fails and the following message is displayed:
Test: Test Failed at \test\runtests.jl Expression: sum(diff(Ft)) == 0.0 Evaluated: 2.220446049250313e-16 == 0.0
On my machine, 2.220446049250313e-16 is the machine epsilon. Of course, because floating-point arithmetics, some differences can occur between what we expect and what is computed. However, in the present case, it seems that it is not the case, since when I execute
sum(diff(Ft)) in the REPL the result is 0. as expected.
Is it a bug or is it the expected behaviour ?
Thanks for your comments