Skip to content

Commit a40aea7

Browse files
committed
Add test: Support limiting the number of parallel processing subroutines
1 parent 3ac28e9 commit a40aea7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎utils_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ func testParallelN(n, procs int) bool {
4949
return true
5050
}
5151

52+
func TestParallelMaxProcs(t *testing.T) {
53+
for _, n := range []int{0, 1, 10, 100, 1000} {
54+
for _, p := range []int{1, 2, 4, 8, 16, 100} {
55+
if !testParallelMaxProcsN(n, p) {
56+
t.Fatalf("test [parallel %d %d] failed", n, p)
57+
}
58+
}
59+
}
60+
}
61+
62+
func testParallelMaxProcsN(n, procs int) bool {
63+
data := make([]bool, n)
64+
MaxProcs = procs
65+
parallel(0, n, func(is <-chan int) {
66+
for i := range is {
67+
data[i] = true
68+
}
69+
})
70+
MaxProcs = 0
71+
for i := 0; i < n; i++ {
72+
if !data[i] {
73+
return false
74+
}
75+
}
76+
return true
77+
}
78+
5279
func TestClamp(t *testing.T) {
5380
testCases := []struct {
5481
f float64

0 commit comments

Comments
 (0)