-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
106 lines (85 loc) · 1.77 KB
/
example_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 bw_test
import (
"math/rand"
"testing"
"time"
"github.com/fatih/color"
"github.com/kura-lab/bw"
)
func Example(t *testing.T) {
numbers := 220
slice := make([]int, numbers)
for i := range slice {
slice[i] = i
}
n := len(slice)
for i := n - 1; i >= 0; i-- {
j := rand.Intn(i + 1)
slice[i], slice[j] = slice[j], slice[i]
}
bw := bw.NewBubbleWrap(numbers)
bw.Display()
for _, i := range slice {
time.Sleep(20 * time.Millisecond)
bw.Pop(i)
bw.Redisplay()
}
}
func ExampleBubbleWrap_SetColumn(t *testing.T) {
numbers := 220
bw := bw.NewBubbleWrap(numbers).SetColumn(60)
bw.Display()
for i := 0; i < numbers; i++ {
time.Sleep(10 * time.Millisecond)
bw.Pop(i)
bw.Redisplay()
}
}
func ExampleBubbleWrap_ChangeBubbleShape(t *testing.T) {
numbers := 220
bw := bw.NewBubbleWrap(numbers).ChangeBubbleShape("o", "x")
bw.Display()
for i := 0; i < numbers; i++ {
time.Sleep(10 * time.Millisecond)
bw.Pop(i)
bw.Redisplay()
}
}
func ExampleBubbleWrap_ChangeBubbleColor(t *testing.T) {
numbers := 220
before := color.New(color.FgCyan)
after := color.New(color.FgRed)
bw := bw.NewBubbleWrap(numbers).ChangeBubbleColor(before, after)
bw.Display()
for i := 0; i < numbers; i++ {
time.Sleep(10 * time.Millisecond)
bw.Pop(i)
bw.Redisplay()
}
}
func ExampleBubbleWrap_Interrupt(t *testing.T) {
numbers := 220
bw := bw.NewBubbleWrap(numbers)
bw.Display()
for i := 0; i < numbers; i++ {
time.Sleep(10 * time.Millisecond)
bw.Pop(i)
bw.Redisplay()
if i == 120 {
bw.Interrupt()
}
}
}
func ExampleBubbleWrap_Clear(t *testing.T) {
numbers := 220
bw := bw.NewBubbleWrap(numbers)
bw.Display()
for i := 0; i < numbers; i++ {
time.Sleep(10 * time.Millisecond)
bw.Pop(i)
bw.Redisplay()
}
bw.Display()
bw.Clear()
bw.Redisplay()
}