-
Notifications
You must be signed in to change notification settings - Fork 2
/
sortedset_score_test.go
48 lines (40 loc) · 971 Bytes
/
sortedset_score_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
// Copyright (c) 2018-2019 Burak Sezer. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sorted
import "testing"
func Test_SortedSetWithScore(t *testing.T) {
ss := NewSortedSetWithScore(0)
defer ss.Close()
keys := []string{}
for i := 0; i < 100; i++ {
err := ss.Set(bkey(i), uint64(100-i))
if err != nil {
t.Fatalf("Expected nil. Got %v", err)
}
keys = append(keys, string(bkey(i)))
}
for i := 0; i < 100; i++ {
ok := ss.Check(bkey(i))
if !ok {
t.Fatalf("Key could not be found: %s", bkey(i))
}
}
idx := 99
ss.Range(func(key []byte) bool {
if keys[idx] != string(key) {
t.Fatalf("Invalid key: %s", string(key))
}
idx--
return true
})
for i := 0; i < 100; i++ {
err := ss.Delete(bkey(i))
if err != nil {
t.Fatalf("Expected nil. Got %v", err)
}
}
if ss.Len() != 0 {
t.Fatalf("Expected length is zero. Got: %d", ss.Len())
}
}