-
Notifications
You must be signed in to change notification settings - Fork 1
/
color_test.go
69 lines (58 loc) · 1.25 KB
/
color_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
package coloredgoroutine
import (
"fmt"
"math"
"os"
"sync"
"testing"
"github.com/xiegeo/coloredgoroutine/goid"
)
func TestGetColorForID(t *testing.T) {
t.Log(getColorForID(math.MinInt32).Sprintf("%d", math.MinInt32))
t.Log(getColorForUID(math.MaxUint64).Sprintf("%d", uint64(math.MaxUint64)))
for i := 0; i < len(colors); {
s := []interface{}{}
for {
s = append(s, getColorForID(i).Sprintf("%3d", i))
//c := &colors[i]
//s = append(s, c.Sprintf("%3d%3d", c.fg, c.bg-10))
i++
if i%24 == 0 || i == len(colors) {
break
}
}
t.Log(s...)
}
}
func TestPrintBannedColors(t *testing.T) {
for i := 0; i < len(bannedColors); {
s := []interface{}{}
for i < len(bannedColors) {
c := &bannedColors[i]
s = append(s, c.Sprintf("%3d%3d", c.fg, c.bg-10))
i++
if i%13 == 0 {
break
}
}
t.Log(s...)
}
}
func TestColorsInGoRoutines(t *testing.T) {
c := Colors(os.Stdout)
fmt.Fprintln(c, "Hi, I am go routine", goid.ID(), "from test routine")
if testing.Short() {
t.Skip("skip the longer version")
}
count := 100
var wg sync.WaitGroup
wg.Add(count)
for i := 0; i < count; i++ {
i := i
go func() {
fmt.Fprintln(c, "Hi, I am go routine", goid.ID(), "from loop i =", i)
wg.Done()
}()
}
wg.Wait()
}