public void GenericBinaryTree_AddRandomElementsAndDeleteThem() { TestObject_Integer[] testObjectArray_01 = new TestObject_Integer[100000]; TestObject_Integer[] testObjectArray_02 = new TestObject_Integer[100000]; for (int i = 0; i < testObjectArray_01.Length; i++) { testObjectArray_01[i] = new TestObject_Integer(i); testObjectArray_02[i] = new TestObject_Integer(i); } testObjectArray_01 = CollectionManipulation.RandomizeGenericArray<TestObject_Integer>(testObjectArray_01); System.Threading.Thread.Sleep(100); testObjectArray_02 = CollectionManipulation.RandomizeGenericArray<TestObject_Integer>(testObjectArray_02); GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); bool addResult = true; for (int i = 0; i < testObjectArray_01.Length; i++) { if (!testTree.Add(testObjectArray_01[i])) { addResult = false; } } Assert.IsTrue(addResult, "addResult"); Assert.IsFalse(testTree.HasErrors, "HasErrors"); bool deleteResult = true; for (int i = 0; i < testObjectArray_02.Length; i++) { if (!testTree.Delete(testObjectArray_02[i])) { deleteResult = false; } } Assert.IsTrue(deleteResult, "deleteResult"); Assert.IsFalse(testTree.HasErrors, "HasErrors"); Assert.IsNull(testTree.RootNode, "RootNode"); }
public void Contains_6_True() { bool containsResult = false; GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); testTree.Add(new TestObject_Integer(4)); testTree.Add(new TestObject_Integer(2)); testTree.Add(new TestObject_Integer(6)); testTree.Add(new TestObject_Integer(1)); testTree.Add(new TestObject_Integer(3)); testTree.Add(new TestObject_Integer(5)); testTree.Add(new TestObject_Integer(7)); containsResult = testTree.Contains(new TestObject_Integer(6)); Assert.IsTrue(containsResult, "ContainsResult"); Assert.IsFalse(testTree.IsEmpty, "IsEmpty"); Assert.IsFalse(testTree.HasErrors, "HasErrors"); Assert.IsNotNull(testTree.ParentNode, "ParentNode"); Assert.IsNotNull(testTree.CurrentNode, "CurrentNode"); Assert.IsNotNull(testTree.LeftGrandChild, "LeftGrandChild"); Assert.IsNotNull(testTree.RightGrandChild, "RightGrandChild"); Assert.AreEqual(4, testTree.ParentNode.Item.Value); Assert.AreEqual(6, testTree.CurrentNode.Item.Value); Assert.AreEqual(5, testTree.LeftGrandChild.Item.Value); Assert.AreEqual(7, testTree.RightGrandChild.Item.Value); }
public void Add_4_2_1_3_Delete_1() { bool deleteResult = false; GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); testTree.Add(new TestObject_Integer(4)); testTree.Add(new TestObject_Integer(2)); testTree.Add(new TestObject_Integer(1)); testTree.Add(new TestObject_Integer(3)); deleteResult = testTree.Delete(new TestObject_Integer(1)); Assert.IsTrue(deleteResult, "DeleteResult"); Assert.IsFalse(testTree.HasErrors, "HasErrors"); Assert.IsNotNull(testTree.ParentNode, "ParentNode"); Assert.IsNull(testTree.CurrentNode, "CurrentNode"); Assert.IsNull(testTree.LeftGrandChild, "LeftGrandChild"); Assert.IsNull(testTree.RightGrandChild, "RightGrandChild"); Assert.AreEqual(2, testTree.ParentNode.Item.Value, "ParentNode"); }
public void Clear_IsNotEmpty() { GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); testTree.Add(new TestObject_Integer(4)); testTree.Add(new TestObject_Integer(2)); testTree.Add(new TestObject_Integer(6)); testTree.Add(new TestObject_Integer(1)); testTree.Add(new TestObject_Integer(3)); testTree.Add(new TestObject_Integer(5)); testTree.Add(new TestObject_Integer(7)); testTree.Add(null); testTree.Clear(); Assert.IsTrue(testTree.IsEmpty, "IsEmpty"); Assert.IsFalse(testTree.HasErrors, "HasErrors"); Assert.IsNull(testTree.RootNode, "RootNode"); Assert.IsNull(testTree.ParentNode, "ParentNode"); Assert.IsNull(testTree.CurrentNode, "CurrentNode"); Assert.IsNull(testTree.LeftGrandChild, "LeftGrandChild"); Assert.IsNull(testTree.RightGrandChild, "RightGrandChild"); }
public void Add_4_6_5_7_6() { bool addResult = false; GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); addResult = testTree.Add(new TestObject_Integer(4)); addResult = testTree.Add(new TestObject_Integer(6)); addResult = testTree.Add(new TestObject_Integer(5)); addResult = testTree.Add(new TestObject_Integer(7)); addResult = testTree.Add(new TestObject_Integer(6)); Assert.IsFalse(addResult); Assert.IsTrue(testTree.HasErrors); Assert.AreEqual(4, testTree.ParentNode.Item.Value); Assert.AreEqual(6, testTree.CurrentNode.Item.Value); Assert.AreEqual(5, testTree.LeftGrandChild.Item.Value); Assert.AreEqual(7, testTree.RightGrandChild.Item.Value); }
public void Add_4_Delete_4() { GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); bool deleteResult = false; testTree.Add(new TestObject_Integer(4)); deleteResult = testTree.Delete(new TestObject_Integer(4)); Assert.IsTrue(deleteResult, "DeleteResult"); Assert.IsFalse(testTree.HasErrors, "HasErrors"); Assert.IsNull(testTree.RootNode, "RootNode"); Assert.IsNull(testTree.ParentNode, "ParentNode"); Assert.IsNull(testTree.CurrentNode, "CurrentNode"); Assert.IsNull(testTree.LeftGrandChild, "LeftGrandChild"); Assert.IsNull(testTree.RightGrandChild, "RightGrandChild"); }
public void Add_4_2_3_1_2() { bool addResult = false; GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); addResult = testTree.Add(new TestObject_Integer(4)); addResult = testTree.Add(new TestObject_Integer(2)); addResult = testTree.Add(new TestObject_Integer(3)); addResult = testTree.Add(new TestObject_Integer(1)); addResult = testTree.Add(new TestObject_Integer(2)); Assert.IsFalse(addResult); Assert.IsTrue(testTree.HasErrors); Assert.AreEqual(4, testTree.ParentNode.Item.Value); Assert.AreEqual(2, testTree.CurrentNode.Item.Value); Assert.AreEqual(1, testTree.LeftGrandChild.Item.Value); Assert.AreEqual(3, testTree.RightGrandChild.Item.Value); }
public void Add_4_2_3() { bool addResult = false; GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); addResult = testTree.Add(new TestObject_Integer(4)); addResult = testTree.Add(new TestObject_Integer(2)); addResult = testTree.Add(new TestObject_Integer(3)); Assert.IsTrue(addResult); Assert.IsNotNull(testTree.ParentNode); Assert.AreEqual(2, testTree.ParentNode.Item.Value, testTree.GetNodeComposition()); Assert.IsNotNull(testTree.CurrentNode); Assert.AreEqual(3, testTree.CurrentNode.Item.Value, testTree.GetNodeComposition()); Assert.IsNull(testTree.LeftGrandChild); Assert.IsNull(testTree.RightGrandChild); }
public void Add_null() { GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); bool addResult = testTree.Add(null); Assert.IsTrue(testTree.IsEmpty); Assert.IsFalse(addResult); Assert.IsTrue(testTree.HasErrors); }
public void Traverse_PostOrder() { GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); TestObject_TraversalMethodSource testHandler = new TestObject_TraversalMethodSource(); GenericBinaryTree<TestObject_Integer>.HandleItem testDelegate = testHandler.HandleNode; testTree.Add(new TestObject_Integer(4)); testTree.Add(new TestObject_Integer(2)); testTree.Add(new TestObject_Integer(6)); testTree.Add(new TestObject_Integer(1)); testTree.Add(new TestObject_Integer(3)); testTree.Add(new TestObject_Integer(5)); testTree.Add(new TestObject_Integer(7)); bool traverseResult = false; traverseResult = testTree.Traverse(TraverseType.PostOrder, testDelegate); string expectedResult = "1325764"; Assert.IsTrue(traverseResult); Assert.IsFalse(testTree.HasErrors); Assert.AreEqual(expectedResult, testHandler.ToString()); }
public void Traverse_None() { GenericBinaryTree<TestObject_Integer> testTree = new GenericBinaryTree<TestObject_Integer>(); TestObject_TraversalMethodSource testHandler = new TestObject_TraversalMethodSource(); GenericBinaryTree<TestObject_Integer>.HandleItem testDelegate = testHandler.HandleNode; testTree.Add(new TestObject_Integer(4)); testTree.Add(new TestObject_Integer(2)); testTree.Add(new TestObject_Integer(6)); testTree.Add(new TestObject_Integer(1)); testTree.Add(new TestObject_Integer(3)); testTree.Add(new TestObject_Integer(5)); testTree.Add(new TestObject_Integer(7)); bool traverseResult = true; traverseResult = testTree.Traverse(TraverseType.None, testDelegate); Assert.IsFalse(traverseResult); Assert.IsTrue(testTree.HasErrors); }