11
2- module TestIndexing
2+ module TestIndexing
33
44using MultidimensionalSparseArrays
55using Test
66
7-
8- @testset " Indexing" begin
9- A = SparseArray {Float64, 2} ((3 , 3 ))
10-
11- # Setting values
12- A[1 , 1 ] = 5.0
13- A[2 , 3 ] = - 2.5
14- A[3 , 2 ] = 1.0
15-
16- @test A[1 , 1 ] == 5.0
17- @test A[2 , 3 ] == - 2.5
18- @test A[3 , 2 ] == 1.0
19- @test A[1 , 2 ] == 0.0 # Default value
20- @test A[2 , 2 ] == 0.0 # Default value
21-
22- # CartesianIndex access
23- @test A[CartesianIndex (1 , 1 )] == 5.0
24- @test A[CartesianIndex (2 , 2 )] == 0.0
25-
26- A[CartesianIndex (2 , 1 )] = 3.0
27- @test A[2 , 1 ] == 3.0
28-
29- # Setting to default value should remove from storage
30- A[1 , 1 ] = 0.0
31- @test A[1 , 1 ] == 0.0
32- @test nnz (A) == 3 # Should be one less stored element
33-
34- # Bounds checking
35- @test_throws BoundsError A[0 , 1 ]
36- @test_throws BoundsError A[4 , 1 ]
37- @test_throws BoundsError A[1 , 4 ]
38- end
39-
40- end
7+ @testset " Indexing" begin
8+ A = SparseArray {Float64, 2} ((3 , 3 ))
9+
10+ # Setting values
11+ A[1 , 1 ] = 5.0
12+ A[2 , 3 ] = - 2.5
13+ A[3 , 2 ] = 1.0
14+
15+ @test A[1 , 1 ] == 5.0
16+ @test A[2 , 3 ] == - 2.5
17+ @test A[3 , 2 ] == 1.0
18+ @test A[1 , 2 ] == 0.0 # Default value
19+ @test A[2 , 2 ] == 0.0 # Default value
20+
21+ # CartesianIndex access
22+ @test A[CartesianIndex (1 , 1 )] == 5.0
23+ @test A[CartesianIndex (2 , 2 )] == 0.0
24+
25+ A[CartesianIndex (2 , 1 )] = 3.0
26+ @test A[2 , 1 ] == 3.0
27+
28+ # Setting to default value should remove from storage
29+ A[1 , 1 ] = 0.0
30+ @test A[1 , 1 ] == 0.0
31+ @test nnz (A) == 3 # Should be one less stored element
32+
33+ # Bounds checking
34+ @test_throws BoundsError A[0 , 1 ]
35+ @test_throws BoundsError A[4 , 1 ]
36+ @test_throws BoundsError A[1 , 4 ]
37+ end
38+
39+ end
0 commit comments