|
| 1 | +# This file is a part of MultiThreadingTools.jl, licensed under the MIT License (MIT). |
| 2 | + |
| 3 | +using MultiThreadingTools |
| 4 | +using Compat.Test |
| 5 | + |
| 6 | +@testset "workpartition" begin |
| 7 | + |
| 8 | + @testset "workpartition" begin |
| 9 | + num = 99 |
| 10 | + part = 7 |
| 11 | + tmp = div(num, part) |
| 12 | + cmp = [tmp, tmp+1] |
| 13 | + old = 0 |
| 14 | + for j=1:part |
| 15 | + res = @inferred MultiThreadingTools._workpartition_hi(num, part, j) |
| 16 | + @test res - old in cmp |
| 17 | + old = res |
| 18 | + end |
| 19 | + res = @inferred MultiThreadingTools._workpartition_hi(Int32(99), Int32(7), Int32(7)) |
| 20 | + @test res == Int32(99) |
| 21 | + @test typeof(res) <: Int32 |
| 22 | + @test_throws AssertionError MultiThreadingTools._workpartition_hi(-1, 7, 1) |
| 23 | + @test_throws AssertionError MultiThreadingTools._workpartition_hi(20, 0, 1) |
| 24 | + @test_throws AssertionError MultiThreadingTools._workpartition_hi(20, 7, -1) |
| 25 | + @test_throws AssertionError MultiThreadingTools._workpartition_hi(0, 7, 8) |
| 26 | + |
| 27 | + res = Array{Int}([]) |
| 28 | + num = 24 |
| 29 | + part = 6 |
| 30 | + tmp = div(num, part) |
| 31 | + cmp = [tmp, tmp+1] |
| 32 | + for i =1:part |
| 33 | + tmp = @inferred MultiThreadingTools._workpartition_impl(num, part, i) |
| 34 | + @test length(tmp) in cmp |
| 35 | + res = vcat(res, tmp) |
| 36 | + end |
| 37 | + @test res == collect(1:num) |
| 38 | + |
| 39 | + res = Array{Int}([]) |
| 40 | + num = 27 |
| 41 | + part = 3 |
| 42 | + stp = 4 |
| 43 | + fi = 3 |
| 44 | + |
| 45 | + for i =1:part |
| 46 | + res = vcat(res, @inferred workpartition(fi:stp:num, part, i)) |
| 47 | + end |
| 48 | + @test res == collect(fi:stp:num) |
| 49 | + |
| 50 | + res = Array{Int}([]) |
| 51 | + num = 14 |
| 52 | + part = 3 |
| 53 | + fi = 7 |
| 54 | + |
| 55 | + for i =1:part |
| 56 | + res = vcat(res, @inferred workpartition(UnitRange(fi:num), part, i)) |
| 57 | + end |
| 58 | + @test res == collect(fi:num) |
| 59 | + |
| 60 | + num = 20 |
| 61 | + part = 3 |
| 62 | + cmp = rand(num) |
| 63 | + res = Array{Float64}([]) |
| 64 | + |
| 65 | + for i =1:part |
| 66 | + res = vcat(res, @inferred workpartition(cmp, part, i)) |
| 67 | + end |
| 68 | + @test res == cmp |
| 69 | + |
| 70 | + res = Array{Float64}([]) |
| 71 | + for i=workpartitions(cmp, part) |
| 72 | + res = vcat(res, i) |
| 73 | + end |
| 74 | + @test res == cmp |
| 75 | + end |
| 76 | +end |
0 commit comments