-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_test.go
48 lines (43 loc) · 1.05 KB
/
node_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
package skiplist
import (
"bytes"
"reflect"
"testing"
)
func TestNewNode(t *testing.T) {
n := NewNode(2, 2, []byte("Node two"))
if len(n.forward) != 2 {
t.Errorf("Forward length should be set to 2")
}
if n.key != 2 {
t.Errorf("Key should be set to 2")
}
if !bytes.Equal(reflect.ValueOf(n.val).Bytes(), []byte("Node two")) {
t.Errorf("Val should be set to 'Node two'")
}
}
func TestNextWithoutForwardNodes(t *testing.T) {
n := NewNode(0, 2, []byte("Node two"))
if n.next() != nil {
t.Errorf("Should not have found forward nodes")
}
}
func TestNextWithForwardNodes(t *testing.T) {
n := NewNode(2, 2, []byte("Node two"))
n2 := NewNode(2, 3, []byte("Node three"))
n.forward[0] = n2
if n.next() != n2 {
t.Errorf("Should have found n2 as a forward node")
}
}
func TestPrev(t *testing.T) {
n := NewNode(2, 2, []byte("Node two"))
if n.prev() != nil {
t.Errorf("Should not have found a previous node")
}
n2 := NewNode(2, 3, []byte("Node three"))
n.backward = n2
if n.prev() != n2 {
t.Errorf("Should have found n2 as the previous node")
}
}