-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsweep_test.go
More file actions
41 lines (36 loc) · 744 Bytes
/
sweep_test.go
File metadata and controls
41 lines (36 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2021 John Papandriopoulos. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package concurrent_test
import (
"sync"
"testing"
"go.jpap.org/concurrent"
)
func TestRunSweep(t *testing.T) {
tests := []struct {
count int
threads int
}{
{6, 1},
{7, 2},
{3, 0},
{7, 0},
{20, 0},
{7, 10},
{11, 10},
{3, 10},
}
for i, tc := range tests {
var mux sync.Mutex
x := make(map[int]bool)
concurrent.RunSweep(tc.count, tc.threads, func(i int) {
mux.Lock()
x[i] = true
mux.Unlock()
})
if c := len(x); c != tc.count {
t.Errorf("tc #%d: got %d, expected %d (threads: %d): %v", i, c, tc.count, tc.threads, x)
}
}
}