Skip to content

Commit 2e8e2b0

Browse files
Add more fixes to get_struct unit tests
1 parent bf4d141 commit 2e8e2b0

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

test/DataLayouts/unit_struct.jl

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function one_to_n(a::Array)
1515
end
1616
one_to_n(s::Tuple, ::Type{FT}) where {FT} = one_to_n(zeros(FT, s...))
1717
ncomponents(::Type{FT}, ::Type{S}) where {FT, S} = div(sizeof(S), sizeof(FT))
18-
field_dim_to_one(s, dim) = Tuple(map(j-> j == dim ? 1 : s[j], 1:length(s)))
18+
field_dim_to_one(s, dim) = Tuple(map(j -> j == dim ? 1 : s[j], 1:length(s)))
1919
CI(s) = CartesianIndices(map-> Base.OneTo(ξ), s))
2020

2121
struct Foo{T}
@@ -72,8 +72,9 @@ end
7272
@testset "get_struct - VIJFH indexing" begin
7373
FT = Float64
7474
S = Foo{FT}
75-
s = (2, 2, 2, 2, 2)
76-
a = one_to_n(s, FT)
75+
s_array = (2, 2, 2, 2, 2)
76+
s = field_dim_to_one(s_array, 4)
77+
a = one_to_n(s_array, FT)
7778
@test ncomponents(FT, S) == 2
7879

7980
@test get_struct(a, S, Val(4), CI(s)[1]) == Foo{FT}(1.0, 9.0)
@@ -84,30 +85,15 @@ end
8485
@test get_struct(a, S, Val(4), CI(s)[6]) == Foo{FT}(6.0, 14.0)
8586
@test get_struct(a, S, Val(4), CI(s)[7]) == Foo{FT}(7.0, 15.0)
8687
@test get_struct(a, S, Val(4), CI(s)[8]) == Foo{FT}(8.0, 16.0)
87-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[9])
88-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[10])
89-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[11])
90-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[12])
91-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[13])
92-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[14])
93-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[15])
94-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[16])
95-
@test get_struct(a, S, Val(4), CI(s)[17]) == Foo{FT}(17.0, 25.0)
96-
@test get_struct(a, S, Val(4), CI(s)[18]) == Foo{FT}(18.0, 26.0)
97-
@test get_struct(a, S, Val(4), CI(s)[19]) == Foo{FT}(19.0, 27.0)
98-
@test get_struct(a, S, Val(4), CI(s)[20]) == Foo{FT}(20.0, 28.0)
99-
@test get_struct(a, S, Val(4), CI(s)[21]) == Foo{FT}(21.0, 29.0)
100-
@test get_struct(a, S, Val(4), CI(s)[22]) == Foo{FT}(22.0, 30.0)
101-
@test get_struct(a, S, Val(4), CI(s)[23]) == Foo{FT}(23.0, 31.0)
102-
@test get_struct(a, S, Val(4), CI(s)[24]) == Foo{FT}(24.0, 32.0)
103-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[25])
104-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[26])
105-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[27])
106-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[28])
107-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[29])
108-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[30])
109-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[31])
110-
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[32])
88+
@test get_struct(a, S, Val(4), CI(s)[9]) == Foo{FT}(17.0, 25.0)
89+
@test get_struct(a, S, Val(4), CI(s)[10]) == Foo{FT}(18.0, 26.0)
90+
@test get_struct(a, S, Val(4), CI(s)[11]) == Foo{FT}(19.0, 27.0)
91+
@test get_struct(a, S, Val(4), CI(s)[12]) == Foo{FT}(20.0, 28.0)
92+
@test get_struct(a, S, Val(4), CI(s)[13]) == Foo{FT}(21.0, 29.0)
93+
@test get_struct(a, S, Val(4), CI(s)[14]) == Foo{FT}(22.0, 30.0)
94+
@test get_struct(a, S, Val(4), CI(s)[15]) == Foo{FT}(23.0, 31.0)
95+
@test get_struct(a, S, Val(4), CI(s)[16]) == Foo{FT}(24.0, 32.0)
96+
@test_throws BoundsError get_struct(a, S, Val(4), CI(s)[17])
11197
end
11298

11399
# TODO: add set_struct!

0 commit comments

Comments
 (0)