forked from sjbog/go-DBSCAN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcurrentQueue_test.go
More file actions
56 lines (47 loc) · 1.14 KB
/
concurrentQueue_test.go
File metadata and controls
56 lines (47 loc) · 1.14 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package dbscan
import (
"sync"
"testing"
)
func Test_Queue(t *testing.T) {
t.Parallel()
var (
q = NewConcurrentQueue_InsertOnly()
waitGroup = new(sync.WaitGroup)
numSize = uint(100)
goroutinesSize = uint(10)
)
waitGroup.Add(int(goroutinesSize))
for gi := uint(0); gi < goroutinesSize; gi += 1 {
go func() {
for i := uint(0); i < numSize; i += 1 {
q.Add(i)
}
waitGroup.Done()
}()
}
waitGroup.Wait()
if q.Size != uint64(numSize*goroutinesSize) {
t.Fatalf("Didn't get the expected queue size : %v, result : %v", numSize*goroutinesSize, q.Size)
}
var (
slice = q.Slice()
counter = make(map[uint]uint)
)
// t.Logf("len=%d cap=%d %v", len(slice), cap(slice), slice)
if len(slice) != int(numSize*goroutinesSize) {
t.Fatalf("Didn't get the expected slice size : %v, result : %v", numSize*goroutinesSize, len(slice))
}
for _, x := range slice {
if _, ok := counter[x]; !ok {
counter[x] = 1
} else {
counter[x] += 1
}
}
for k, v := range counter {
if v != goroutinesSize {
t.Fatalf("Didn't get the expected count of \"%v\"'s, expected %v, got %v", k, numSize, v)
}
}
}