generated from atomicgo/template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
examples_test.go
106 lines (83 loc) · 1.37 KB
/
examples_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package robin_test
import (
"atomicgo.dev/robin"
"fmt"
)
type Person struct {
Name string
}
func ExampleLoadbalancer_demo() {
people := []Person{
{Name: "person1"},
{Name: "person2"},
{Name: "person3"},
{Name: "person4"},
{Name: "person5"},
}
lb := robin.NewLoadbalancer(people)
for i := 0; i < 10; i++ {
fmt.Println(lb.Next().Name)
}
// Output:
// person1
// person2
// person3
// person4
// person5
// person1
// person2
// person3
// person4
// person5
}
func ExampleNewLoadbalancer() {
set := []string{"object1", "object2", "object3"}
lb := robin.NewLoadbalancer(set)
fmt.Println(lb.Current())
// Output:
// object1
}
func ExampleLoadbalancer_Current() {
set := []int{1, 2, 3}
lb := robin.NewLoadbalancer(set)
fmt.Println(lb.Current())
// Output:
// 1
}
func ExampleLoadbalancer_AddItems() {
set := []int{1, 2, 3}
lb := robin.NewLoadbalancer(set)
lb.AddItems(4, 5, 6)
fmt.Println(lb.Items)
// Output:
// [1 2 3 4 5 6]
}
func ExampleLoadbalancer_Reset() {
set := []int{1, 2, 3, 4, 5, 6}
lb := robin.NewLoadbalancer(set)
lb.Next()
lb.Next()
lb.Next()
lb.Reset()
fmt.Println(lb.Current())
// Output:
// 1
}
func ExampleLoadbalancer_Next() {
set := []int{1, 2, 3}
lb := robin.NewLoadbalancer(set)
for i := 0; i < 10; i++ {
fmt.Println(lb.Next())
}
// Output:
// 1
// 2
// 3
// 1
// 2
// 3
// 1
// 2
// 3
// 1
}