-
Notifications
You must be signed in to change notification settings - Fork 5
/
encoding_test.go
51 lines (44 loc) · 955 Bytes
/
encoding_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
package fbptree
import (
"reflect"
"testing"
)
func TestEncodeDecodeTreeMetadata(t *testing.T) {
treeMetadata := &treeMetadata{
order: 542,
rootID: 12,
leftmostID: 42,
}
decoded, err := decodeTreeMetadata(encodeTreeMetadata(treeMetadata))
if err != nil {
t.Fatalf("failed to decode node: %s", err)
}
if !reflect.DeepEqual(treeMetadata, decoded) {
t.Fatalf("tree metadata %v != decoded tree metadata %v", treeMetadata, decoded)
}
}
func TestEncodeDecodeNode(t *testing.T) {
node := &node{
id: 42,
leaf: true,
parentID: 75,
keys: [][]byte{
{1, 2, 3, 4},
{5, 6, 7, 8},
nil,
},
pointers: []*pointer{
{uint32(42)},
{[]byte{1, 2, 3, 4}},
{uint32(17)},
},
keyNum: 2,
}
decoded, err := decodeNode(encodeNode(node))
if err != nil {
t.Fatalf("failed to decode node: %s", err)
}
if !reflect.DeepEqual(node, decoded) {
t.Fatalf("node %v != decoded node %v", node, decoded)
}
}