-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_test.go
More file actions
53 lines (40 loc) · 746 Bytes
/
random_test.go
File metadata and controls
53 lines (40 loc) · 746 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
42
43
44
45
46
47
48
49
50
51
52
53
package random_test
import (
"os"
"testing"
"atomicgo.dev/random"
)
func TestMain(m *testing.M) {
random.Seed(1337)
os.Exit(m.Run())
}
func ExampleSeed() {
random.Seed(1337)
}
func isUnique[T comparable](s []T) bool {
m := make(map[T]struct{})
for _, v := range s {
if _, ok := m[v]; ok {
return false
}
m[v] = struct{}{}
}
return true
}
func TestIsUniqueHelper(t *testing.T) {
t.Parallel()
t.Run("unique", func(t *testing.T) {
t.Parallel()
s := []int{1, 2, 3, 4, 5, 6}
if !isUnique(s) {
t.Errorf("Expected %v to be unique", s)
}
})
t.Run("not unique", func(t *testing.T) {
t.Parallel()
s := []int{1, 2, 3, 4, 5, 6, 1}
if isUnique(s) {
t.Errorf("Expected %v to not be unique", s)
}
})
}