aboutsummaryrefslogtreecommitdiffstats
path: root/trie.test.go
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2013-12-30 08:09:57 +0800
committerobscuren <obscuren@obscura.com>2013-12-30 08:09:57 +0800
commitf17930eb4661721cd0e1b92765448c589441907b (patch)
tree35def5092a0d704feb0c20f1d29b94452ebfd09c /trie.test.go
parenta926686445929d091c2d9e019b017600168e9e47 (diff)
downloadgo-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.gz
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.bz2
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.lz
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.xz
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.zst
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.zip
Split up db and trie and added interface
Diffstat (limited to 'trie.test.go')
-rw-r--r--trie.test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/trie.test.go b/trie.test.go
new file mode 100644
index 000000000..0a6054cf0
--- /dev/null
+++ b/trie.test.go
@@ -0,0 +1,61 @@
+package main
+
+import (
+ "testing"
+)
+
+type MemDatabase struct {
+ db map[string][]byte
+ trie *Trie
+}
+
+func NewMemDatabase() (*MemDatabase, error) {
+ db := &MemDatabase{db: make(map[string][]byte)}
+
+ db.trie = NewTrie(db)
+
+ return db, nil
+}
+
+func (db *MemDatabase) Put(key []byte, value []byte) {
+ db.db[string(key)] = value
+}
+
+func (db *MemDatabase) Get(key []byte) ([]byte, error) {
+ return db.db[string(key)], nil
+}
+
+func TestTriePut(t *testing.T) {
+ db, err := NewMemDatabase()
+
+ if err != nil {
+ t.Error("Error starting db")
+ }
+
+ key := db.trie.Put([]byte("testing node"))
+
+ data, err := db.Get(key)
+ if err != nil {
+ t.Error("Nothing at node")
+ }
+
+ s, _ := Decode(data, 0)
+ if str, ok := s.([]byte); ok {
+ if string(str) != "testing node" {
+ t.Error("Wrong value node", str)
+ }
+ } else {
+ t.Error("Invalid return type")
+ }
+}
+
+func TestTrieUpdate(t *testing.T) {
+ db, err := NewMemDatabase()
+
+ if err != nil {
+ t.Error("Error starting db")
+ }
+
+ db.trie.Update("test", "test")
+}
+