-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel_test.go
120 lines (94 loc) · 1.79 KB
/
label_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package yalzo
import (
"testing"
)
func initLabelList() LabelList {
return []string{"l1", "l2", "l3", "l4"}
}
func TestGetListLength(t *testing.T) {
ls := initLabelList()
if ls.GetListLength() != 4 {
t.Error("label: get list length")
}
}
func TestGetList(t *testing.T) {
initList := initLabelList()
ls := initList.GetList(10)
expected := []string{
" l1 ",
" l2 ",
" l3 ",
" l4 ",
}
for i := range ls {
if ls[i] != expected[i] {
t.Errorf("got %v, expected %v", ls[i], expected[i])
}
}
}
func TestIsInAryRange(t *testing.T) {
ls := initLabelList()
if !ls.IsInAryRange(3) {
t.Error("in range error")
}
if ls.IsInAryRange(4) {
t.Error("in range error")
}
}
func TestContains(t *testing.T) {
ls := initLabelList()
if i, ok := ls.Contains("l2"); i != 1 || !ok {
t.Error("error contains")
}
if i, ok := ls.Contains("l100"); i != 0 || ok {
t.Error("error contains")
}
}
func TestAdd(t *testing.T) {
ls := initLabelList()
i := ls.Add("l5")
if i != 5 {
t.Error("add error")
}
if ls[i-1] != "l5" {
t.Error("add error")
}
}
func TestRemove(t *testing.T) {
ls := initLabelList()
label := ls.Remove(0).(string)
if label != "l1" {
t.Error("error remove")
}
if len(ls) != 3 {
t.Error("error remove")
}
}
func TestGetPresentName(t *testing.T) {
ls := initLabelList()
name := ls.GetPresentName(0)
if name != "l1" {
t.Error("get name")
}
}
func TestRename(t *testing.T) {
ls := initLabelList()
ls.Rename(0, "l10")
if ls[0] != "l10" {
t.Error("rename")
}
}
func TestExchange(t *testing.T) {
ls := initLabelList()
ls.Exchange(0, 3)
if ls[0] != "l4" || ls[3] != "l1" {
t.Error("exchange")
}
}
func TestChangeLabel(t *testing.T) {
ls := initLabelList()
ls.ChangeLabel(0, "l10")
if ls[0] != "l10" {
t.Error("rename")
}
}