From 9bc5c4a0c5116cf3b49a55fc2aceb5f5c3b3e34d Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 20 Feb 2014 14:40:00 +0100 Subject: Long over due Trie delete implemented --- ethutil/trie_test.go | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'ethutil/trie_test.go') diff --git a/ethutil/trie_test.go b/ethutil/trie_test.go index fa60c8cfc..9d2c8e19f 100644 --- a/ethutil/trie_test.go +++ b/ethutil/trie_test.go @@ -1,8 +1,7 @@ package ethutil import ( - _ "encoding/hex" - _ "fmt" + "reflect" "testing" ) @@ -116,3 +115,36 @@ func TestTrieCmp(t *testing.T) { t.Errorf("Expected tries not to be equal %x %x", trie1.Root, trie2.Root) } } + +func TestTrieDelete(t *testing.T) { + _, trie := New() + trie.Update("cat", LONG_WORD) + exp := trie.Root + trie.Update("dog", LONG_WORD) + trie.Delete("dog") + if !reflect.DeepEqual(exp, trie.Root) { + t.Errorf("Expected tries to be equal %x : %x", exp, trie.Root) + } + + trie.Update("dog", LONG_WORD) + exp = trie.Root + trie.Update("dude", LONG_WORD) + trie.Delete("dude") + if !reflect.DeepEqual(exp, trie.Root) { + t.Errorf("Expected tries to be equal %x : %x", exp, trie.Root) + } +} + +func TestTrieDeleteWithValue(t *testing.T) { + _, trie := New() + trie.Update("c", LONG_WORD) + exp := trie.Root + trie.Update("ca", LONG_WORD) + trie.Update("cat", LONG_WORD) + trie.Delete("ca") + trie.Delete("cat") + if !reflect.DeepEqual(exp, trie.Root) { + t.Errorf("Expected tries to be equal %x : %x", exp, trie.Root) + } + +} -- cgit v1.2.3