public void CorrectlyCountsGoodNodesTestCase01() { const int expectedResult = 4; var binaryTree = BinaryTreeManager.Create(new int?[] { 5, 3, 10, 20, 21, 1, null }); TestImplementations(binaryTree.Root, expectedResult); }
public void IsCorrectlyDoneInLevelOrderTestCase10() { var expectedTraversal = new char?[] { 'D', 'B', 'F', 'A' }; // D // / \ // / \ // / \ // B F // / // A var binaryTree1 = BinaryTreeManager.Create(new char?[] { 'D', 'B', 'F', 'A' }); TestImplementations(binaryTree1.Root, expectedTraversal); var binaryTree2 = BinaryTreeManager.Create(new char?[] { 'D', 'B', 'F', 'A', null }); TestImplementations(binaryTree2.Root, expectedTraversal); var binaryTree3 = BinaryTreeManager.Create(new char?[] { 'D', 'B', 'F', 'A', null, null }); TestImplementations(binaryTree3.Root, expectedTraversal); var binaryTree4 = BinaryTreeManager.Create(new char?[] { 'D', 'B', 'F', 'A', null, null, null }); TestImplementations(binaryTree4.Root, expectedTraversal); }
public void IsCorrectlyDoneInLevelOrderTestCase01() { var binaryTree = BinaryTreeManager.Create(new char?[0]); var expectedTraversal = new char?[0]; TestImplementations(binaryTree.Root, expectedTraversal); }
public BinaryTreeMaximumElementsByLevelSearch() { TypeToTest = typeof(FindBinaryTreeMaximumElementsByLevel); // 1 // / \ // / \ // 3 2 // / \ \ // 5 3 9 _binaryTree1 = BinaryTreeManager.Create(new int?[] { 1, 3, 2, 5, 3, null, 9 }); // 3 // / // 4 // \ // 5 // / // 2 // \ // 1 _binaryTree2 = BinaryTreeManager.Create(new int?[] { 3, 4, null, null, 5, 2, null, null, 1 }); // -9 // / \ // / \ // / \ // -6 -70 // / \ / \ // -15 -6 -2 -8 // / // -3 _binaryTree3 = BinaryTreeManager.Create(new int?[] { -9, -6, -70, -15, -6, -2, -8, -3, null }); }
public void ReturnsNullTestCase01() { // 2 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 2 }); TestImplementations(binarySearchTree.Root, null); }
public void CorrectlyCountsGoodNodesTestCase02() { const int expectedResult = 2; var binaryTree = BinaryTreeManager.Create(new int?[] { 8, 2, 6, 8, 7 }); TestImplementations(binaryTree.Root, expectedResult); }
public void ReturnsClosestValueTestCase01() { // 9 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 9 }); const int target = 100; const int expectedResult = 9; TestImplementations(binarySearchTree.Root, target, expectedResult); }
public void ReturnsFirstSmallestElementOfASingleNodeTree() { // 2 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 2 }); const int k = 1; const int expectedResult = 2; TestImplementations(binarySearchTree.Root, k, expectedResult); }
public void ReturnsSecondMaximumElementTestCase02() { // 2 // / \ // / \ // -2 5 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 2, -2, 5 }); const int expectedResult = 2; TestImplementations(binarySearchTree.Root, expectedResult); }
private void TestImplementations(IReadOnlyCollection <int?> nodesData, IReadOnlyCollection <int?> expectedResults) { foreach (var implementation in ImplementationsToTest()) { var binaryTree = BinaryTreeManager.Create(nodesData); var nodeActualResult = (BinaryNode <int>)implementation.Invoke(null, new object[] { binaryTree.Root }); var actualResults = new List <int?>(); TraverseBinaryTreeInBreadthFirstSearchWay <int> .Visit = node => actualResults.Add(node?.Data); TraverseBinaryTreeInBreadthFirstSearchWay <int> .IterativeImplementation(nodeActualResult); actualResults.TrimTrailingNulls().ShouldBe(expectedResults); } }
public void ReturnsSecondMaximumElementTestCase06() { // 25 // \ // 50 // / // 37 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 25, null, 50, 37, null }); const int expectedResult = 37; TestImplementations(binarySearchTree.Root, expectedResult); }
public void IsCorrectlyDoneInLevelOrderTestCase06() { // D // / \ // / \ // / \ // B F // / \ // E G var binaryTree = BinaryTreeManager.Create(new char?[] { 'D', 'B', 'F', null, null, 'E', 'G' }); var expectedTraversal = new char?[] { 'D', 'B', 'F', null, null, 'E', 'G' }; TestImplementations(binaryTree.Root, expectedTraversal); }
public void ReturnsClosestValueTestCase05() { // 10 // / \ // / \ // 5 15 // / \ / \ // 2 5 13 22 // / \ // 1 14 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 10, 5, 15, 2, 5, 13, 22, 1, null, null, 14 }); const int target = 12; const int expectedResult = 13; TestImplementations(binarySearchTree.Root, target, expectedResult); }
public BinaryTreeDepthFirstSearchTraversal() { TypeToTest = typeof(TraverseBinaryTreeInDepthFirstSearchWay <char>); // F // / \ // / \ // / \ // B G // / \ \ // A D I // / \ / // C E H _binaryTree = BinaryTreeManager.Create(new char?[] { 'F', 'B', 'G', 'A', 'D', null, 'I', null, null, 'C', 'E', 'H', null }); }
public void ReturnsSecondMaximumElementTestCase04() { // 50 // / // 25 // / // 12 // \ // 24 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 50, 25, null, 12, null, null, 24 }); const int expectedResult = 25; TestImplementations(binarySearchTree.Root, expectedResult); }
public void IsCorrectlyDoneInLevelOrderTestCase03() { // F // / \ // / \ // / \ // B G // / \ \ // A D I // / \ / // C E H var binaryTree = BinaryTreeManager.Create(new char?[] { 'F', 'B', 'G', 'A', 'D', null, 'I', null, null, 'C', 'E', 'H', null }); var expectedTraversal = new char?[] { 'F', 'B', 'G', 'A', 'D', null, 'I', null, null, 'C', 'E', 'H' }; TestImplementations(binaryTree.Root, expectedTraversal); }
public void ReturnsClosestValueTestCase04() { // 9 // / \ // / \ // 4 17 // / \ \ // 3 6 22 // / \ / // 5 7 20 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 9, 4, 17, 3, 6, null, 22, null, null, 5, 7, 20 }); const int target = 12; const int expectedResult = 9; TestImplementations(binarySearchTree.Root, target, expectedResult); }
public BinarySearchTreeKthSmallestElementSearch() { TypeToTest = typeof(FindBinarySearchTreeKthSmallestElement); // 50 // / \ // / \ // / \ // 25 100 // / \ // 12 200 // \ / // 18 150 // / \ / \ // 15 21 125 175 _bigTree = BinaryTreeManager.Create(new int?[] { 50, 25, 100, 12, null, null, 200, null, 18, 150, null, 15, 21, 125, 175 }); }
public void ReturnsSecondMaximumElementTestCase05() { // 50 // / // 25 // / \ // 12 37 // / \ // 27 49 // / \ // 26 36 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 50, 25, null, 12, 37, null, null, 27, 49, 26, 36 }); const int expectedResult = 49; TestImplementations(binarySearchTree.Root, expectedResult); }
public void ReturnsSecondMaximumElementTestCase03() { // 5 // / \ // / \ // 3 8 // / \ / \ // 1 4 7 12 // / // 10 // / \ // 9 11 var binarySearchTree = BinaryTreeManager.Create(new int?[] { 5, 3, 8, 1, 4, 7, 12, null, null, null, null, null, null, 10, null, 9, 11 }); const int expectedResult = 11; TestImplementations(binarySearchTree.Root, expectedResult); }
public BinaryTreeMaximumElementSearch() { TypeToTest = typeof(FindBinaryTreeMaximumElement); // 5 // / \ // / \ // 4 7 // \ \ // 18 8 _binaryTree1 = BinaryTreeManager.Create(new int?[] { 5, 4, 7, null, 18, null, 8 }); // -9 // / \ // / \ // / \ // -6 -70 // / \ / \ // -15 -6 -2 -8 // / // -3 _binaryTree2 = BinaryTreeManager.Create(new int?[] { -9, -6, -70, -15, -6, -2, -8, -3, null }); }