public void Test_DFS(int[] arrInit, int valueToFind, int[] arrExpected, bool IsException) { //Arrange BTree tree = new BTree(); for (int i = 0; i < arrInit.Length; i++) { tree.AddItem(arrInit[i]); } //Act //Assert if (IsException) { Action act = () => BTreeSearch.DFS(null, valueToFind); Assert.Throws <ArgumentNullException>(act); } else { var result = BTreeSearch.DFS(tree.GetRoot(), valueToFind); Assert.Equal(valueToFind, result.ResultValue.Data); for (int i = 0; i < arrExpected.Length; i++) { Assert.Equal(arrExpected[i], result.TreeInLine[i].Node.Data); } } }
static void Main(string[] args) { BTree bTree = new BTree(); bTree.AddItem(10); bTree.AddItem(5); bTree.AddItem(15); bTree.AddItem(2); bTree.AddItem(7); bTree.AddItem(12); bTree.AddItem(17); bTree.AddItem(1); bTree.AddItem(3); bTree.AddItem(6); bTree.AddItem(8); bTree.AddItem(11); bTree.AddItem(13); bTree.AddItem(16); bTree.AddItem(18); BTreePrinter.Print(bTree.GetRoot(), 0, 32); var b = BTreeSearch.BFS(bTree.GetRoot(), 18); var d = BTreeSearch.DFS(bTree.GetRoot(), 18); }