public void RemoveAt() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyDictionary = new SortedList <int, int>(1024); //**************************************** for (var Index = 0; Index < 1024; Index++) { int Key, Value; do { Key = MyRandom.Next(); } while (MyDictionary.ContainsKey(Key)); Value = MyRandom.Next(); MyDictionary.Add(Key, Value); } var MyRecords = new ObservableSortedList <int, int>(MyDictionary); //**************************************** for (var Index = 0; Index < 512; Index++) { var InnerIndex = MyRandom.Next(MyRecords.Count); var Key = MyRecords.Keys[InnerIndex]; MyRecords.RemoveAt(InnerIndex); Assert.IsTrue(MyDictionary.Remove(Key)); } //**************************************** Assert.AreEqual(512, MyRecords.Count, "Count incorrect. Bad Seed was {0}", MySeed); CollectionAssert.AreEquivalent(MyDictionary, MyRecords, "Collections don't match. Bad Seed was {0}", MySeed); foreach (var MyPair in MyDictionary) { Assert.IsTrue(MyRecords.TryGetValue(MyPair.Key, out var Value)); Assert.AreEqual(MyPair.Value, Value); } Thread.Sleep(1); }
public void RemoveRange() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyDictionary = new SortedList <int, int>(1024); //**************************************** for (var Index = 0; Index < 1024; Index++) { int Key, Value; do { Key = MyRandom.Next(); } while (MyDictionary.ContainsKey(Key)); Value = MyRandom.Next(); MyDictionary.Add(Key, Value); } var MyRecords = new ObservableSortedList <int, int>(MyDictionary); //**************************************** foreach (var MyResult in MyRecords.Skip(256).Take(256)) { MyDictionary.Remove(MyResult.Key); } MyRecords.RemoveRange(256, 256); //**************************************** CollectionAssert.AreEquivalent(MyDictionary, MyRecords, "Collections don't match. Bad Seed was {0}", MySeed); foreach (var MyPair in MyDictionary) { Assert.IsTrue(MyRecords.TryGetValue(MyPair.Key, out var Value)); Assert.AreEqual(MyPair.Value, Value); } Thread.Sleep(1); }