github.com/cosmtrek/supergo@v0.0.0-20171126040752-2bc610f32e46/trie/trie_test.go (about)

     1  package trie
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  )
     7  
     8  func TestTrieAdd(t *testing.T) {
     9  	tree := NewTrie()
    10  	v := "a"
    11  	tree.Add(v)
    12  	if !tree.Found(v) {
    13  		t.Errorf("Failed to found value %v", v)
    14  	}
    15  	if tree.Found("aa") {
    16  		t.Errorf("Actually there are no such value: %v", "aa")
    17  	}
    18  }
    19  
    20  func TestTrieDestroy(t *testing.T) {
    21  	tree := NewTrie()
    22  	v := "a"
    23  	tree.Add(v)
    24  	if tree.Empty() {
    25  		t.Error("Failed to add node")
    26  	}
    27  	tree.Destroy()
    28  	if !tree.Empty() {
    29  		t.Error("Failed to destroy the tree")
    30  	}
    31  }
    32  
    33  func BenchmarkAdd(b *testing.B) {
    34  	tree := NewTrie()
    35  	for i := 0; i < 100000000; i++ {
    36  		tree.Add(strconv.Itoa(i))
    37  	}
    38  }