aboutsummaryrefslogtreecommitdiff
path: root/node_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-04-11 15:11:55 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-04-11 15:11:55 -0600
commit2c8020ec8e98e7b6c6c0fd3bd6e91d41caf7f25a (patch)
tree125c24e03c653417ce8bf5965b7fbcbeb2dedb04 /node_test.go
parentMerge pull request #128 from benbjohnson/import-export (diff)
parentUpgrade import/export to use nested buckets. (diff)
downloaddedo-2c8020ec8e98e7b6c6c0fd3bd6e91d41caf7f25a.tar.gz
dedo-2c8020ec8e98e7b6c6c0fd3bd6e91d41caf7f25a.tar.xz
Merge pull request #127 from benbjohnson/nested-keys
Add nested buckets.
Diffstat (limited to 'node_test.go')
-rw-r--r--node_test.go51
1 files changed, 26 insertions, 25 deletions
diff --git a/node_test.go b/node_test.go
index 8555223..e58a544 100644
--- a/node_test.go
+++ b/node_test.go
@@ -8,12 +8,12 @@ import (
)
// Ensure that a node can insert a key/value.
-func TestNodePut(t *testing.T) {
+func TestNode_put(t *testing.T) {
n := &node{inodes: make(inodes, 0)}
- n.put([]byte("baz"), []byte("baz"), []byte("2"), 0)
- n.put([]byte("foo"), []byte("foo"), []byte("0"), 0)
- n.put([]byte("bar"), []byte("bar"), []byte("1"), 0)
- n.put([]byte("foo"), []byte("foo"), []byte("3"), 0)
+ n.put([]byte("baz"), []byte("baz"), []byte("2"), 0, 0)
+ n.put([]byte("foo"), []byte("foo"), []byte("0"), 0, 0)
+ n.put([]byte("bar"), []byte("bar"), []byte("1"), 0, 0)
+ n.put([]byte("foo"), []byte("foo"), []byte("3"), 0, leafPageFlag)
assert.Equal(t, len(n.inodes), 3)
assert.Equal(t, n.inodes[0].key, []byte("bar"))
assert.Equal(t, n.inodes[0].value, []byte("1"))
@@ -21,10 +21,11 @@ func TestNodePut(t *testing.T) {
assert.Equal(t, n.inodes[1].value, []byte("2"))
assert.Equal(t, n.inodes[2].key, []byte("foo"))
assert.Equal(t, n.inodes[2].value, []byte("3"))
+ assert.Equal(t, n.inodes[2].flags, uint32(leafPageFlag))
}
// Ensure that a node can deserialize from a leaf page.
-func TestNodeReadLeafPage(t *testing.T) {
+func TestNode_read_LeafPage(t *testing.T) {
// Create a page.
var buf [4096]byte
page := (*page)(unsafe.Pointer(&buf[0]))
@@ -55,12 +56,12 @@ func TestNodeReadLeafPage(t *testing.T) {
}
// Ensure that a node can serialize into a leaf page.
-func TestNodeWriteLeafPage(t *testing.T) {
+func TestNode_write_LeafPage(t *testing.T) {
// Create a node.
n := &node{isLeaf: true, inodes: make(inodes, 0)}
- n.put([]byte("susy"), []byte("susy"), []byte("que"), 0)
- n.put([]byte("ricki"), []byte("ricki"), []byte("lake"), 0)
- n.put([]byte("john"), []byte("john"), []byte("johnson"), 0)
+ n.put([]byte("susy"), []byte("susy"), []byte("que"), 0, 0)
+ n.put([]byte("ricki"), []byte("ricki"), []byte("lake"), 0, 0)
+ n.put([]byte("john"), []byte("john"), []byte("johnson"), 0, 0)
// Write it to a page.
var buf [4096]byte
@@ -82,14 +83,14 @@ func TestNodeWriteLeafPage(t *testing.T) {
}
// Ensure that a node can split into appropriate subgroups.
-func TestNodeSplit(t *testing.T) {
+func TestNode_split(t *testing.T) {
// Create a node.
n := &node{inodes: make(inodes, 0)}
- n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0)
- n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0)
- n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0)
- n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0)
- n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0)
+ n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0, 0)
// Split between 2 & 3.
nodes := n.split(100)
@@ -100,11 +101,11 @@ func TestNodeSplit(t *testing.T) {
}
// Ensure that a page with the minimum number of inodes just returns a single node.
-func TestNodeSplitWithMinKeys(t *testing.T) {
+func TestNode_split_MinKeys(t *testing.T) {
// Create a node.
n := &node{inodes: make(inodes, 0)}
- n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0)
- n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0)
+ n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0, 0)
// Split.
nodes := n.split(20)
@@ -113,14 +114,14 @@ func TestNodeSplitWithMinKeys(t *testing.T) {
}
// Ensure that a node that has keys that all fit on a page just returns one leaf.
-func TestNodeSplitFitsInPage(t *testing.T) {
+func TestNode_split_SinglePage(t *testing.T) {
// Create a node.
n := &node{inodes: make(inodes, 0)}
- n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0)
- n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0)
- n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0)
- n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0)
- n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0)
+ n.put([]byte("00000001"), []byte("00000001"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000002"), []byte("00000002"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000003"), []byte("00000003"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000004"), []byte("00000004"), []byte("0123456701234567"), 0, 0)
+ n.put([]byte("00000005"), []byte("00000005"), []byte("0123456701234567"), 0, 0)
// Split.
nodes := n.split(4096)