/// <summary> /// Test getting the count for an empty array /// </summary> static void TestCountEmptyDynamicArray() { UnorderedDynamicArray <String> array = new UnorderedDynamicArray <String>(); System.Console.Write("TestCountEmptyDynamicArray: "); if (array.Count == 0) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: 0 Actual: " + array.Count); } }
/// <summary> /// Test removing an item from an empty array /// </summary> static void TestRemoveEmptyDynamicArray() { UnorderedDynamicArray <String> array = new UnorderedDynamicArray <String>(); System.Console.Write("TestRemoveEmptyDynamicArray: "); if (!array.Remove("Foxtrot")) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: false Actual: true"); } }
/// <summary> /// Test finding the index of an item in an empty array /// </summary> static void TestIndexOfEmptyDynamicArray() { UnorderedDynamicArray <String> array = new UnorderedDynamicArray <String>(); System.Console.Write("TestIndexOfEmptyDynamicArray: "); int actualIndex = array.IndexOf("Foxtrot"); if (actualIndex == -1) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: -1 Actual: " + actualIndex); } }
/// <summary> /// Test adding an item to an empty array /// </summary> static void TestAddEmptyDynamicArray() { UnorderedDynamicArray <String> array = new UnorderedDynamicArray <String>(); array.Add("Foxtrot"); System.Console.Write("TestAddEmptyDynamicArray: "); String arrayString = array.ToString(); if (arrayString.Equals("Foxtrot") && array.Count == 1) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: Foxtrot Actual: " + arrayString); } }
/// <summary> /// Test finding the index of an item at the back of the array /// </summary> static void TestIndexOfBackOfDynamicArray() { UnorderedDynamicArray <String> array = new UnorderedDynamicArray <String>(); array.Add("Foxtrot"); array.Add("Echo"); array.Add("Delta"); System.Console.Write("TestIndexOfBackOfDynamicArray: "); int actualIndex = array.IndexOf("Delta"); if (actualIndex == 2) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: 2 Actual: " + actualIndex); } }
/// <summary> /// Test clearing a non-empty array /// </summary> static void TestClearNonemptyDynamicArray() { UnorderedDynamicArray <String> array = new UnorderedDynamicArray <String>(); array.Add("Foxtrot"); array.Add("Echo"); array.Add("Delta"); array.Add("Charlie"); array.Add("Bravo"); array.Add("Alpha"); System.Console.Write("TestClearNonemptyDynamicArray: "); array.Clear(); if (array.Count == 0) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: 0 Actual: " + array.Count); } }
/// <summary> /// Test removing an item in the interior of the array /// </summary> static void TestRemoveItemInteriorOfDynamicArray() { UnorderedDynamicArray <String> array = new UnorderedDynamicArray <String>(); array.Add("Foxtrot"); array.Add("Echo"); array.Add("Delta"); System.Console.Write("TestRemoveItemInteriorOfDynamicArray: "); bool removed = array.Remove("Echo"); String arrayString = array.ToString(); if (removed && arrayString.Equals("Foxtrot,Delta") && array.Count == 2) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: Foxtrot,Delta Actual: " + arrayString); } }
/// <summary> /// Test adding an item to an array that needs to be expanded /// </summary> static void TestAddExpandDynamicArray() { UnorderedDynamicArray <String> array = new UnorderedDynamicArray <String>(); array.Add("Foxtrot"); array.Add("Echo"); array.Add("Delta"); array.Add("Charlie"); array.Add("Bravo"); array.Add("Alpha"); System.Console.Write("TestAddExpandedDynamicArray: "); String arrayString = array.ToString(); if (arrayString.Equals("Foxtrot,Echo,Delta,Charlie,Bravo,Alpha") && array.Count == 6) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: Foxtrot,Echo,Delta,Charlie,Bravo,Alpha Actual: " + arrayString); } }