Skip to content

Commit 9c245df

Browse files
kshyattandyferris
authored andcommitted
Tests for setindex (#206)
* Tests for setindex * Error throwing tests * One more error test
1 parent 5b42c36 commit 9c245df

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

test/MArray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,7 @@
112112
m[3] = 13
113113
m[4] = 14
114114
@test m.data === (11, 12, 13, 14)
115+
116+
@test_throws BoundsError setindex!(v, 4, -1)
115117
end
116118
end

test/indexing.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@
2626
# SVector
2727
mv = MVector{4,Int}()
2828
@test (mv[SVector(1,2,3,4)] = vec; (@inferred getindex(mv, SVector(4,3,2,1)))::SVector{4,Int} == SVector((7,6,5,4)))
29+
30+
mv = MVector{4,Int}()
31+
@test (mv[SVector(1,2,3,4)] = [4, 5, 6, 7]; (@inferred getindex(mv, SVector(4,3,2,1)))::SVector{4,Int} == SVector((7,6,5,4)))
32+
@test (mv[SVector(1,2,3,4)] = 2; (@inferred getindex(mv, SVector(4,3,2,1)))::SVector{4,Int} == SVector((2,2,2,2)))
2933

3034
# Colon
3135
mv = MVector{4,Int}()
3236
@test (mv[:] = vec; (@inferred getindex(mv, :))::SVector{4,Int} == SVector((4,5,6,7)))
37+
@test (mv[:] = [4, 5, 6, 7]; (@inferred getindex(mv, :))::SVector{4,Int} == SVector((4,5,6,7)))
38+
@test (mv[:] = 2; (@inferred getindex(mv, :))::SVector{4,Int} == SVector((2,2,2,2)))
39+
40+
@test_throws DimensionMismatch setindex!(mv, SVector(1,2,3), SVector(1,2,3,4))
41+
@test_throws DimensionMismatch setindex!(mv, SVector(1,2,3), :)
42+
@test_throws DimensionMismatch setindex!(mv, [1,2,3], SVector(1,2,3,4))
3343
end
3444

3545
@testset "Linear getindex()/setindex!() on MMatrix" begin

0 commit comments

Comments
 (0)