~telemachus/algorithms

ref: 7efe7ef5bf2ecd1d8f8111e31064af0296325e03 algorithms/binarysearchtree_test.go -rw-r--r-- 692 bytes
7efe7ef5Peter Aronoff Add Insert and Walk functions 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package algorithms_test

import (
	"fmt"
	"testing"

	"git.sr.ht/~telemachus/algorithms"
)

func TestNewBST(t *testing.T) {
	tree := algorithms.NewBST()

	if tree == nil {
		t.Errorf("tree is nil, but it shouldn’t be")
	}
	if 0 != tree.Size() {
		t.Errorf("expected tree.Size() to be 0; actual: %d", tree.Size())
	}
	expected := "*algorithms.Tree"
	actual := fmt.Sprintf("%T", tree)
	if expected != actual {
		t.Errorf("expected %s; actual %s", expected, actual)
	}
}

func TestTreeInsert(t *testing.T) {
	tree := algorithms.NewBST()
	
	tree.Insert(2)
	tree.Insert(10)
	tree.Insert(-15)

	if 3 != tree.Size() {
		t.Errorf("inserted three items; actual tree.Size() is %d", tree.Size())
	}
}