Skip to content

Commit b60aa48

Browse files
authored
Make tests modular (#386)
1 parent 64339dc commit b60aa48

12 files changed

+73
-17
lines changed

test/test_blockarrayinterface.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using BlockArrays, LinearAlgebra, FillArrays, Test
1+
module TestBlockArrayInterface
2+
3+
using BlockArrays, LinearAlgebra, FillArrays, Test, ArrayLayouts
24

35
# avoid fast-paths for view
46
bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
@@ -51,7 +53,7 @@ end
5153
@test H[Block(2, 3)] == A[2:3, 4:6]
5254
@test H[Block(3, 2)] == A[2:3, 4:6]'
5355

54-
@test sprint(show, "text/plain", UpperTriangular(A)) == "10×10 UpperTriangular{ComplexF64, PseudoBlockMatrix{ComplexF64, Matrix{ComplexF64}, $(typeof(axes(A)))}} with indices 1:1:10×1:1:10:\n 1.0+0.0im │ 11.0+0.0im 21.0+0.0im │ 31.0+0.0im 41.0+0.0im 51.0+0.0im │ 61.0+0.0im 71.0+0.0im 81.0+0.0im 91.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ 12.0+0.0im 22.0+0.0im │ 32.0+0.0im 42.0+0.0im 52.0+0.0im │ 62.0+0.0im 72.0+0.0im 82.0+0.0im 92.0+0.0im\n ⋅ │ ⋅ 23.0+0.0im │ 33.0+0.0im 43.0+0.0im 53.0+0.0im │ 63.0+0.0im 73.0+0.0im 83.0+0.0im 93.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ ⋅ ⋅ │ 34.0+0.0im 44.0+0.0im 54.0+0.0im │ 64.0+0.0im 74.0+0.0im 84.0+0.0im 94.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ 45.0+0.0im 55.0+0.0im │ 65.0+0.0im 75.0+0.0im 85.0+0.0im 95.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ 56.0+0.0im │ 66.0+0.0im 76.0+0.0im 86.0+0.0im 96.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ 67.0+0.0im 77.0+0.0im 87.0+0.0im 97.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ 78.0+0.0im 88.0+0.0im 98.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ ⋅ 89.0+0.0im 99.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ ⋅ ⋅ 100.0+0.0im"
56+
@test sprint(show, "text/plain", UpperTriangular(A)) == "10×10 $UpperTriangular{ComplexF64, $(PseudoBlockMatrix{ComplexF64, Matrix{ComplexF64}, typeof(axes(A))})} with indices 1:1:10×1:1:10:\n 1.0+0.0im │ 11.0+0.0im 21.0+0.0im │ 31.0+0.0im 41.0+0.0im 51.0+0.0im │ 61.0+0.0im 71.0+0.0im 81.0+0.0im 91.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ 12.0+0.0im 22.0+0.0im │ 32.0+0.0im 42.0+0.0im 52.0+0.0im │ 62.0+0.0im 72.0+0.0im 82.0+0.0im 92.0+0.0im\n ⋅ │ ⋅ 23.0+0.0im │ 33.0+0.0im 43.0+0.0im 53.0+0.0im │ 63.0+0.0im 73.0+0.0im 83.0+0.0im 93.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ ⋅ ⋅ │ 34.0+0.0im 44.0+0.0im 54.0+0.0im │ 64.0+0.0im 74.0+0.0im 84.0+0.0im 94.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ 45.0+0.0im 55.0+0.0im │ 65.0+0.0im 75.0+0.0im 85.0+0.0im 95.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ 56.0+0.0im │ 66.0+0.0im 76.0+0.0im 86.0+0.0im 96.0+0.0im\n ───────────┼──────────────────────────┼──────────────────────────────────────┼─────────────────────────────────────────────────\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ 67.0+0.0im 77.0+0.0im 87.0+0.0im 97.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ 78.0+0.0im 88.0+0.0im 98.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ ⋅ 89.0+0.0im 99.0+0.0im\n ⋅ │ ⋅ ⋅ │ ⋅ ⋅ ⋅ │ ⋅ ⋅ ⋅ 100.0+0.0im"
5557

5658
V = view(A, Block.(1:2), Block.(1:2))
5759
@test blockisequal(axes(Symmetric(V)), axes(view(A, Block.(1:2), Block.(1:2))))
@@ -130,7 +132,7 @@ end
130132
@test_throws BlockBoundsError A[Block(1, 3)]
131133
@test A == [1 2 0 0; 0 0 1 2]
132134
@test BlockArray(A) == A
133-
@test sprint(show, "text/plain", A) == "2×2-blocked 2×4 BlockMatrix{$Int, Diagonal{Matrix{$Int}, Vector{Matrix{$Int}}}, Tuple{BlockedUnitRange{Vector{$Int}}, BlockedUnitRange{Vector{$Int}}}}:\n 1 2 │ ⋅ ⋅\n ──────┼──────\n ⋅ ⋅ │ 1 2"
135+
@test sprint(show, "text/plain", A) == "2×2-blocked 2×4 $(BlockMatrix{Int, Diagonal{Matrix{Int}, Vector{Matrix{Int}}}, Tuple{BlockedUnitRange{Vector{Int}}, BlockedUnitRange{Vector{Int}}}}):\n 1 2 │ ⋅ ⋅\n ──────┼──────\n ⋅ ⋅ │ 1 2"
134136

135137
N = 3
136138
D = Diagonal(mortar(Fill.(-(0:N) - (0:N) .^ 2, 1:2:2N+1)))
@@ -187,9 +189,9 @@ end
187189

188190
U = UpperTriangular(Ones((blockedrange([1, 2]), blockedrange([2, 1]))))
189191

190-
@test sprint(show, "text/plain", A) == "5-element Fill{$Int, 1, Tuple{BlockedUnitRange{Vector{$Int}}}} with indices 1:1:5, with entries equal to 2"
191-
@test sprint(show, "text/plain", B) == "3×3 Diagonal{Float64, Ones{Float64, 1, Tuple{BlockedUnitRange{Vector{$Int}}}}} with indices 1:1:3×1:1:3"
192-
@test sprint(show, "text/plain", U) == "3×3 UpperTriangular{Float64, Ones{Float64, 2, Tuple{BlockedUnitRange{Vector{$Int}}, BlockedUnitRange{Vector{$Int}}}}} with indices 1:1:3×1:1:3:\n 1.0 1.0 │ 1.0\n ──────────┼─────\n ⋅ 1.0 │ 1.0\n ⋅ ⋅ │ 1.0"
192+
@test sprint(show, "text/plain", A) == "5-element $(Fill{Int, 1, Tuple{BlockedUnitRange{Vector{Int}}}}) with indices 1:1:5, with entries equal to 2"
193+
@test sprint(show, "text/plain", B) == "3×3 $(Diagonal{Float64, Ones{Float64, 1, Tuple{BlockedUnitRange{Vector{Int}}}}}) with indices 1:1:3×1:1:3"
194+
@test sprint(show, "text/plain", U) == "3×3 $(UpperTriangular{Float64, Ones{Float64, 2, Tuple{BlockedUnitRange{Vector{Int}}, BlockedUnitRange{Vector{Int}}}}}) with indices 1:1:3×1:1:3:\n 1.0 1.0 │ 1.0\n ──────────┼─────\n ⋅ 1.0 │ 1.0\n ⋅ ⋅ │ 1.0"
193195

194196
@testset "views" begin
195197
# This in theory can be dropped because `view` returns the block, but we keep in case needed
@@ -200,3 +202,5 @@ end
200202
@test FillArrays.getindex_value(bview(f, Block(2))) == 2
201203
end
202204
end
205+
206+
end # module

test/test_blockarrays.jl

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module TestBlockArrays
2+
13
using SparseArrays, BlockArrays, FillArrays, LinearAlgebra, Test, OffsetArrays
24
import BlockArrays: _BlockArray
35

@@ -545,24 +547,30 @@ end
545547
end
546548

547549
@testset "replstring" begin
548-
@test sprint(show, "text/plain", BlockArray(collect(1:4), [1,3])) == "2-blocked 4-element BlockVector{$Int}:\n 1\n\n 2\n 3\n 4"
549-
@test sprint(show, "text/plain", PseudoBlockArray(collect(1:4), [1,3])) == "2-blocked 4-element PseudoBlockVector{$Int}:\n 1\n\n 2\n 3\n 4"
550-
@test sprint(show, "text/plain", BlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])) == "2×2-blocked 4×4 BlockMatrix{$Int}:\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
551-
@test sprint(show, "text/plain", PseudoBlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])) == "2×2-blocked 4×4 PseudoBlockMatrix{$Int}:\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
552-
@test sprint(show, "text/plain", BlockArray(collect(reshape(1:8, 2, 2, 2)), [1,1], [1,1], [1,1])) == "2×2×2-blocked 2×2×2 BlockArray{$Int, 3}:\n[:, :, 1] =\n 1 3\n 2 4\n\n[:, :, 2] =\n 5 7\n 6 8"
553-
@test sprint(show, "text/plain", PseudoBlockArray(collect(reshape(1:8, 2, 2, 2)), [1,1], [1,1], [1,1])) == "2×2×2-blocked 2×2×2 PseudoBlockArray{$Int, 3}:\n[:, :, 1] =\n 1 3\n 2 4\n\n[:, :, 2] =\n 5 7\n 6 8"
550+
A = BlockArray(collect(1:4), [1,3])
551+
@test sprint(show, "text/plain", A) == "$(summary(A)):\n 1\n\n 2\n 3\n 4"
552+
A = PseudoBlockArray(collect(1:4), [1,3])
553+
@test sprint(show, "text/plain", A) == "$(summary(A)):\n 1\n\n 2\n 3\n 4"
554+
A = BlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])
555+
@test sprint(show, "text/plain", A) == "$(summary(A)):\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
556+
A = PseudoBlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])
557+
@test sprint(show, "text/plain", A) == "$(summary(A)):\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
558+
A = BlockArray(collect(reshape(1:8, 2, 2, 2)), [1,1], [1,1], [1,1])
559+
@test sprint(show, "text/plain", A) == "$(summary(A)):\n[:, :, 1] =\n 1 3\n 2 4\n\n[:, :, 2] =\n 5 7\n 6 8"
560+
A = PseudoBlockArray(collect(reshape(1:8, 2, 2, 2)), [1,1], [1,1], [1,1])
561+
@test sprint(show, "text/plain", A) == "$(summary(A)):\n[:, :, 1] =\n 1 3\n 2 4\n\n[:, :, 2] =\n 5 7\n 6 8"
554562
design = zeros(Int16,6,9);
555563
A = BlockArray(design,[6],[4,5])
556-
@test sprint(show, "text/plain", A) == "1×2-blocked 6×9 BlockMatrix{Int16}:\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
564+
@test sprint(show, "text/plain", A) == "$(summary(A)):\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
557565
A = PseudoBlockArray(design,[6],[4,5])
558-
@test sprint(show, "text/plain", A) == "1×2-blocked 6×9 PseudoBlockMatrix{Int16}:\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
566+
@test sprint(show, "text/plain", A) == "$(summary(A)):\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
559567
D = PseudoBlockArray(Diagonal(1:3), [1,2], [2,1])
560-
@test sprint(show, "text/plain", D) == "2×2-blocked 3×3 $(PseudoBlockMatrix{Int, Diagonal{Int, UnitRange{Int}}, Tuple{BlockedUnitRange{Vector{Int}}, BlockedUnitRange{Vector{Int}}}}):\n 1 ⋅ │ ⋅\n ──────┼───\n ⋅ 2 │ ⋅\n ⋅ ⋅ │ 3"
568+
@test sprint(show, "text/plain", D) == "$(summary(D)):\n 1 ⋅ │ ⋅\n ──────┼───\n ⋅ 2 │ ⋅\n ⋅ ⋅ │ 3"
561569

562570
a = BlockArray{Int}(undef_blocks, [1,2])
563-
@test sprint(show, "text/plain", a) == "2-blocked 3-element BlockVector{Int64}:\n #undef\n ──────\n #undef\n #undef"
571+
@test sprint(show, "text/plain", a) == "$(summary(a)):\n #undef\n ──────\n #undef\n #undef"
564572
B = BlockArray{Int}(undef_blocks, [1,2], [1,1])
565-
@test sprint(show, "text/plain", B) == "2×2-blocked 3×2 BlockMatrix{Int64}:\n #undef │ #undef\n ────────┼────────\n #undef │ #undef\n #undef │ #undef"
573+
@test sprint(show, "text/plain", B) == "$(summary(B)):\n #undef │ #undef\n ────────┼────────\n #undef │ #undef\n #undef │ #undef"
566574
end
567575

568576
@testset "AbstractVector{Int} blocks" begin
@@ -781,3 +789,5 @@ end
781789
@test size(a[:,1]) == (8,)
782790
end
783791
end
792+
793+
end # module

test/test_blockbroadcast.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module TestBlockBroadcast
2+
13
using BlockArrays, FillArrays, Test
24
import BlockArrays: SubBlockIterator, BlockIndexRange, Diagonal
35

@@ -291,3 +293,5 @@ import BlockArrays: SubBlockIterator, BlockIndexRange, Diagonal
291293
@test w == reverse(v)
292294
end
293295
end
296+
297+
end # module

test/test_blockcholesky.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module TestBlockCholesky
2+
13
using BlockArrays, Test, LinearAlgebra, Random
24

35

@@ -60,3 +62,4 @@ Random.seed!(0)
6062
@test cholesky(E8; check=false).info == 8
6163
end
6264

65+
end # module

test/test_blockdeque.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module TestBlockDeque
2+
13
using BlockArrays, Test
24

35
@testset "block dequeue" begin
@@ -192,3 +194,5 @@ using BlockArrays, Test
192194
end
193195
end
194196
end
197+
198+
end # module

test/test_blockindices.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module TestBlockIndices
2+
13
using BlockArrays, FillArrays, Test, StaticArrays, ArrayLayouts
24
using OffsetArrays
35
import BlockArrays: BlockIndex, BlockIndexRange, BlockSlice
@@ -516,3 +518,5 @@ end
516518
@test !blockisequal(axB, axv)
517519
@test !blockisequal(axv, axB)
518520
end
521+
522+
end # module

test/test_blocklinalg.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
module TestBlockLinalg
2+
13
using BlockArrays, ArrayLayouts, LinearAlgebra, Test
24
import BlockArrays: BlockLayout
35
import ArrayLayouts: DenseRowMajor, ColumnMajor, StridedLayout
46

7+
bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
8+
59
@testset "Linear Algebra" begin
610
@testset "BlockArray scalar * matrix" begin
711
A = BlockArray{Float64}(randn(6,6), fill(2,3), 1:3)
@@ -248,3 +252,5 @@ import ArrayLayouts: DenseRowMajor, ColumnMajor, StridedLayout
248252
@test mul!(view(copy(C),:,1:3), Ã, B̃, 1, 2) A*B + 2C
249253
end
250254
end
255+
256+
end # module

test/test_blockproduct.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module TestBlockProduct
2+
13
using BlockArrays, Test
24

35
@testset "block product" begin
@@ -143,3 +145,5 @@ using BlockArrays, Test
143145
@test_throws MethodError BlockKron(a)
144146
end
145147
end
148+
149+
end # module

test/test_blockrange.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module TestBlockRange
2+
13
using BlockArrays, Test
24

35
@testset "block range" begin
@@ -99,3 +101,5 @@ end
99101
@test size(bi) == (2,2)
100102
end
101103
end
104+
105+
end # module

test/test_blockreduce.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module TestBlockReduce
2+
13
using BlockArrays, Test
24

35
@testset "foldl" begin
@@ -25,3 +27,5 @@ end
2527
@test blockisequal(axes(A,2), axes(sum(A; dims=1),2))
2628
@test blockisequal(axes(A,1), axes(sum(A; dims=2),1))
2729
end
30+
31+
end # module

0 commit comments

Comments
 (0)