More modular tests
pnkraemer opened this issue · comments
Would be great to have tests for
- different element types
- static arrays (and non-static arrays)
without manually defining a bunch of matrices.
Would also be great to have some easier-to-access test functions (macros?).
Many tests seem to follow a clear pattern:
- Test that
op
is (approximately) invariant w.r.t.Matrix()
: e.g.@test det(S) \approx det(Matrix(S))
,@test size(S) \approx size(Matrix(S))
,@test S \ X ≈ Matrix(S) \ X
- Test that
op
(approximately) commutes withMatrix()
: e.g.@test inv(Matrix(S)) == Matrix(inv(S))
This could be realized with a bunch of functions
function test_op_invariant(op, S)
@test op(S) == op(Matrix(S))
end
function test_op_invariant_approx(op, S, abstol=0.1, reltol=0.1) # ignore the values
@test op(S) \approx op(Matrix(S)) abstol=abstol reltol=reltol
end
function test_op_commutes(op, S)
@test Matrix(op(S)) == op(Matrix(S))
end
# etc.
It seems possible to implement this with a macro; see https://github.com/JuliaLang/julia/blob/bf534986350a991e4a1b29126de0342ffd76205e/stdlib/Test/src/Test.jl#L654-L674 for a starting point.