forked from rosedblabs/rosedb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_zset_test.go
216 lines (174 loc) · 3.98 KB
/
db_zset_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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package rosedb
import (
"testing"
)
func TestRoseDB_ZAdd(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
err := db.ZAdd(key, 310.23, []byte("roseduan"))
db.ZAdd(nil, 0, nil)
db.ZAdd(key, 30.234554, []byte("Java"))
db.ZAdd(key, 92.2233, []byte("Golang"))
db.ZAdd(key, 221.24, []byte("Python"))
db.ZAdd(key, 221.24, []byte("Python-tensorflow"))
db.ZAdd(key, 221.24, []byte("Python-flask"))
db.ZAdd(key, 221.24, []byte("Python-django"))
db.ZAdd(key, 221.24, []byte("Python-scrapy"))
db.ZAdd(key, 54.30003, []byte("C"))
db.ZAdd(key, 54.30003, []byte("C plus plus"))
if err != nil {
t.Log(err)
}
}
func TestRoseDB_ZRem(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
db.ZRem(nil, nil)
_, _ = db.ZRem(key, []byte("C"))
_, _ = db.ZRem(key, []byte("Java"))
}
func TestRoseDB_ZScore(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
s := db.ZScore(key, []byte("roseduan"))
t.Log(s)
}
func TestRoseDB_ZCard(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
t.Log(db.ZCard(key))
}
func TestRoseDB_ZRank(t *testing.T) {
db := ReopenDb()
db.Close()
key := []byte("my_zset")
db.ZRank(nil, nil)
rank := db.ZRank(key, []byte("Python-flask"))
t.Log(rank)
t.Log(db.ZRank(key, []byte("Java")))
t.Log(db.ZRank(key, []byte("roseduan")))
}
func TestRoseDB_ZRevRank(t *testing.T) {
db := ReopenDb()
db.Close()
key := []byte("my_zset")
db.ZRevRank(nil, nil)
rank := db.ZRevRank(key, []byte("Python-flask"))
t.Log(rank)
t.Log(db.ZRevRank(key, []byte("Java")))
t.Log(db.ZRevRank(key, []byte("roseduan")))
}
func TestRoseDB_ZRange(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
db.ZRange(nil, 0, -1)
vals := db.ZRange(key, 0, -1)
for _, v := range vals {
t.Logf("%+v ", v)
}
}
func TestRoseDB_ZRangeWithScores(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
db.ZRangeWithScores(nil, 0, -1)
vals := db.ZRangeWithScores(key, 0, -1)
for _, v := range vals {
t.Logf("%+v ", v)
}
}
func TestRoseDB_ZRevRange(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
db.ZRevRange(nil, 0, -1)
vals := db.ZRevRange(key, 0, -1)
for _, v := range vals {
t.Logf("%+v ", v)
}
}
func TestRoseDB_ZRevRangeWithScores(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
db.ZRevRangeWithScores(nil, 0, -1)
vals := db.ZRevRangeWithScores(key, 0, -1)
for _, v := range vals {
t.Logf("%+v ", v)
}
}
func TestRoseDB_ZIncrBy(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
db.ZIncrBy(nil, 10, nil)
incr, err := db.ZIncrBy(key, 100, []byte("Java"))
if err != nil {
t.Log(err)
}
t.Log(incr)
t.Log(db.ZScore(key, []byte("Java")))
}
func TestRoseDB_ZGetByRank(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
getRank := func(rank int) {
val := db.ZGetByRank(key, rank)
for _, v := range val {
t.Logf("%+v ", v)
}
}
getRank(0)
getRank(4)
getRank(8)
getRank(2)
}
func TestRoseDB_ZRevGetByRank(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
getRevRank := func(rank int) {
val := db.ZRevGetByRank(key, rank)
for _, v := range val {
t.Logf("%+v ", v)
}
}
getRevRank(0)
getRevRank(9)
}
func TestRoseDB_ZScoreRange(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
scoreRange := func(min, max float64) {
vals := db.ZScoreRange(key, min, max)
for _, v := range vals {
t.Logf("%+v ", v)
}
}
db.ZScoreRange(nil, 0, -1)
scoreRange(50, 100)
scoreRange(100, 200)
scoreRange(200, 500)
}
func TestRoseDB_ZRevScoreRange(t *testing.T) {
db := ReopenDb()
defer db.Close()
key := []byte("my_zset")
recScoreRange := func(max, min float64) {
vals := db.ZRevScoreRange(key, max, min)
for _, v := range vals {
t.Logf("%+v ", v)
}
}
db.ZRevScoreRange(nil, 0, -1)
recScoreRange(100, 50)
recScoreRange(200, 100)
recScoreRange(500, 200)
}