From aefd780bf72c87121bafab94ef89f4a07bee95dd Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 28 Apr 2026 16:23:10 -0500 Subject: [PATCH] Improve test coverage to 100% Add tests for `size(A, d)`, `length`, `similar`, the k-rank output branch in `mul!(C::FactoredMatrix, A::FactoredMatrix, B::FactoredMatrix)`, and the DimensionMismatch error path. Co-Authored-By: Claude Sonnet 4.6 --- test/runtests.jl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 40b921b..43d6217 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -76,6 +76,12 @@ end @test D' * M ≈ D' * Mf @test M * E' ≈ Mf * E' @test E * M' ≈ E * Mf' + @test size(Mf, 1) == 15 + @test size(Mf, 2) == 10 + @test size(Mf, 3) == 1 + @test length(Mf) == 150 + @test similar(Mf, (3, 4)) isa Matrix{eltype(U)} + @test similar(Mf, Int, (3, 4)) isa Matrix{Int} @test !any(isnan, Mf) @test !any(isinf, Mf) V1, U1 = [1; 1;;], [1 -1] @@ -203,6 +209,21 @@ end check_fmfm_fm_alloc(Mf, Mf_A, ws3x3, Cf15x8) end + # mul! FM×FM→FM: elseif branch (k-rank output) and DimensionMismatch + let + Ua = myrand(T, 15, 2); Va = myrand(T, 2, 10) + Ub = myrand(T, 10, 3); Vb = myrand(T, 3, 8) + Af = FactoredMatrix(Ua, Va); Bf = FactoredMatrix(Ub, Vb) + expected = (Ua * Va) * (Ub * Vb) + # k-rank output (C rank = k = 2) + Ck = FactoredMatrix(Matrix{T}(undef, 15, 2), Matrix{T}(undef, 2, 8)) + mul!(Ck, Af, Bf) + @test Array(Ck) ≈ expected + # wrong rank → DimensionMismatch + Cbad = FactoredMatrix(Matrix{T}(undef, 15, 4), Matrix{T}(undef, 4, 8)) + @test_throws DimensionMismatch("C's factorization size doesn't match the result of A*B") mul!(Cbad, Af, Bf) + end + # mul! vector (with and without cache) let b = vec(myrand(T, 10, 1))