What's the difference between @assert and @test?

817 views
Skip to first unread message

Ismael VC

unread,
Mar 25, 2015, 1:26:30 PM3/25/15
to julia...@googlegroups.com
Hello guys!

I just had someone ask me this question and I didn't know what to answer him, example:

julia> using Base.Test

julia> @test 1 == 1

julia> @test 1 == 3
ERROR: test failed: 1 == 3
 in error at error.jl:21 (repeats 2 times)

julia> @assert 1 == 1

julia> @assert 1 == 3
ERROR: assertion failed: 1 == 3
 in error at error.jl:21 (repeats 2 times)

I fail to see the difference, besides that `@test` conveys the idea of "testing". 

Even the error message is even the same:  `in error at error.jl:21 (repeats 2 times)`

Thanks!

Ivar Nesje

unread,
Mar 25, 2015, 4:22:28 PM3/25/15
to julia...@googlegroups.com
Good question!

In 0.4 the printing for @test has been improved quite significantly to display the values of variables.

julia> a,b = 1,2

julia> @test a==b 
ERROR: test failed: (1 == 2)
in expression: a == b 
in error at error.jl:19
in default_handler at test.jl:27
in do_test at test.jl:50

julia> @assert a==b
ERROR: AssertionError: a == b


There is some discussion in #10614 about means to disable assertions, so there is a conceptual difference in that assertions is used inside a program to test for invalid inputs to functions, but tests are usually runned externally to see that functions work correctly for different outputs.

Regards
Ivar

Ismael VC

unread,
Mar 26, 2015, 11:13:14 AM3/26/15
to julia...@googlegroups.com
Thank you very much Ivar, that makes sense.
Reply all
Reply to author
Forward
0 new messages