/// <summary> /// Test removing an item from an empty array /// </summary> static void TestRemoveEmptyDynamicArray() { OrderedIntDynamicArray array = new OrderedIntDynamicArray(); System.Console.Write("TestRemoveEmptyDynamicArray: "); if (!array.Remove(42)) { 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() { OrderedIntDynamicArray array = new OrderedIntDynamicArray(); System.Console.Write("TestIndexOfEmptyDynamicArray: "); int actualIndex = array.IndexOf(42); 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() { OrderedIntDynamicArray array = new OrderedIntDynamicArray(); array.Add(42); System.Console.Write("TestAddEmptyDynamicArray: "); String arrayString = array.ToString(); if (arrayString.Equals("42") && array.Count == 1) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: 42 Actual: " + arrayString); } }
/// <summary> /// Test finding the index of an item at the back of the array /// </summary> static void TestIndexOfBackOfDynamicArray() { OrderedIntDynamicArray array = new OrderedIntDynamicArray(); array.Add(40); array.Add(41); array.Add(42); System.Console.Write("TestIndexOfBackOfDynamicArray: "); int actualIndex = array.IndexOf(42); if (actualIndex == 2) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: 2 Actual: " + actualIndex); } }
/// <summary> /// Test removing an item in the interior of the array /// </summary> static void TestRemoveItemInteriorOfDynamicArray() { OrderedIntDynamicArray array = new OrderedIntDynamicArray(); array.Add(40); array.Add(41); array.Add(42); System.Console.Write("TestRemoveItemInteriorOfDynamicArray: "); bool removed = array.Remove(41); String arrayString = array.ToString(); if (removed && arrayString.Equals("40,42") && array.Count == 2) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: 40,42 Actual: " + arrayString); } }
/// <summary> /// Test adding an item to an array that needs to be expanded. Also tests adding an item at /// the beginning of the array /// </summary> static void TestAddExpandDynamicArray() { OrderedIntDynamicArray array = new OrderedIntDynamicArray(); array.Add(42); array.Add(41); array.Add(40); array.Add(39); array.Add(38); array.Add(37); System.Console.Write("TestAddExpandedDynamicArray: "); String arrayString = array.ToString(); if (arrayString.Equals("37,38,39,40,41,42") && array.Count == 6) { System.Console.WriteLine("Passed"); } else { System.Console.WriteLine("FAILED!!! Expected: 37,38,39,40,41,42 Actual: " + arrayString); } }