Skip to content

Commit dbd4dff

Browse files
committed
Add bounds-check tests
1 parent 2df36b9 commit dbd4dff

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

test/bidiag.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,9 @@ end
11841184
B[LinearAlgebra.BandIndex(-1,1)] = 2
11851185
@test B[2,1] == 2
11861186
@test_throws "cannot set entry $((3,1)) off the lower bidiagonal band" B[LinearAlgebra.BandIndex(-2,1)] = 2
1187+
1188+
@test_throws BoundsError B[LinearAlgebra.BandIndex(size(B,1),1)]
1189+
@test_throws BoundsError B[LinearAlgebra.BandIndex(0,size(B,1)+1)]
11871190
end
11881191

11891192
end # module TestBidiagonal

test/diagonal.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,9 @@ end
14851485
D = Diagonal(zeros(2))
14861486
D[LinearAlgebra.BandIndex(0,2)] = 1
14871487
@test D[2,2] == 1
1488-
@test_throws "cannot set off-diagonal entry" D[LinearAlgebra.BandIndex(1,1)] = 1
1488+
@test_throws "cannot set off-diagonal entry $((1,2))" D[LinearAlgebra.BandIndex(1,1)] = 1
1489+
@test_throws BoundsError D[LinearAlgebra.BandIndex(size(D,1),1)]
1490+
@test_throws BoundsError D[LinearAlgebra.BandIndex(0,size(D,1)+1)]
14891491
end
14901492

14911493
end # module TestDiagonal

test/tridiag.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,12 +1173,16 @@ end
11731173

11741174
@test_throws "cannot set entry $((1,3)) off the tridiagonal band" T[LinearAlgebra.BandIndex(2,1)] = 1
11751175
@test_throws "cannot set entry $((3,1)) off the tridiagonal band" T[LinearAlgebra.BandIndex(-2,1)] = 1
1176+
@test_throws BoundsError T[LinearAlgebra.BandIndex(size(T,1),1)]
1177+
@test_throws BoundsError T[LinearAlgebra.BandIndex(0,size(T,1)+1)]
11761178

11771179
S = SymTridiagonal(zeros(4), zeros(3))
11781180
S[LinearAlgebra.BandIndex(0,2)] = 1
11791181
@test S[2,2] == 1
11801182

11811183
@test_throws "cannot set off-diagonal entry $((1,3))" S[LinearAlgebra.BandIndex(2,1)] = 1
1184+
@test_throws BoundsError S[LinearAlgebra.BandIndex(size(S,1),1)]
1185+
@test_throws BoundsError S[LinearAlgebra.BandIndex(0,size(S,1)+1)]
11821186
end
11831187

11841188
end # module TestTridiagonal

0 commit comments

Comments
 (0)