@test evaluates one expression as an individual test assertion. Place assertions inside @testset blocks to verify package behavior and identify which checks pass or fail. section 16.5
Checking trigonometric functions
using Test @testset "cosine tests" begin @test cosine(π) ≈ -1.0 @test cosine(0) ≈ 1.0 for x in 0:0.1:2π @test isapprox(cos(x), cosine(x), atol=0.05) end end Each loop iteration creates another assertion, while ≈ and isapprox allow approximate numeric comparisons. Test output reports passed and failed assertions, helping reveal regressions after a code change. section 16.5
Listing 16.11 ToyGeometry/test/trigtests.jl
@testset "cosine tests" begin
@test cosine(π) ≈ -1.0
@test cosine(0) ≈ 1.0
for x in 0:0.1:2π #1
@test isapprox(cos(x), cosine(x), atol=0.05) #1
end #1
end
@testset "sine tests" begin
@test sine(0) ≈ 0.0
@test sine(π/2) ≈ 1.0
for x in 0:0.1:2π
@test isapprox(sin(x), sine(x), atol=0.05)
end
end
Browse the complete trigonometric test file, including cosine and sine test sets and their repeated @test assertions. section 16.5
