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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
// collection_test.go
package utils
import (
"fmt"
"testing"
)
func insertData(t *testing.T, oMap *OrderedMap, num int) (*OrderedMap, string) {
var e error = nil
for i := 0; i < num; i++ {
arg := "test"
key := i
value := fmt.Sprintf("%s%d", arg, key)
e = oMap.Append(key, value)
if e != nil {
t.Error(e)
}
}
result := "FAIL"
if e == nil {
result = "OK"
}
return oMap, result
}
func getData(t *testing.T, oMap *OrderedMap, iNum int, deleteNum int) string {
var result string
for i := 0; i < iNum; i++ {
if deleteNum == i {
continue
}
arg := "test"
key := i
value := fmt.Sprintf("%s%d", arg, key)
ans := oMap.Get(i).Element
result = "OK"
//fmt.Println(ans)
if ans != value {
result = "FAIL"
break
}
}
return result
}
func deleteData(t *testing.T, oMap *OrderedMap, iNum int, deleteNum int) string {
e := oMap.Delete(deleteNum)
result := "OK"
if e != nil {
result = "FAIL"
t.Error(e)
return result
}
result = getData(t, oMap, iNum, deleteNum)
return result
}
func popData(t *testing.T, oMap *OrderedMap, iNum int, popNum int) string {
arg := "test"
value := fmt.Sprintf("%s%d", arg, popNum)
getValue := oMap.Pop(popNum).Element
result := "OK"
fmt.Println(getValue)
if value != getValue {
result = "FAIL"
t.Errorf("Different result < %s > < %s >", value, getValue)
return result
}
result = getData(t, oMap, iNum, popNum)
return result
}
func checkLen(t *testing.T, oMap *OrderedMap, iNum int) string {
mLen := oMap.Len()
result := "OK"
if mLen != iNum {
result = "FAIL"
t.Errorf("Different result < %d > < %d >", mLen, iNum)
return result
}
return result
}
func getkListData(t *testing.T, oMap *OrderedMap, iNum int) string {
kList := oMap.KeyLists()
mkLen := kList.Len()
result := "OK"
if mkLen != iNum {
result = "FAIL"
t.Errorf("Different result < %d > < %d >", mkLen, iNum)
return result
}
i := 0
for elem := kList.Front(); elem != nil; elem = elem.Next() {
if elem.Value != i {
result = "FAIL"
break
}
i++
}
return result
}
func getvListData(t *testing.T, oMap *OrderedMap, iNum int) string {
vList := oMap.ValueLists()
mvLen := vList.Len()
result := "OK"
if mvLen != iNum {
result = "FAIL"
t.Errorf("Different result < %d > < %d >", mvLen, iNum)
return result
}
arg := "test"
i := 0
for elem := vList.Front(); elem != nil; elem = elem.Next() {
value := fmt.Sprintf("%s%d", arg, i)
if elem.Value != value {
result = "FAIL"
break
}
i++
}
return result
}
func Test_Collection(t *testing.T) {
// init
var result string
iNum := 10
deleteNum := -1
oMap := NewOrderedMap()
// test
t.Log("# INSERT")
oMap, result = insertData(t, oMap, iNum)
t.Log("# INSERT END -> [ ", result, " ]")
t.Log("")
t.Log("# GET ELEMENT")
result = getData(t, oMap, iNum, deleteNum)
t.Log("# INSERT ELEMENT END -> [ ", result, " ]")
t.Log("")
t.Log("# DELETE ELEMENT")
deleteNum = 9
result = deleteData(t, oMap, iNum, deleteNum)
t.Log("# DELETE ELEMENT END -> [ ", result, " ]")
t.Log("")
t.Log("# POP ELEMENT")
popNum := 9
oMap = NewOrderedMap()
oMap, result = insertData(t, oMap, iNum)
result = popData(t, oMap, iNum, popNum)
t.Log("# POP ELEMENT END -> [ ", result, " ]")
t.Log("")
t.Log("# CHECK LEN")
oMap = NewOrderedMap()
oMap, result = insertData(t, oMap, iNum)
result = checkLen(t, oMap, iNum)
t.Log("# CHECK LEN END -> [ ", result, " ]")
t.Log("")
t.Log("# GET KEY LIST")
result = getkListData(t, oMap, iNum)
t.Log("# GET KEY LIST END -> [ ", result, " ]")
t.Log("")
t.Log("# GET VALUE LIST")
result = getvListData(t, oMap, iNum)
t.Log("# GET VALUE LIST END -> [ ", result, " ]")
t.Log("")
}
|