@@ -5,28 +5,14 @@ using TestItems: @testitem, @testsnippet
55
66@testsnippet Testing begin
77 function test_index_chunks (; array_length, n, size, split, result)
8- if n === nothing
9- d, r = divrem (array_length, size)
10- nchunks = d + (r != 0 )
11- elseif size === nothing
12- nchunks = n
13- else
14- throw (ArgumentError (" both n and size === nothing" ))
15- end
168 c = index_chunks (rand (Int, array_length); n= n, size= size, split= split)
9+ nchunks = length (c)
1710 ranges = [c[i] for i in 1 : nchunks]
1811 all (ranges .== result)
1912 end
2013
2114 function sum_parallel (x, n, size, split, which)
22- if n === nothing
23- d, r = divrem (length (x), size)
24- nchunks = d + (r != 0 )
25- elseif size === nothing
26- nchunks = n
27- else
28- throw (ArgumentError (" both n and size === nothing" ))
29- end
15+ nchunks = length (index_chunks (x; n= n, size= size, split= split))
3016 s = zeros (eltype (x), nchunks)
3117 if which == " index_chunks"
3218 Threads. @threads for (ichunk, range) in enumerate (index_chunks (x; n= n, size= size, split= split))
128114 @test collect .(index_chunks (x; n= 3 , split= RoundRobin ())) == [[- 1 , 2 , 5 ], [0 , 3 ], [1 , 4 ]]
129115
130116 # FixedSize
131- @test_throws ArgumentError collect (index_chunks (1 : 10 ; size= 2 , split= RoundRobin ())) # not supported (yet?)
117+ @test collect (index_chunks ([1 ,2 ,3 ,4 ,5 ,6 ,7 ]; size= 2 , split= RoundRobin ())) == [[1 ,4 ], [2 ,5 ], [3 ,6 ], [7 ]]
118+ @test collect (chunks ([' a' ,' b' ,' c' ,' d' ,' e' ,' f' ,' g' ]; size= 2 , split= RoundRobin ())) == [[' a' ,' d' ], [' b' ,' e' ], [' c' ,' f' ], [' g' ]]
119+ @test collect (index_chunks (1 : 7 ; size= 2 , split= RoundRobin ())) == [1 : 3 : 4 , 2 : 3 : 5 , 3 : 3 : 6 , 7 : 3 : 7 ]
120+ @test collect (index_chunks (1 : 6 ; size= 2 , split= RoundRobin ())) == [1 : 3 : 4 , 2 : 3 : 5 , 3 : 3 : 6 ]
121+ @test collect (index_chunks (1 : 10 ; size= 3 , split= RoundRobin ())) == [1 : 3 : 7 , 2 : 3 : 8 , 3 : 3 : 9 , 10 : 3 : 10 ]
122+ @test collect (index_chunks (1 : 9 ; size= 3 , split= RoundRobin ())) == [1 : 3 : 7 , 2 : 3 : 8 , 3 : 3 : 9 ]
123+ x = OffsetArray (1 : 7 , - 1 : 5 )
124+ @test collect (index_chunks (x; size= 2 , split= RoundRobin ())) == [- 1 : 3 : 2 , 0 : 3 : 3 , 1 : 3 : 4 , 5 : 3 : 5 ]
125+ @test test_sum (; array_length= 7 , n= nothing , size= 2 , split= RoundRobin ())
126+ @test test_sum (; array_length= 15 , n= nothing , size= 4 , split= RoundRobin ())
127+ @test test_sum (; array_length= 117 , n= nothing , size= 10 , split= RoundRobin ())
132128end
133129
134130@testitem " check input argument errors" begin
0 commit comments