Testing & Documentation
Package tests live in test/runtests.jl; run with pkg> test.
22.1 Test (stdlib)
Package tests live in test/runtests.jl; run with pkg> test. Extra tools: ReTest.jl, TestItemRunner.jl (@testitem, VS Code integration), Aqua.jl (package quality checks), JET.jl (static analysis), SafeTestsets.jl.
using Test
@test 1 + 1 == 2
@test π ≈ 3.14159 atol=1e-5
@test_throws DomainError sqrt(-1)
@test_broken 1 == 2 # known failure
@test_logs (:warn, "careful") @warn "careful"
@test_nowarn f()
@inferred sum([1, 2]) # checks type inference
@testset "Geometry" begin
@test area(Circle(1)) ≈ π
@testset "Edge cases" begin
@test area(Circle(0)) == 0
@test_throws ArgumentError Circle(-1)
end
end
@testset "table $x" for x in 1:3 # parameterized test sets
@test x^2 >= x
end22.2 Docstrings
julia> area(Circle(1.0)) 3.141592653589793 Access with ?area in the REPL. Documenter.jl builds HTML documentation sites and runs jldoctest blocks; DocumenterVitepress.jl, Literate.jl (turn scripts into docs/notebooks).
"""
area(c::Circle) -> Float64
Compute the area of circle `c`.
# Arguments
- `c::Circle`: a circle with radius `c.r ≥ 0`.
# ExamplesSee also [`perimeter`](@ref).
"""
area(c::Circle) = π * c.r^2🧪 Part II Exercises
Create a 5×5 matrix of random integers; compute row/column sums, its transpose, and extract the anti-diagonal.
Implement matrix multiplication with three nested loops; compare results and speed with *.
Solve a 3×3 linear system with \ and verify the residual norm.
Define an abstract Shape type and concrete Circle, Rectangle, Triangle structs; implement area and perimeter via dispatch.
Write a parametric Interval{T} struct with an inner constructor and +, *, in, and show methods.
Implement the iteration interface for a Fibonacci(n) type.
Implement a custom AbstractVector subtype CircularVector whose indices wrap around.
Create a module Stats exporting mymean, myvar; put it in a project environment with a Project.toml.
Read a CSV-like text file manually (eachline, split, parse), handling malformed lines with try/catch.
Write a @testset suite covering exercises 4–7, including @test_throws and @inferred.