public void RandomInsertDeleteRange() { const int ITER = 2000, LOOP = 15; Random rand = new Random(13); for (int loop = 0; loop < LOOP; ++loop) { Deque <int> deque = new Deque <int>(); List <int> list = new List <int>(); for (int iter = 0; iter < ITER; ++iter) { //Console.Write("Loop {0}, Iteration {1}: ", loop, iter); if (rand.Next(100) < 45) { // remove a range. if (list.Count > 0) { int index = rand.Next(list.Count); int count = rand.Next(list.Count - index); //Console.WriteLine("RemoveAt({0}, {1})", index, count); list.RemoveRange(index, count); deque.RemoveRange(index, count); } } else { // Add an range. int index = rand.Next(list.Count + 1); int count = rand.Next(10); int[] items = new int[count]; for (int i = 0; i < count; ++i) { items[i] = rand.Next(1000); } /*Console.Write("Insert({0}, {{", index); * for (int i = 0; i < count; ++i) { * if (i > 0) * Console.Write(", "); * Console.Write(items[i]); * } * Console.WriteLine("})"); */ IEnumerable <int> e = (rand.Next(2) == 0) ? AlgorithmsTests.EnumerableFromArray(items) : items; list.InsertRange(index, e); deque.InsertRange(index, e); } //deque.Print(); CheckListAndDeque(list, deque); } InterfaceTests.TestReadWriteList(deque, list.ToArray()); } }
public void AddMany() { ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary(); dict.AddMany("Rules", AlgorithmsTests.EnumerableFromArray(new int[] { 9, -8, 18 })); dict.AddMany("World", AlgorithmsTests.EnumerableFromArray(new int[] { })); dict.AddMany("Bizzle", AlgorithmsTests.EnumerableFromArray(new int[] { 3, 2, 1 })); dict.AddMany("Dazzle", AlgorithmsTests.EnumerableFromArray(new int[] { })); string[] s_array = new string[] { "Eric", "Clapton", "Rules", "The", "World", "Bizzle" }; int[][] i_array = new int[][] { new int[] { 1, 9, 11 }, new int[] { 6, 10 }, new int[] { 4, 9, -8, 18 }, new int[] { 1, 2, 3, 4, 5, 6 }, new int[] { 8 }, new int[] { 3, 2, 1 } }; CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null); }