-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashqueue_test.go
More file actions
87 lines (65 loc) · 1.45 KB
/
hashqueue_test.go
File metadata and controls
87 lines (65 loc) · 1.45 KB
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
package hashqueue
import (
"fmt"
"github.com/google/uuid"
"strings"
"testing"
)
func TestHashQueue(t *testing.T) {
h := New()
/*
h.PushBack("foo", "foo")
h.PushFront("bar", "bar")
h.InsertAfter("qux", "qux", "bar")
h.InsertBefore("baz", "baz", "foo")
for e := h.Front(); e != nil; e = e.Next() {
fmt.Printf("%v => %v\n", e.Key, e.Value)
}
fmt.Printf("--\n")
h.MoveToFront("qux")
h.MoveToBack("bar")
h.MoveBefore("baz", "bar")
h.MoveAfter("foo", "qux")
for e := h.Front(); e != nil; e = e.Next() {
fmt.Printf("%v => %v\n", e.Key, e.Value)
}
fmt.Printf("--\n")
h.Sort(func(l, r *Element) bool {
return l.Key < r.Key
})
for e := h.Front(); e != nil; e = e.Next() {
fmt.Printf("%v => %v\n", e.Key, e.Value)
}
*/
/*
for i := 0; i < 100; i++ {
h.PushBack(uuid.New().String(), uuid.New().String())
}
h.Sort(func(l, r *Element) bool {
return l.Value.(string) < r.Value.(string)
})
*/
for i := 0; i < 10000; i++ {
key, val := uuid.New().String(), uuid.New().String()
h.Put(key, val, func(k string, v Value) bool {
return strings.Compare(val, v.(string)) < 0
})
}
var lastKey string
var failed bool
h.Range(func(key string, val Value) bool {
fmt.Printf("%v => %v\n", key, val)
// if key > lastKey {
if val.(string) > lastKey {
lastKey = val.(string)
return true
}
failed = true
return false
})
if failed {
fmt.Printf("FAILED\n")
} else {
fmt.Printf("PASS\n")
}
}