diff --git a/binary-search-tree-1-insertion/binary-search-tree-1-insertion_test.go b/binary-search-tree-1-insertion/binary-search-tree-1-insertion_test.go new file mode 100644 index 0000000..6f43695 --- /dev/null +++ b/binary-search-tree-1-insertion/binary-search-tree-1-insertion_test.go @@ -0,0 +1,40 @@ +// ==================================================== +// Data-Structures-with-Go Copyright(C) 2017 Furkan Türkal +// This program comes with ABSOLUTELY NO WARRANTY; This is free software, +// and you are welcome to redistribute it under certain conditions; See +// file LICENSE, which is part of this source code package, for details. +// ==================================================== + +package main + +import ( + "reflect" + "testing" +) + +func TestBinarySearchTreeNew(t *testing.T) { + var testDatas = []struct { + Node *Node + ArrayIn []int + Test int + Out int + }{ + {New(0), []int{20, 4, 15, 85}, 15, 15}, + {New(3), []int{10, 20, 30, 40, 50}, 50, 50}, + {New(7), []int{7}, 7, 7}, + } + + for _, data := range testDatas { + for i := 0; i < len(data.ArrayIn); i++ { + Insert(data.Node, data.ArrayIn[i]) + } + + actual := Search(data.Node, data.Test) + + expected := data.Out + + if !reflect.DeepEqual(expected, actual.data) { + t.Errorf("BinarySearchTree: Expected: %d, Actual: %d", expected, actual) + } + } +}