|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+package modules
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ _ "fmt"
|
|
|
6
|
+ "testing"
|
|
|
7
|
+ "github.com/stretchr/testify/assert"
|
|
|
8
|
+)
|
|
|
9
|
+
|
|
|
10
|
+func Test_addTopicNode(t *testing.T) {
|
|
|
11
|
+
|
|
|
12
|
+ list := &topicList{nil, nil, 0}
|
|
|
13
|
+ ary := []int64{123,456,789,1234}
|
|
|
14
|
+
|
|
|
15
|
+ for i:=0; i< 4; i++{
|
|
|
16
|
+ tmp := []int64{ary[i]}
|
|
|
17
|
+ list.addTopicNode(tmp)
|
|
|
18
|
+ exp := []int64{ary[i]}
|
|
|
19
|
+
|
|
|
20
|
+ assert.Equal(t, list.tail.topic, exp, "add TopicNode failed")
|
|
|
21
|
+ }
|
|
|
22
|
+}
|
|
|
23
|
+
|
|
|
24
|
+func Test_addValueNode(t *testing.T) {
|
|
|
25
|
+
|
|
|
26
|
+ list := &valueList{nil, nil, 0}
|
|
|
27
|
+ ary := []int64{123,456,789,1234}
|
|
|
28
|
+
|
|
|
29
|
+ for i:=0; i< 4; i++{
|
|
|
30
|
+ tmp := []int64{ary[i]}
|
|
|
31
|
+ list.addValueNode(tmp)
|
|
|
32
|
+ exp := []int64{ary[i]}
|
|
|
33
|
+
|
|
|
34
|
+ assert.Equal(t, list.tail.val, exp, "add ValueNode failed")
|
|
|
35
|
+ }
|
|
|
36
|
+}
|
|
|
37
|
+
|
|
|
38
|
+func Test_findSub(t *testing.T){
|
|
|
39
|
+
|
|
|
40
|
+ ary := []int{1,2,3,4,5,6}
|
|
|
41
|
+ for i := 0; i < 6; i++ {
|
|
|
42
|
+ assert.Equal(t, findSub(ary, i + 1), i, "findSub is failed")
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ // Don't Exist
|
|
|
46
|
+ assert.Equal(t, findSub(ary, 7), -1, "findSub is failed")
|
|
|
47
|
+
|
|
|
48
|
+ // array = {1, 2, 3, 4, 5, 6} -> {1, 2, 4, 5, 6}
|
|
|
49
|
+ ary = remove(ary, 2)
|
|
|
50
|
+ assert.Equal(t, findSub(ary, 6), 4)
|
|
|
51
|
+}
|
|
|
52
|
+
|
|
|
53
|
+func Test_remove(t *testing.T){
|
|
|
54
|
+ l := make([]int, 4)
|
|
|
55
|
+ var i int
|
|
|
56
|
+ for i = 0; i < 4; i++{
|
|
|
57
|
+ l[i] = i
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ // array = {0, 1, 2, 3} -> {0, 1, 3}
|
|
|
61
|
+ l = remove(l, 2)
|
|
|
62
|
+ assert.Equal(t, l,[]int{0, 1, 3}, "Array Delete is failed")
|
|
|
63
|
+
|
|
|
64
|
+ // array = {0, 1, 3} -> {1, 3}
|
|
|
65
|
+ l = remove(l, 0)
|
|
|
66
|
+ assert.Equal(t, l, []int{1, 3}, "Array Delete is failed")
|
|
|
67
|
+
|
|
|
68
|
+ // array = {1, 2} -> {1}
|
|
|
69
|
+ l = remove(l, 1)
|
|
|
70
|
+ assert.Equal(t, l, []int{1}, "Array Delete is failed")
|
|
|
71
|
+
|
|
|
72
|
+ // array = {1} -> {}
|
|
|
73
|
+ l = remove(l, 0)
|
|
|
74
|
+ assert.Equal(t, l, []int{}, "Array Delete is failed")
|
|
|
75
|
+}
|
|
|
76
|
+
|
|
|
77
|
+func Test_isempty(t *testing.T){
|
|
|
78
|
+ node := &valueNode{next : nil, prev : nil}
|
|
|
79
|
+
|
|
|
80
|
+ // 1. One element in Node
|
|
|
81
|
+ node.single2sub_eb = append(node.single2sub_eb, 1)
|
|
|
82
|
+ assert.Equal(t, node.isEmpty(), false, "isEmpty is failed")
|
|
|
83
|
+
|
|
|
84
|
+ // 2. Empty
|
|
|
85
|
+ node.single2sub_eb = remove(node.single2sub_eb, 0)
|
|
|
86
|
+ assert.Equal(t, node.isEmpty(), true, "isEmpty is failed")
|
|
|
87
|
+
|
|
|
88
|
+ // 3. Many elements in Node
|
|
|
89
|
+ node.single2sub_b = append(node.single2sub_b, 1)
|
|
|
90
|
+ node.single2sub_eb = append(node.single2sub_eb, 1)
|
|
|
91
|
+ node.single2sub_s = append(node.single2sub_s, 1)
|
|
|
92
|
+ node.single2sub_es = append(node.single2sub_es, 1)
|
|
|
93
|
+ node.single2sub_e = append(node.single2sub_e, 1)
|
|
|
94
|
+ assert.Equal(t, node.isEmpty(), false,"isEmpty is failed")
|
|
|
95
|
+}
|
|
|
96
|
+
|
|
|
97
|
+func Test_insertSub(t *testing.T){
|
|
|
98
|
+ node := &valueNode{next : nil, prev : nil}
|
|
|
99
|
+
|
|
|
100
|
+// 1. Single2sub
|
|
|
101
|
+
|
|
|
102
|
+ // (1) <
|
|
|
103
|
+ node.insertSub("<", 1, true)
|
|
|
104
|
+ assert.Equal(t, 0, findSub(node.single2sub_s, 1),"singleInsertSub (<) is failed")
|
|
|
105
|
+
|
|
|
106
|
+ // (2) <=
|
|
|
107
|
+ node.insertSub("<=", 2, true)
|
|
|
108
|
+ assert.Equal(t, 0, findSub(node.single2sub_es, 2), "singleInsertSub (<=) is failed")
|
|
|
109
|
+
|
|
|
110
|
+ // (3) >
|
|
|
111
|
+ node.insertSub(">", 3, true)
|
|
|
112
|
+ assert.Equal(t, 0, findSub(node.single2sub_b, 3), "singleInsertSub (>) is failed")
|
|
|
113
|
+
|
|
|
114
|
+ // (4) >=
|
|
|
115
|
+ node.insertSub(">=", 4, true)
|
|
|
116
|
+ assert.Equal(t, 0, findSub(node.single2sub_eb, 4), "singleInsertSub (>=) is failed")
|
|
|
117
|
+
|
|
|
118
|
+ // (5) ==
|
|
|
119
|
+ node.insertSub("==", 5, true)
|
|
|
120
|
+ assert.Equal(t, 0, findSub(node.single2sub_e, 5), "singleInsertSub (==) is failed")
|
|
|
121
|
+
|
|
|
122
|
+// 2. range2sub
|
|
|
123
|
+
|
|
|
124
|
+ // (1) <
|
|
|
125
|
+ node.insertSub("<", 1, false)
|
|
|
126
|
+ assert.Equal(t, 0, findSub(node.range2sub_s, 1),"rangeInsertSub (<) is failed")
|
|
|
127
|
+
|
|
|
128
|
+ // (2) <=
|
|
|
129
|
+ node.insertSub("<=", 2, false)
|
|
|
130
|
+ assert.Equal(t, 0, findSub(node.range2sub_es, 2), "rangeInsertSub (<=) is failed")
|
|
|
131
|
+
|
|
|
132
|
+ // (3) >
|
|
|
133
|
+ node.insertSub(">", 3, false)
|
|
|
134
|
+ assert.Equal(t, 0, findSub(node.range2sub_b, 3), "rangeInsertSub (>) is failed")
|
|
|
135
|
+
|
|
|
136
|
+ // (4) >=
|
|
|
137
|
+ node.insertSub(">=", 4, false)
|
|
|
138
|
+ assert.Equal(t, 0, findSub(node.range2sub_eb, 4), "rangeInsertSub (>=) is failed")
|
|
|
139
|
+
|
|
|
140
|
+}
|
|
|
141
|
+
|
|
|
142
|
+func Test_getTopicPos(t *testing.T){
|
|
|
143
|
+ l := topicList{}
|
|
|
144
|
+ l.addTopicNode(nil)
|
|
|
145
|
+
|
|
|
146
|
+ // 1. find Topic in empty topiclist
|
|
|
147
|
+ if l.head.topic != nil{
|
|
|
148
|
+ fmt.Println("addTopicNode is failed")
|
|
|
149
|
+ }
|
|
|
150
|
+
|
|
|
151
|
+ // 2. find {{12},{34},{56},{78},{89},{90}} in topiclist
|
|
|
152
|
+ ary := [][]int64{{12},{34},{56},{78},{89},{90}}
|
|
|
153
|
+ if l.getTopicNodePos(ary[0]) != nil{
|
|
|
154
|
+ fmt.Println("getTopicNodePos is failed")
|
|
|
155
|
+ }
|
|
|
156
|
+
|
|
|
157
|
+ for i := 0; i < 5; i++{
|
|
|
158
|
+ l.addTopicNode(ary[i])
|
|
|
159
|
+ assert.Equal(t, ary[i], l.tail.topic)
|
|
|
160
|
+ }
|
|
|
161
|
+
|
|
|
162
|
+}
|
|
|
163
|
+
|
|
|
164
|
+func Test_getValuePos(t *testing.T){
|
|
|
165
|
+ l := valueList{}
|
|
|
166
|
+ l.addValueNode(nil)
|
|
|
167
|
+
|
|
|
168
|
+ ary := [][]int64{{12},{34},{56},{78},{89},{90}}
|
|
|
169
|
+
|
|
|
170
|
+ // 1. find {{12},{34},{56},{78},{89},{90}} in topiclist
|
|
|
171
|
+ for i := 0; i < 5; i++{
|
|
|
172
|
+ l.addValueNode(ary[i])
|
|
|
173
|
+ assert.Equal(t, ary[i], l.tail.val)
|
|
|
174
|
+ }
|
|
|
175
|
+}
|