public void TestRemove() { // The first array in the tuple represents the contents of // the list before calling 'Remove', the second array is // the list after calling 'Remove'. The third element of // the tuple represents the value to be removed from the // list. Tuple <int[], int[], int>[] test_vectors = { new Tuple <int[], int[], int>( new int[] { }, new int[] { }, 5), new Tuple <int[], int[], int>( new int[] { -2, 9, 0 }, new int[] { -2, 9, 0 }, 6), new Tuple <int[], int[], int>( new int[] { 6 }, new int[] { }, 6), new Tuple <int[], int[], int>( new int[] { -2, 5, 0 }, new int[] { -2, 0 }, 5), new Tuple <int[], int[], int>( new int[] { 4, 4,4, 4, 4 }, new int[] { }, 4), new Tuple <int[], int[], int>( new int[] { -3, 5,6, 7, -3 }, new int[] { 5, 6, 7 }, -3), new Tuple <int[], int[], int>( new int[] { 10, 2,5, 6, 2, 2, 2 }, new int[] { 10, 5, 6 }, 2), new Tuple <int[], int[], int>( new int[] { -1, 0,0, 5, -1, 9 }, new int[] { 0, 0,5, 9 }, -1), }; foreach (Tuple <int[], int[], int> test_vector in test_vectors) { var list = new DoubleEndedLinkedList <int>(); // Populate the list with the items from Tuple.Item1 foreach (int value in test_vector.Item1) { list.PushBack(value); } // Remove Tuple.Item3 value from the list list.Remove(test_vector.Item3); // Verify that the contents of the list is equal to Tuple.Item2 Assert.AreEqual(test_vector.Item2.Length, list.Size); int index = 0; foreach (int value in list) { Assert.AreEqual(test_vector.Item2[index++], value); } // Also verify that IsEmpty and Size return correct values Assert.AreEqual(test_vector.Item2.Length, list.Size); Assert.AreEqual(test_vector.Item2.Length == 0, list.IsEmpty()); // Finally, verify that PeakFront and PeakBack return expected // values if (!list.IsEmpty()) { Assert.AreEqual(test_vector.Item2[0], list.PeakFront()); Assert.AreEqual(test_vector.Item2[test_vector.Item2.Length - 1], list.PeakBack()); } } }
public void PeakFrontThrowsIfCalledOnEmptyList() { var list = new DoubleEndedLinkedList <int>(); Assert.Throws <IndexOutOfRangeException>(() => list.PeakFront()); }