~telemachus/algorithms

fb191391624ddf8f29949589fea7e33c224193dd — Peter Aronoff 10 months ago 597d3c5
Start work on binary search tree
2 files changed, 46 insertions(+), 0 deletions(-)

A binarysearchtree.go
A binarysearchtree_test.go
A binarysearchtree.go => binarysearchtree.go +22 -0
@@ 0,0 1,22 @@
package algorithms

type Node struct {
	parent *Node
	lChild *Node
	rChild *Node
	Count int
	Value int
}

type Tree struct {
	root *Node
	size int
}

func NewBST() *Tree {
	return &Tree{}
}

func (t *Tree) Size() int {
	return t.size
}

A binarysearchtree_test.go => binarysearchtree_test.go +24 -0
@@ 0,0 1,24 @@
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)
	}
}