Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions BinaryTree.Test/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,63 @@ public void TestMethod3()
Node parent = bt.findParent(32);
Assert.AreEqual(47, parent.value);
}

/// <summary>
/// Creates a tree with negative values.
/// Expected to work the same as positive values.
/// </summary>
[TestMethod]
public void FindParent_NegativeValueTree_Success()
{
BSTree bt = new BSTree();
int[] arr1 = { -22, -5, -91, -2, -47, -13, -32, -45, -95 };

for (int i = 0; i < arr1.Length; i++)
{
bt.insert(arr1[i]);
}

Node parent = bt.findParent(-32);
Assert.AreEqual(-47, parent.value);
}

/// <summary>
/// Attempts to locate the parent node of a value that was not
/// given to the tree to manage. Expected return is null.
/// </summary>
[TestMethod]
public void FindParent_NonExistantValue_Null()
{
BSTree bt = new BSTree();
int[] arr1 = { 22, 5, 91, 2, 47, 13, 32, 45, 95 };

for (int i = 0; i < arr1.Length; i++)
{
bt.insert(arr1[i]);
}

Node parent = bt.findParent(-32);
// Assert.AreEqual(null, parent.value);
Assert.AreEqual(null, parent);
}


/// <summary>
/// Insert 10 equal values to create tree.
/// </summary>
[TestMethod]
public void Insert_SameValue_Success()
{
BSTree bt = new BSTree();
int[] arr1 = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 42 };

for (int i = 0; i < arr1.Length; i++)
{
bt.insert(arr1[i]);
}

var nodeCount = bt.count();
Assert.AreEqual(10, nodeCount);
}
}
}