Example #1
0
        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);
        }