public void FindShouldReturnMaxSumInLevelOfTree() { TreeDSNode rootNode = TreeTestData.GetComplexTreeRootNode(); MaxSumInLevelOfTree maxSumInLevelOfTree = new MaxSumInLevelOfTree(); var maxSum = maxSumInLevelOfTree.Find(rootNode); Assert.AreEqual(15, maxSum); }
public void ShouldReturnHeightUsinrNonRecussion() { TreeDSNode rootNode = TreeTestData.GetComplexTreeRootNode(); IAlgorithm <TreeDSNode, int> heightOfTree = new HeightOfTree(); var height = heightOfTree.UsingNonRecursion(rootNode); Assert.AreEqual(4, height); }
public void ShouldReturnDeepestNode() { TreeDSNode rootNode = TreeTestData.GetComplexTreeRootNode(); DeepestNodeOfTree deepestNodeOfTree = new DeepestNodeOfTree(); var deepestNode = deepestNodeOfTree.Find(rootNode); Assert.AreEqual(8, deepestNode.Value); }
public void ShouldReturnDiameterOfTree() { TreeDSNode rootNode = TreeTestData.GetComplexTreeRootNode(); DiameterOfTree diameterOfTree = new DiameterOfTree(); var diameter = diameterOfTree.Find(rootNode); Assert.AreEqual(6, diameter); }
public void ShouldReturnFullNodesCount() { TreeDSNode rootNode = TreeTestData.GetComplexTreeRootNode(); TreeNodesType treeNodesType = new TreeNodesType(); var fullNodesCount = treeNodesType.FullNodesCount(rootNode); Assert.AreEqual(3, fullNodesCount); }
public void ShouldReturnLeafNodesCount() { TreeDSNode rootNode = TreeTestData.GetComplexTreeRootNode(); TreeNodesType treeNodesType = new TreeNodesType(); var leafNodesCount = treeNodesType.LeaftNodesCount(rootNode); Assert.AreEqual(4, leafNodesCount); }
public void ShouldReturnTrueIfSumExistInPathOfTree() { var rootNode = TreeTestData.GetComplexTreeRootNode(); var existenceOfSumInPathOfTree = new ExistenceOfSumInPathOfTree(); var isExist = existenceOfSumInPathOfTree.Check(rootNode, 15); Assert.AreEqual(true, isExist); }
public void ShouldReturnSumUsingNonRecussion() { var rootNode = TreeTestData.GetComplexTreeRootNode(); var sumAllNode = new SumAllNodesInTree(); var sum = sumAllNode.UsingNonRecursion(rootNode); Assert.AreEqual(36, sum); }
public void ShouldReturnMaxNodeInNonRecursion() { TreeDSNode rootNode = TreeTestData.GetComplexTreeRootNode(); FindMaxElement findMaxNode = new FindMaxElement(); var maxNode = findMaxNode.UsingNonRecursion(rootNode); Assert.AreEqual(8, maxNode.Value); }
public void ShouldReturnFalseValidateMirrorImageTree() { var rootNode = TreeTestData.GetComplexTreeRootNode(); var mirrorImageRootNode = TreeTestData.GetComplexTreeRootNode(); var MirrorImageTree = new MirrorImageOfTree(); var isValid = MirrorImageTree.Validate(rootNode, mirrorImageRootNode); Assert.IsFalse(isValid); }
public void ShouldReturnTrueIfTwoTreeStructuresAreSame() { TreeDSNode rootNodeOfFirstTree = TreeTestData.GetComplexTreeRootNode(); TreeDSNode rootNodeOfSecondTree = TreeTestData.GetRootNodeOfComplexTreeWithHighervalue(); var structuralIdentification = new StructuralIdentification(); var structuralIdentificationResult = structuralIdentification.Validate(rootNodeOfFirstTree, rootNodeOfSecondTree); Assert.AreEqual(true, structuralIdentificationResult); }
public void ShouldReturnFalseIfTwoTreeStructuresAreNotIdentical() { TreeDSNode rootNodeOfFirstTree = TreeTestData.GetComplexTreeRootNode(); TreeDSNode rootNodeOfSecondTree = TreeTestData.GetLeftSplayTreeRootNode(); var structuralIdentification = new StructuralIdentification(); var structuralIdentificationResult = structuralIdentification.Validate(rootNodeOfFirstTree, rootNodeOfSecondTree); Assert.AreEqual(false, structuralIdentificationResult); }
public void ShouldReturnRootOfMirrorImageTree() { var rootNode = TreeTestData.GetComplexTreeRootNode(); var expectedRootTree = TreeTestData.GetRootNodeOfComplexTreeMirror(); var MirrorImageTree = new MirrorImageOfTree(); var actualRoot = MirrorImageTree.Create(rootNode); var structuralIdentification = new StructuralIdentification(); var isIdentical = structuralIdentification.ValidateWithValue(rootNode, expectedRootTree); Assert.IsTrue(isIdentical); }
public void ShouldPrintTreeInLevelOrderForComplexTree() { var expectedOutputs = new List <int>() { 8, 7, 6, 5, 4, 3, 2, 1 }; IConsoleWriter writerMock = MockWriter.GetInstance(expectedOutputs); var rootNode = TreeTestData.GetComplexTreeRootNode(); var levelOrderTraversalInReverse = new LevelOrderTraversalInReverse(writerMock); levelOrderTraversalInReverse.Print(rootNode); }
public void ShouldReturnLeastCommonAncestor() { var rootNode = TreeTestData.GetComplexTreeRootNode(); var nodeWithValue4 = TreeDSNode.Create(4); var nodeWithValue5 = TreeDSNode.Create(5); var nodeWithValue3 = TreeDSNode.Create(3); LeastCommonAncestor leastCommonAncestor = new LeastCommonAncestor(); var actualLCA = leastCommonAncestor.Find(rootNode, nodeWithValue4, nodeWithValue5); Assert.AreEqual(2, actualLCA.Value); actualLCA = leastCommonAncestor.Find(rootNode, nodeWithValue4, nodeWithValue3); Assert.AreEqual(1, actualLCA.Value); }