-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathterms_test.go
More file actions
59 lines (51 loc) · 1.39 KB
/
Copy pathterms_test.go
File metadata and controls
59 lines (51 loc) · 1.39 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
57
58
59
package search
import "testing"
func newTestTerms(t ...string) *Terms {
return &Terms{terms: t, size: len(t)}
}
func TestNextCyclesSequentially(t *testing.T) {
terms := newTestTerms("a", "b", "c")
want := []string{"a", "b", "c", "a", "b"}
for i, w := range want {
got := terms.Next()
if got != w {
t.Fatalf("Next() call %d = %q, want %q", i, got, w)
}
}
}
func TestNextSingleTerm(t *testing.T) {
terms := newTestTerms("only")
for i := 0; i < 5; i++ {
if got := terms.Next(); got != "only" {
t.Fatalf("Next() = %q, want %q", got, "only")
}
}
}
func TestRandomReturnsValidTerm(t *testing.T) {
terms := newTestTerms("a", "b", "c")
valid := map[string]bool{"a": true, "b": true, "c": true}
for i := 0; i < 100; i++ {
got := terms.Random()
if !valid[got] {
t.Fatalf("Random() = %q, not in term list", got)
}
}
}
func TestNextIndependentPerInstance(t *testing.T) {
// Simulates two VUs each getting their own Terms instance
vu1 := newTestTerms("a", "b", "c")
vu2 := newTestTerms("a", "b", "c")
// Both should start from the same position
if got := vu1.Next(); got != "a" {
t.Fatalf("vu1 first = %q, want %q", got, "a")
}
if got := vu2.Next(); got != "a" {
t.Fatalf("vu2 first = %q, want %q", got, "a")
}
// Advancing vu1 doesn't affect vu2
vu1.Next() // "b"
vu1.Next() // "c"
if got := vu2.Next(); got != "b" {
t.Fatalf("vu2 second = %q, want %q", got, "b")
}
}