2015-03-04 18:38:46 +00:00
|
|
|
package redblacktree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-03-04 18:46:09 +00:00
|
|
|
func TestPutGet(t *testing.T) {
|
2015-03-04 18:38:46 +00:00
|
|
|
|
|
|
|
tree := NewWithIntComparator()
|
|
|
|
|
|
|
|
tree.Put(3, "c")
|
|
|
|
tree.Put(4, "d")
|
|
|
|
tree.Put(1, "x")
|
|
|
|
tree.Put(2, "b")
|
2015-03-04 18:46:09 +00:00
|
|
|
tree.Put(1, "a") //overwrite
|
2015-03-04 18:38:46 +00:00
|
|
|
|
|
|
|
// key,expectedValue,expectedFound
|
|
|
|
tests := [][]interface{}{
|
|
|
|
{1, "a", true},
|
|
|
|
{2, "b", true},
|
|
|
|
{3, "c", true},
|
|
|
|
{4, "d", true},
|
|
|
|
{5, nil, false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
actualValue, actualFound := tree.Get(test[0])
|
|
|
|
if actualValue != test[1] || actualFound != test[2] {
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, test[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|