public void RemoveAt() { const int TestCount = 10; const int LoopCount = 1248; var random = new Random(); for (int n = 0; n < TestCount; n++) { var list = new List <int>(); var speedyList = new SpeedyList <int>(); for (int i = 0; i < LoopCount; i++) { int index = random.Next(list.Count); list.Insert(index, i); speedyList.Insert(index, i); } Assert.AreEqual(LoopCount, list.Count); Assert.AreEqual(list.Count, speedyList.Count); for (int i = 0; i < LoopCount / 2; i++) { int index = random.Next(list.Count); list.RemoveAt(index); speedyList.RemoveAt(index); } Assert.AreEqual(LoopCount / 2, list.Count); Assert.AreEqual(list.Count, speedyList.Count); for (int i = 0; i < LoopCount / 2; i++) { Assert.AreEqual(list[i], speedyList[i]); int index1 = list.IndexOf(i); int index2 = speedyList.IndexOf(i); Assert.AreEqual(index1, index2); bool contains1 = list.Contains(i); bool contains2 = speedyList.Contains(i); Assert.AreEqual(contains1, contains2); } for (int i = 0; i < LoopCount / 2; i++) { int index = random.Next(list.Count); int index1 = list.IndexOf(index); int index2 = speedyList.IndexOf(index); Assert.AreEqual(index1, index2); } } }
public void RemoveAll() { const int TestCount = 10; const int LoopCount = 1248; var random = new Random(); for (int n = 0; n < TestCount; n++) { var list = new List <int>(); var speedyList = new SpeedyList <int>(); for (int i = 0; i < LoopCount; i++) { int index = random.Next(list.Count); list.Insert(index, i); speedyList.Insert(index, i); } Assert.AreEqual(LoopCount, list.Count); Assert.AreEqual(list.Count, speedyList.Count); int removeIndex = random.Next(list.Count); int count1 = list.RemoveAll(x => x < removeIndex); int count2 = speedyList.RemoveAll(x => x < removeIndex); Assert.AreEqual(count1, count2); Assert.AreEqual(list.Count, speedyList.Count); for (int i = 0; i < list.Count; i++) { Assert.AreEqual(list[i], speedyList[i]); int index1 = list.IndexOf(i); int index2 = speedyList.IndexOf(i); Assert.AreEqual(index1, index2); } } }
public void IndexOf3() { const int LoopCount = 1000; var list = new List <int>(); var speedyList = new SpeedyList <int>(); var random = new Random(); for (int i = 0; i < LoopCount; i++) { int index = random.Next(list.Count); int value = random.Next(LoopCount) + 1; list.Insert(index, value); speedyList.Insert(index, value); } Assert.AreEqual(LoopCount, list.Count); Assert.AreEqual(list.Count, speedyList.Count); for (int i = 0; i < LoopCount; i++) { int index = random.Next(list.Count); int count = random.Next(1, list.Count - index); int index1 = list.IndexOf(i, index, count); int index2 = speedyList.IndexOf(i, index, count); Assert.AreEqual(index1, index2); } }
public void ComplexTestString() { const int TestCount = 20; const int LoopCount = 999; var random = new Random(); for (int n = 0; n < TestCount; n++) { var list = new List <string>(); var speedyList = new SpeedyList <string>(); for (int i = 0; i < LoopCount + 1; i++) { var value = i.ToString(); list.Add(value); speedyList.Add(value); } Assert.AreNotEqual(0, list.Count); Assert.AreEqual(list.Count, speedyList.Count); for (int i = 0; i < LoopCount; i++) { int method = random.Next(6); int index = random.Next(list.Count); var value = random.Next(LoopCount).ToString(); switch (method) { case 0: list.Add(value); speedyList.Add(value); break; case 1: list.Insert(index, value); speedyList.Insert(index, value); break; case 2: list.Remove(value); speedyList.Remove(value); break; case 3: list.RemoveAt(index); speedyList.RemoveAt(index); break; case 4: list.Insert(index, null); speedyList.Insert(index, null); break; case 5: list.Remove(null); speedyList.Remove(null); break; default: Assert.IsTrue(false); break; } } Assert.AreNotEqual(0, list.Count); Assert.AreEqual(list.Count, speedyList.Count); for (int i = 0; i < list.Count; i++) { Assert.AreEqual(list[i], speedyList[i]); var value = i.ToString(); int index1 = list.IndexOf(value); int index2 = speedyList.IndexOf(value); Assert.AreEqual(index1, index2); bool contains1 = list.Contains(value); bool contains2 = speedyList.Contains(value); Assert.AreEqual(contains1, contains2); } } }