public void TestInsertRemove() { RWList <int> list = new RWList <int>(); for (int i = 0; i <= 12; i++) { list.Insert(0, i); } ExpectList(list, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); for (int i = 1; i <= 6; i++) { list.RemoveAt(i); } ExpectList(list, 12, 10, 8, 6, 4, 2, 0); Assert.AreEqual(0, list.Pop()); list.Insert(1, -2); ExpectList(list, 12, -2, 10, 8, 6, 4, 2); list.Insert(2, -1); ExpectList(list, 12, -2, -1, 10, 8, 6, 4, 2); Assert.That(list.Remove(-1)); Assert.That(list.Remove(12)); list[0] = 12; ExpectList(list, 12, 10, 8, 6, 4, 2); // Make sure RWList.Clear doesn't disturb FVList RVList <int> v = list.WithoutLast(4); list.Clear(); ExpectList(list); ExpectList(v, 12, 10); // Some simple InsertRange calls where some immutable items must be // converted to mutable RVList <int> oneTwo = new RVList <int>(1, 2); RVList <int> threeFour = new RVList <int>(3, 4); list = oneTwo.ToRWList(); list.InsertRange(1, threeFour); ExpectList(list, 1, 3, 4, 2); list = threeFour.ToRWList(); list.InsertRange(0, oneTwo); ExpectList(list, 1, 2, 3, 4); // More tests... list.RemoveRange(2, 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.ToRVList(); 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() { RWList <int> a = new RWList <int>(); RWList <int> b = new RWList <int>(); a.AddRange(b); a.InsertRange(0, b); a.RemoveRange(0, 0); Assert.That(!a.Remove(0)); Assert.That(a.IsEmpty); Assert.That(a.WithoutLast(0).IsEmpty); a.Add(1); Assert.That(a.WithoutLast(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.Last); Assert.That(b.IsEmpty); }
public void SimpleTests() { // Tests simple adds and removes from the front of the list. It // makes part of its tail immutable, but doesn't make it mutable // again. Also, we test operations that don't modify the list. RWList <int> list = new RWList <int>(); Assert.That(list.IsEmpty); // create VListBlockOfTwo list = new RWList <int>(10, 20); ExpectList(list, 10, 20); // Add() list.Clear(); list.Add(1); Assert.That(!list.IsEmpty); list.Add(2); Assert.AreEqual(1, list.BlockChainLength); list.Add(3); Assert.AreEqual(2, list.BlockChainLength); ExpectList(list, 1, 2, 3); RVList <int> snap = list.ToRVList(); ExpectList(snap, 1, 2, 3); // AddRange(), Push(), Pop() list.Push(4); list.AddRange(new int[] { 5, 6 }); ExpectList(list, 1, 2, 3, 4, 5, 6); Assert.AreEqual(list.Pop(), 6); ExpectList(list, 1, 2, 3, 4, 5); list.RemoveRange(3, 2); ExpectList(list, 1, 2, 3); // Double the list list.AddRange(list); ExpectList(list, 1, 2, 3, 1, 2, 3); list.RemoveRange(3, 3); // Fill a third block list.AddRange(new int[] { 4, 5, 6, 7, 8, 9 }); list.AddRange(new int[] { 10, 11, 12, 13, 14 }); ExpectList(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14); // Remove(), enumerator list.Remove(14); list.Remove(13); list.Remove(12); list.Remove(11); ExpectListByEnumerator(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // IndexOutOfRangeException AssertThrows <IndexOutOfRangeException>(delegate() { int i = list[-1]; }); AssertThrows <IndexOutOfRangeException>(delegate() { int i = list[10]; }); AssertThrows <IndexOutOfRangeException>(delegate() { list.Insert(-1, -1); }); AssertThrows <IndexOutOfRangeException>(delegate() { list.Insert(list.Count + 1, -1); }); AssertThrows <IndexOutOfRangeException>(delegate() { list.RemoveAt(-1); }); AssertThrows <IndexOutOfRangeException>(delegate() { list.RemoveAt(list.Count); }); // Front, Contains, IndexOf Assert.That(list.Last == 10); Assert.That(list.Contains(9)); Assert.That(list[list.IndexOf(2)] == 2); Assert.That(list[list.IndexOf(9)] == 9); Assert.That(list[list.IndexOf(7)] == 7); Assert.That(list.IndexOf(-1) == -1); // snap is still the same ExpectList(snap, 1, 2, 3); }