Skip to content

Commit

Permalink
Merge pull request #1909 from CliMA/ck/improve_get_struct_tests
Browse files Browse the repository at this point in the history
Widen `get_struct` tests
  • Loading branch information
charleskawczynski authored Jul 31, 2024
2 parents e2d61b0 + 372759f commit cf881de
Showing 1 changed file with 71 additions and 4 deletions.
75 changes: 71 additions & 4 deletions test/DataLayouts/unit_struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,61 @@ end
a = one_to_n(s, FT)
CI = CartesianIndices(map-> Base.OneTo(ξ), s))
@test ncomponents(FT, S) == 2
# Call get_struct, and span `a` (access elements to 24.0): 12 cases

# Call get_struct, and span `a` (access elements to 24.0):
# No datalayouts have field dim of 1
@test DataLayouts.get_struct(a, S, Val(1), CI[1]) == Foo{FT}(1.0, 2.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[2])

@test DataLayouts.get_struct(a, S, Val(1), CI[3]) == Foo{FT}(3.0, 4.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[4])
@test DataLayouts.get_struct(a, S, Val(1), CI[5]) == Foo{FT}(5.0, 6.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[6])
@test DataLayouts.get_struct(a, S, Val(1), CI[7]) == Foo{FT}(7.0, 8.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[8])
@test DataLayouts.get_struct(a, S, Val(1), CI[9]) == Foo{FT}(9.0, 10.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[10])
@test DataLayouts.get_struct(a, S, Val(1), CI[11]) == Foo{FT}(11.0, 12.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[12])
@test DataLayouts.get_struct(a, S, Val(1), CI[13]) == Foo{FT}(13.0, 14.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[14])
@test DataLayouts.get_struct(a, S, Val(1), CI[15]) == Foo{FT}(15.0, 16.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[16])
@test DataLayouts.get_struct(a, S, Val(1), CI[17]) == Foo{FT}(17.0, 18.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[18])
@test DataLayouts.get_struct(a, S, Val(1), CI[19]) == Foo{FT}(19.0, 20.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[20])
@test DataLayouts.get_struct(a, S, Val(1), CI[21]) == Foo{FT}(21.0, 22.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[22])
@test DataLayouts.get_struct(a, S, Val(1), CI[23]) == Foo{FT}(23.0, 24.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(1), CI[24])

# e.g., how IFH is indexed (field dim 2)
@test DataLayouts.get_struct(a, S, Val(2), CI[1]) == Foo{FT}(1.0, 3.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[2]) == Foo{FT}(2.0, 4.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[3]) == Foo{FT}(3.0, 5.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[4]) == Foo{FT}(4.0, 6.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(2), CI[5])

@test_throws BoundsError DataLayouts.get_struct(a, S, Val(2), CI[6])
@test DataLayouts.get_struct(a, S, Val(2), CI[7]) == Foo{FT}(7.0, 9.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[8]) == Foo{FT}(8.0, 10.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[9]) == Foo{FT}(9.0, 11.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[10]) == Foo{FT}(10.0, 12.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(2), CI[11])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(2), CI[12])
@test DataLayouts.get_struct(a, S, Val(2), CI[13]) == Foo{FT}(13.0, 15.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[14]) == Foo{FT}(14.0, 16.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[15]) == Foo{FT}(15.0, 17.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[16]) == Foo{FT}(16.0, 18.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(2), CI[17])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(2), CI[18])
@test DataLayouts.get_struct(a, S, Val(2), CI[19]) == Foo{FT}(19.0, 21.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[20]) == Foo{FT}(20.0, 22.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[21]) == Foo{FT}(21.0, 23.0)
@test DataLayouts.get_struct(a, S, Val(2), CI[22]) == Foo{FT}(22.0, 24.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(2), CI[23])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(2), CI[24])

# e.g., how IJF is indexed (field dim 3)
@test DataLayouts.get_struct(a, S, Val(3), CI[1]) == Foo{FT}(1.0, 7.0)
@test DataLayouts.get_struct(a, S, Val(3), CI[2]) == Foo{FT}(2.0, 8.0)
@test DataLayouts.get_struct(a, S, Val(3), CI[3]) == Foo{FT}(3.0, 9.0)
Expand Down Expand Up @@ -139,7 +183,7 @@ end
@test DataLayouts.get_struct(a, S, Val(3), CI[4]) == Foo{FT}(4.0, 8.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(3), CI[5])

# VIJFH
# e.g., how VIJFH is indexed (field dim 4)
@test DataLayouts.get_struct(a, S, Val(4), CI[1]) == Foo{FT}(1.0, 9.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[2]) == Foo{FT}(2.0, 10.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[3]) == Foo{FT}(3.0, 11.0)
Expand All @@ -149,6 +193,29 @@ end
@test DataLayouts.get_struct(a, S, Val(4), CI[7]) == Foo{FT}(7.0, 15.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[8]) == Foo{FT}(8.0, 16.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[9])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[10])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[11])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[12])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[13])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[14])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[15])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[16])
@test DataLayouts.get_struct(a, S, Val(4), CI[17]) == Foo{FT}(17.0, 25.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[18]) == Foo{FT}(18.0, 26.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[19]) == Foo{FT}(19.0, 27.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[20]) == Foo{FT}(20.0, 28.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[21]) == Foo{FT}(21.0, 29.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[22]) == Foo{FT}(22.0, 30.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[23]) == Foo{FT}(23.0, 31.0)
@test DataLayouts.get_struct(a, S, Val(4), CI[24]) == Foo{FT}(24.0, 32.0)
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[25])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[26])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[27])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[28])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[29])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[30])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[31])
@test_throws BoundsError DataLayouts.get_struct(a, S, Val(4), CI[32])

@test DataLayouts.get_struct(a, S, Val(5), CI[1]) == Foo{FT}(1.0, 17.0)
@test DataLayouts.get_struct(a, S, Val(5), CI[2]) == Foo{FT}(2.0, 18.0)
Expand Down

0 comments on commit cf881de

Please sign in to comment.