|
| 1 | +// ==================================================== |
| 2 | +// Data-Structures-with-Go Copyright(C) 2017 Furkan Türkal |
| 3 | +// This program comes with ABSOLUTELY NO WARRANTY; This is free software, |
| 4 | +// and you are welcome to redistribute it under certain conditions; See |
| 5 | +// file LICENSE, which is part of this source code package, for details. |
| 6 | +// ==================================================== |
| 7 | + |
| 8 | +package main |
| 9 | + |
| 10 | +import ( |
| 11 | + "reflect" |
| 12 | + "testing" |
| 13 | +) |
| 14 | + |
| 15 | +func TestBinarySearchTreeNew(t *testing.T) { |
| 16 | + var testDatas = []struct { |
| 17 | + Node *Node |
| 18 | + ArrayIn []int |
| 19 | + Test int |
| 20 | + Out int |
| 21 | + }{ |
| 22 | + {New(0), []int{20, 4, 15, 85}, 15, 15}, |
| 23 | + {New(3), []int{10, 20, 30, 40, 50}, 50, 50}, |
| 24 | + {New(7), []int{7}, 7, 7}, |
| 25 | + } |
| 26 | + |
| 27 | + for _, data := range testDatas { |
| 28 | + for i := 0; i < len(data.ArrayIn); i++ { |
| 29 | + Insert(data.Node, data.ArrayIn[i]) |
| 30 | + } |
| 31 | + |
| 32 | + actual := Search(data.Node, data.Test) |
| 33 | + |
| 34 | + expected := data.Out |
| 35 | + |
| 36 | + if !reflect.DeepEqual(expected, actual.data) { |
| 37 | + t.Errorf("BinarySearchTree: Expected: %d, Actual: %d", expected, actual) |
| 38 | + } |
| 39 | + } |
| 40 | +} |
0 commit comments