Skip to content

Commit 9d6efbe

Browse files
committed
one shot unit tests
1 parent a0b76d2 commit 9d6efbe

1 file changed

Lines changed: 207 additions & 0 deletions

File tree

test/ParallelKernel/test_allocators.jl

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,5 +1151,212 @@ eval(:(
11511151
end;
11521152
@reset_parallel_kernel()
11531153
end;
1154+
@testset "8. Collection types" begin
1155+
@require @is_initialized()
1156+
@testset "ArrayTuple and NamedArrayTuple" begin
1157+
# Test ArrayTuple with separate type parameters for number of components and dimension
1158+
arr1 = @zeros(nx, ny)
1159+
arr2 = @ones(nx, ny)
1160+
arr_tuple = Data.ArrayTuple{2, 2}((arr1, arr2))
1161+
@test size(arr_tuple) == (nx, ny)
1162+
@test eltype(arr_tuple) == eltype(arr1)
1163+
@test length(arr_tuple) == 2
1164+
@test arr_tuple[1] === arr1
1165+
@test arr_tuple[2] === arr2
1166+
1167+
# Test NamedArrayTuple with named access
1168+
named_arr_tuple = Data.NamedArrayTuple{2, 2, (:a, :b)}((arr1, arr2))
1169+
@test size(named_arr_tuple) == (nx, ny)
1170+
@test eltype(named_arr_tuple) == eltype(arr1)
1171+
@test length(named_arr_tuple) == 2
1172+
@test getfield(named_arr_tuple, :a) === arr1
1173+
@test getfield(named_arr_tuple, :b) === arr2
1174+
1175+
# Test 3D case
1176+
arr3d_1 = @zeros(nx, ny, nz)
1177+
arr3d_2 = @ones(nx, ny, nz)
1178+
arr3d_tuple = Data.ArrayTuple{2, 3}((arr3d_1, arr3d_2))
1179+
@test size(arr3d_tuple) == (nx, ny, nz)
1180+
@test length(arr3d_tuple) == 2
1181+
1182+
# Test NamedArrayTuple 3D
1183+
named_arr3d_tuple = Data.NamedArrayTuple{2, 3, (:x, :y)}((arr3d_1, arr3d_2))
1184+
@test size(named_arr3d_tuple) == (nx, ny, nz)
1185+
@test getfield(named_arr3d_tuple, :x) === arr3d_1
1186+
@test getfield(named_arr3d_tuple, :y) === arr3d_2
1187+
end;
1188+
@testset "CellArrayTuple and NamedCellArrayTuple" begin
1189+
# Test CellArrayTuple with separate type parameters for number of components, dimension, and celldims
1190+
cell1 = @zeros(CellArray, (2,2))
1191+
cell2 = @ones(CellArray, (2,2))
1192+
cell_arr_tuple = Data.CellArrayTuple{2, 2, (2,2)}((cell1, cell2))
1193+
@test length(cell_arr_tuple) == 2
1194+
@test cell_arr_tuple[1] === cell1
1195+
@test cell_arr_tuple[2] === cell2
1196+
1197+
# Test NamedCellArrayTuple with named access
1198+
named_cell_arr_tuple = Data.NamedCellArrayTuple{2, 2, (2,2), (:p, :q)}((cell1, cell2))
1199+
@test length(named_cell_arr_tuple) == 2
1200+
@test getfield(named_cell_arr_tuple, :p) === cell1
1201+
@test getfield(named_cell_arr_tuple, :q) === cell2
1202+
end;
1203+
@testset "CellTuple and NamedCellTuple" begin
1204+
# Test CellTuple with static size
1205+
static_size = (2, 2)
1206+
cell_static1 = Data.Cell{static_size}(@zeros(2, 2))
1207+
cell_static2 = Data.Cell{static_size}(@ones(2, 2))
1208+
cell_tuple = Data.CellTuple{2, static_size}((cell_static1, cell_static2))
1209+
@test length(cell_tuple) == 2
1210+
@test cell_tuple[1] === cell_static1
1211+
@test cell_tuple[2] === cell_static2
1212+
1213+
# Test NamedCellTuple with named access
1214+
named_cell_tuple = Data.NamedCellTuple{2, static_size, (:r, :s)}((cell_static1, cell_static2))
1215+
@test length(named_cell_tuple) == 2
1216+
@test getfield(named_cell_tuple, :r) === cell_static1
1217+
@test getfield(named_cell_tuple, :s) === cell_static2
1218+
end;
1219+
@testset "NumberTuple and NamedNumberTuple" begin
1220+
# Test NumberTuple
1221+
num1 = Data.Number(1)
1222+
num2 = Data.Number(2)
1223+
num_tuple = Data.NumberTuple{2}((num1, num2))
1224+
@test length(num_tuple) == 2
1225+
@test num_tuple[1] === num1
1226+
@test num_tuple[2] === num2
1227+
1228+
# Test NamedNumberTuple with named access
1229+
named_num_tuple = Data.NamedNumberTuple{2, (:i, :j)}((num1, num2))
1230+
@test length(named_num_tuple) == 2
1231+
@test getfield(named_num_tuple, :i) === num1
1232+
@test getfield(named_num_tuple, :j) === num2
1233+
end;
1234+
@testset "IndexTuple and NamedIndexTuple" begin
1235+
# Test IndexTuple
1236+
idx1 = Data.Index(1)
1237+
idx2 = Data.Index(2)
1238+
idx_tuple = Data.IndexTuple{2}((idx1, idx2))
1239+
@test length(idx_tuple) == 2
1240+
@test idx_tuple[1] === idx1
1241+
@test idx_tuple[2] === idx2
1242+
1243+
# Test NamedIndexTuple with named access
1244+
named_idx_tuple = Data.NamedIndexTuple{2, (:m, :n)}((idx1, idx2))
1245+
@test length(named_idx_tuple) == 2
1246+
@test getfield(named_idx_tuple, :m) === idx1
1247+
@test getfield(named_idx_tuple, :n) === idx2
1248+
end;
1249+
@testset "Union collection types" begin
1250+
# Test ArrayCollection - union of ArrayTuple and NamedArrayTuple
1251+
arr1 = @zeros(nx, ny)
1252+
arr2 = @ones(nx, ny)
1253+
arr_tuple = Data.ArrayTuple{2, 2}((arr1, arr2))
1254+
named_arr_tuple = Data.NamedArrayTuple{2, 2, (:a, :b)}((arr1, arr2))
1255+
@test arr_tuple isa Data.ArrayCollection{2, 2}
1256+
@test named_arr_tuple isa Data.ArrayCollection{2, 2}
1257+
1258+
# Test NumberCollection - union of NumberTuple and NamedNumberTuple
1259+
num1 = Data.Number(1)
1260+
num2 = Data.Number(2)
1261+
num_tuple = Data.NumberTuple{2}((num1, num2))
1262+
named_num_tuple = Data.NamedNumberTuple{2, (:i, :j)}((num1, num2))
1263+
@test num_tuple isa Data.NumberCollection{2}
1264+
@test named_num_tuple isa Data.NumberCollection{2}
1265+
1266+
# Test IndexCollection - union of IndexTuple and NamedIndexTuple
1267+
idx1 = Data.Index(1)
1268+
idx2 = Data.Index(2)
1269+
idx_tuple = Data.IndexTuple{2}((idx1, idx2))
1270+
named_idx_tuple = Data.NamedIndexTuple{2, (:m, :n)}((idx1, idx2))
1271+
@test idx_tuple isa Data.IndexCollection{2}
1272+
@test named_idx_tuple isa Data.IndexCollection{2}
1273+
1274+
# Test CellCollection - union of CellTuple and NamedCellTuple
1275+
static_size = (2, 2)
1276+
cell_static1 = Data.Cell{static_size}(@zeros(2, 2))
1277+
cell_static2 = Data.Cell{static_size}(@ones(2, 2))
1278+
cell_tuple = Data.CellTuple{2, static_size}((cell_static1, cell_static2))
1279+
named_cell_tuple = Data.NamedCellTuple{2, static_size, (:r, :s)}((cell_static1, cell_static2))
1280+
@test cell_tuple isa Data.CellCollection{2, static_size}
1281+
@test named_cell_tuple isa Data.CellCollection{2, static_size}
1282+
1283+
# Test CellArrayCollection - union of CellArrayTuple and NamedCellArrayTuple
1284+
cell1 = @zeros(CellArray, (2,2))
1285+
cell2 = @ones(CellArray, (2,2))
1286+
cell_arr_tuple = Data.CellArrayTuple{2, 2, (2,2)}((cell1, cell2))
1287+
named_cell_arr_tuple = Data.NamedCellArrayTuple{2, 2, (2,2), (:p, :q)}((cell1, cell2))
1288+
@test cell_arr_tuple isa Data.CellArrayCollection{2, 2, (2,2)}
1289+
@test named_cell_arr_tuple isa Data.CellArrayCollection{2, 2, (2,2)}
1290+
end;
1291+
@reset_parallel_kernel()
1292+
end;
1293+
@testset "9. Kernel signature type matching" begin
1294+
@require @is_initialized()
1295+
@testset "Separate type parameters for number of components and dimension" begin
1296+
# Verify that ArrayTuple has separate type parameters for N_tuple (number of components) and N (dimension)
1297+
arr1 = @zeros(nx, ny)
1298+
arr2 = @ones(nx, ny)
1299+
arr_tuple = Data.ArrayTuple{2, 2}((arr1, arr2))
1300+
@test typeof(arr_tuple).parameters[1] == 2 # N_tuple = 2 (number of components)
1301+
@test typeof(arr_tuple).parameters[2] == 2 # N = 2 (dimension)
1302+
1303+
# Verify that NamedArrayTuple has separate type parameters
1304+
named_arr_tuple = Data.NamedArrayTuple{2, 2, (:a, :b)}((arr1, arr2))
1305+
@test typeof(named_arr_tuple).parameters[1] == 2 # N_tuple
1306+
@test typeof(named_arr_tuple).parameters[2] == 2 # N
1307+
@test typeof(named_arr_tuple).parameters[3] == :a # names
1308+
1309+
# Verify that CellArrayTuple has separate type parameters
1310+
cell1 = @zeros(CellArray, (2,2))
1311+
cell2 = @ones(CellArray, (2,2))
1312+
cell_arr_tuple = Data.CellArrayTuple{2, 2, (2,2)}((cell1, cell2))
1313+
@test typeof(cell_arr_tuple).parameters[1] == 2 # N_tuple
1314+
@test typeof(cell_arr_tuple).parameters[2] == 2 # N
1315+
@test typeof(cell_arr_tuple).parameters[3] == (2,2) # B (celldims)
1316+
1317+
# Verify that NamedCellArrayTuple has separate type parameters
1318+
named_cell_arr_tuple = Data.NamedCellArrayTuple{2, 2, (2,2), (:p, :q)}((cell1, cell2))
1319+
@test typeof(named_cell_arr_tuple).parameters[1] == 2 # N_tuple
1320+
@test typeof(named_cell_arr_tuple).parameters[2] == 2 # N
1321+
@test typeof(named_cell_arr_tuple).parameters[3] == (2,2) # B
1322+
@test typeof(named_cell_arr_tuple).parameters[4] == :p # names
1323+
1324+
# Test 3D case - verify dimension is correctly set to 3
1325+
arr3d_1 = @zeros(nx, ny, nz)
1326+
arr3d_2 = @ones(nx, ny, nz)
1327+
arr3d_tuple = Data.ArrayTuple{2, 3}((arr3d_1, arr3d_2))
1328+
@test typeof(arr3d_tuple).parameters[1] == 2 # N_tuple
1329+
@test typeof(arr3d_tuple).parameters[2] == 3 # N = 3 for 3D
1330+
end;
1331+
@testset "Field types in kernel signatures match field data types" begin
1332+
# Test VectorField type matching - 3 components, 3D dimension
1333+
nxyz = (nx, ny, nz)
1334+
vector_field = @VectorField(nxyz)
1335+
@test typeof(vector_field) == Data.Fields.VectorField
1336+
1337+
# Test BVectorField type matching
1338+
bvector_field = @BVectorField(nxyz)
1339+
@test typeof(bvector_field) == Data.Fields.BVectorField
1340+
1341+
# Test TensorField type matching - 6 components for symmetric tensor, 3D
1342+
tensor_field = @TensorField(nxyz)
1343+
@test typeof(tensor_field) == Data.Fields.TensorField
1344+
1345+
# Test 2D cases
1346+
nxy = (nx, ny)
1347+
vector_field_2d = @VectorField(nxy)
1348+
@test typeof(vector_field_2d) == Data.Fields.VectorField
1349+
1350+
tensor_field_2d = @TensorField(nxy)
1351+
@test typeof(tensor_field_2d) == Data.Fields.TensorField
1352+
1353+
# Verify that field type aliases match the types obtained from field macros
1354+
# For VectorField: N_tuple=3 (3 components), N=3 (3D) or N=2 (2D)
1355+
@test Data.Fields.VectorField == typeof(@VectorField(nxyz))
1356+
@test Data.Fields.BVectorField == typeof(@BVectorField(nxyz))
1357+
@test Data.Fields.TensorField == typeof(@TensorField(nxyz))
1358+
end;
1359+
@reset_parallel_kernel()
1360+
end;
11541361
end;
11551362
)) end == nothing || true;

0 commit comments

Comments
 (0)