Skip to content

Commit 871a13d

Browse files
authored
test with offset arrays (#32)
xref #29
1 parent 52e3342 commit 871a13d

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[compat]
22
Aqua = "0.8"
3+
OffsetArrays = "1.14"
34
Test = "1.11"
45

56
[deps]
67
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
8+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
79
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Test
22
using FixedSizeArrays
3+
using OffsetArrays: OffsetArray
34
import Aqua
45

56
const checked_dims = FixedSizeArrays.checked_dims
@@ -16,6 +17,14 @@ end
1617
@testset "Constructors" begin
1718
@test FixedSizeArray{Float64,0}(undef) isa FixedSizeArray{Float64,0}
1819
@test FixedSizeArray{Float64,0}(undef, ()) isa FixedSizeArray{Float64,0}
20+
for offset (-1, 0, 2, 3)
21+
ax = offset:(offset + 1)
22+
oa = OffsetArray([10, 20], ax)
23+
@test_throws DimensionMismatch FixedSizeArray(oa)
24+
@test_throws DimensionMismatch FixedSizeVector(oa)
25+
@test_throws DimensionMismatch FixedSizeArray{Int}(oa)
26+
@test_throws DimensionMismatch FixedSizeVector{Int}(oa)
27+
end
1928
@test_throws ArgumentError FixedSizeArray{Float64,1}(undef, -1)
2029
@test_throws ArgumentError FixedSizeArray{Float64,1}(undef, (-1,))
2130
@test_throws ArgumentError FixedSizeArray{Float64,2}(undef, -1, -1)
@@ -67,22 +76,25 @@ end
6776
@test similar(FixedSizeVector{Int}, (2,)) isa FixedSizeVector{Int}
6877
@test similar(FixedSizeArray{Int}, (2,)) isa FixedSizeVector{Int}
6978
@test FixedSizeArray{Int}(undef, 2) isa FixedSizeVector{Int}
79+
example_abstract_vectors = (7:9, [7, 8, 9], OffsetArray([7, 8, 9], 1:3))
7080
for T (FixedSizeArray, FixedSizeVector)
71-
a = 1:3
72-
@test convert(T, a) isa FixedSizeVector{Int}
73-
@test convert(T, a) == a
74-
@test convert(T, convert(T, a)) isa FixedSizeVector{Int}
75-
@test convert(T, convert(T, a)) == a
76-
end
77-
for T (FixedSizeArray{Int}, FixedSizeVector{Int})
78-
for S (Int, Float64)
79-
a = map(S, 1:3)
81+
for a example_abstract_vectors
8082
@test convert(T, a) isa FixedSizeVector{Int}
8183
@test convert(T, a) == a
8284
@test convert(T, convert(T, a)) isa FixedSizeVector{Int}
8385
@test convert(T, convert(T, a)) == a
8486
end
8587
end
88+
for T (FixedSizeArray{Int}, FixedSizeVector{Int})
89+
for S (Int, Float64)
90+
for a map((c -> map(S, c)), example_abstract_vectors)
91+
@test convert(T, a) isa FixedSizeVector{Int}
92+
@test convert(T, a) == a
93+
@test convert(T, convert(T, a)) isa FixedSizeVector{Int}
94+
@test convert(T, convert(T, a)) == a
95+
end
96+
end
97+
end
8698
end
8799

88100
@testset "FixedSizeMatrix" begin
@@ -99,22 +111,28 @@ end
99111
@test similar(FixedSizeMatrix{Int}, (2, 3)) isa FixedSizeMatrix{Int}
100112
@test similar(FixedSizeArray{Int}, (2, 3)) isa FixedSizeMatrix{Int}
101113
@test FixedSizeArray{Int}(undef, 2, 3) isa FixedSizeMatrix{Int}
114+
example_abstract_matrices = (
115+
reshape(1:9, (3, 3)),
116+
OffsetArray(reshape(1:9, (3, 3)), 1:3, 1:3),
117+
)
102118
for T (FixedSizeArray, FixedSizeMatrix)
103-
a = reshape(1:9, (3, 3))
104-
@test convert(T, a) isa FixedSizeMatrix{Int}
105-
@test convert(T, a) == a
106-
@test convert(T, convert(T, a)) isa FixedSizeMatrix{Int}
107-
@test convert(T, convert(T, a)) == a
108-
end
109-
for T (FixedSizeArray{Int}, FixedSizeMatrix{Int})
110-
for S (Int, Float64)
111-
a = map(S, reshape(1:9, (3, 3)))
119+
for a example_abstract_matrices
112120
@test convert(T, a) isa FixedSizeMatrix{Int}
113121
@test convert(T, a) == a
114122
@test convert(T, convert(T, a)) isa FixedSizeMatrix{Int}
115123
@test convert(T, convert(T, a)) == a
116124
end
117125
end
126+
for T (FixedSizeArray{Int}, FixedSizeMatrix{Int})
127+
for S (Int, Float64)
128+
for a map((c -> map(S, c)), example_abstract_matrices)
129+
@test convert(T, a) isa FixedSizeMatrix{Int}
130+
@test convert(T, a) == a
131+
@test convert(T, convert(T, a)) isa FixedSizeMatrix{Int}
132+
@test convert(T, convert(T, a)) == a
133+
end
134+
end
135+
end
118136
end
119137

120138
@testset "`map`" begin

0 commit comments

Comments
 (0)