public void TestRemoveAt() { BTreeList <int> test = new BTreeList <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); IList <int> list = test; for (int i = 10; i < 1000; i++) { test.Add(i); } for (int i = 900; i > 0; i -= 100) { Assert.IsTrue(test.Contains(i)); Assert.AreEqual(i, list.IndexOf(i)); list.RemoveAt(i); Assert.IsFalse(test.Contains(i)); Assert.AreEqual(-1, list.IndexOf(i)); Assert.AreEqual(i + 1, list[i]); } list.RemoveAt(0); list.RemoveAt(1); list.RemoveAt(2); Assert.AreEqual(1, list[0]); Assert.AreEqual(3, list[1]); Assert.AreEqual(5, list[2]); Assert.AreEqual(1000 - 12, list.Count); }
void SequencedTest(int start, int incr, int stop, string name) { int count = Math.Abs(start - stop) / Math.Abs(incr); BTreeList <int> data = new BTreeList <int>(Comparer); Stopwatch time = new Stopwatch(); time.Start(); //large order-forward for (int i = start; i != stop; i += incr) { if (!data.TryAddItem(i)) { throw new ApplicationException(); } } Trace.TraceInformation("{0} insert {1} in {2}", name, count, time.ElapsedMilliseconds); time.Reset(); time.Start(); for (int i = start; i != stop; i += incr) { if (!data.Contains(i)) { throw new ApplicationException(); } } Trace.TraceInformation("{0} seek {1} in {2}", name, count, time.ElapsedMilliseconds); time.Reset(); time.Start(); int tmpCount = 0; foreach (int tmp in data) { if (tmp < Math.Min(start, stop) || tmp > Math.Max(start, stop)) { throw new ApplicationException(); } else { tmpCount++; } } if (tmpCount != count) { throw new ApplicationException(); } Trace.TraceInformation("{0} foreach {1} in {2}", name, count, time.ElapsedMilliseconds); time.Reset(); time.Start(); for (int i = start; i != stop; i += incr) { if (!data.Remove(i)) { throw new ApplicationException(); } } Trace.TraceInformation("{0} delete {1} in {2}", name, count, time.ElapsedMilliseconds); for (int i = start; i != stop; i += incr) { if (data.Contains(i)) { throw new ApplicationException(); } } }