forked from goodsign/monday
-
Notifications
You must be signed in to change notification settings - Fork 1
/
set_test.go
45 lines (40 loc) · 894 Bytes
/
set_test.go
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
package monday
import (
"strconv"
"testing"
)
func TestSet_Add(t *testing.T) {
s := newSet()
s.Add(LocaleEnUS)
s.Add(LocaleEnGB)
s.Add(LocaleEnGB) // duplicate
if !s.Has(LocaleEnGB) {
t.Error("Add: added item not available in the set")
}
if !s.Has(LocaleEnUS, LocaleEnGB) {
t.Error("Add: added items are not availabile in the set.")
}
}
func TestSet_RaceAdd(t *testing.T) {
// Create two sets. Add concurrently items to each of them. Remove from the
// other one.
// "go test -race" should detect this if the library is not thread-safe.
s := newSet()
u := newSet()
go func() {
for i := 0; i < 1000; i++ {
item := "item" + strconv.Itoa(i)
go func(i int) {
s.Add(Locale(item))
u.Add(Locale(item))
}(i)
}
}()
for i := 0; i < 1000; i++ {
item := "item" + strconv.Itoa(i)
go func(i int) {
s.Add(Locale(item))
u.Add(Locale(item))
}(i)
}
}