Testing

The @assert macro actually exists in the standard library. The standard version also allows you to give your own error message, which is printed after ERROR: assertion failed.

The Test library contains some useful macros to compare the numbers:

using Test 
@test 1 == 3 

This returns the following:

Test Failed at REPL[5]:1  Expression: 1 == 3    Evaluated: 1 == 3ERROR: There was an error during testing.

@test with the operator tests whether the two numbers are approximately equal. @test 1 ≈ 1.1 returns Test Failed because they are not equal within the machine tolerance. However, you can give the interval as the last argument within which they should be equal: @test 1 ≈ 1.1 atol=0.2, which returns Test Passed, so 1 and 1.1 are within ...

Get Julia 1.0 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.