public void TestInsertRemove() { FWList <int> list = new FWList <int>(); for (int i = 0; i <= 12; i++) { list.Insert(i, i); } ExpectList(list, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); for (int i = 1; i <= 6; i++) { list.RemoveAt(i); } ExpectList(list, 0, 2, 4, 6, 8, 10, 12); Assert.AreEqual(0, list.Pop()); list.Insert(5, -2); ExpectList(list, 2, 4, 6, 8, 10, -2, 12); list.Insert(5, -1); ExpectList(list, 2, 4, 6, 8, 10, -1, -2, 12); list.Remove(-1); list.Remove(12); list[list.Count - 1] = 12; ExpectList(list, 2, 4, 6, 8, 10, 12); // Make sure FWList.Clear doesn't disturb FVList FVList <int> v = list.WithoutFirst(4); list.Clear(); ExpectList(list); ExpectList(v, 10, 12); // Some simple InsertRange calls where some immutable items must be // converted to mutable FVList <int> oneTwo = new FVList <int>(1, 2); FVList <int> threeFour = new FVList <int>(3, 4); list = oneTwo.ToFWList(); list.InsertRange(1, threeFour); ExpectList(list, 1, 3, 4, 2); list = threeFour.ToFWList(); list.InsertRange(2, oneTwo); ExpectList(list, 3, 4, 1, 2); // More tests... list.RemoveRange(0, 2); ExpectList(list, 1, 2); list.InsertRange(2, new int[] { 3, 3, 4, 4, 4, 5, 6, 7, 8, 9 }); ExpectList(list, 1, 2, 3, 3, 4, 4, 4, 5, 6, 7, 8, 9); list.RemoveRange(3, 3); ExpectList(list, 1, 2, 3, 4, 5, 6, 7, 8, 9); v = list.ToFVList(); list.RemoveRange(5, 4); ExpectList(list, 1, 2, 3, 4, 5); ExpectList(v, 1, 2, 3, 4, 5, 6, 7, 8, 9); }
public void TestEmptyListOperations() { FWList <int> a = new FWList <int>(); FWList <int> b = new FWList <int>(); a.AddRange(b); a.InsertRange(0, b); a.RemoveRange(0, 0); Assert.That(!a.Remove(0)); Assert.That(a.IsEmpty); Assert.That(a.WithoutFirst(0).IsEmpty); a.Add(1); Assert.That(a.WithoutFirst(1).IsEmpty); b.AddRange(a); ExpectList(b, 1); b.RemoveAt(0); Assert.That(b.IsEmpty); b.InsertRange(0, a); ExpectList(b, 1); b.RemoveRange(0, 1); Assert.That(b.IsEmpty); b.Insert(0, a[0]); ExpectList(b, 1); b.Remove(a.First); Assert.That(b.IsEmpty); }