Exemplo n.º 1
0
        public void removeWhere_numElements(int numElementsToRemove)
        {
            var        collection   = new MyObservableCollection <int>();
            List <int> removedItems = new List <int>();

            collection.ItemDetached += (sender, oldItem, index) =>
            {
                removedItems.Add(oldItem);
            };
            int maxCount = 30;

            collection.AddRange(Enumerable.Range(0, maxCount));
            int initCount = collection.Count;
            int multiple  = 3;

            collection.RemoveWhere(val =>
            {
                int remainder;
                int div = Math.DivRem(val, multiple, out remainder);
                return(remainder == 0);
            }, numElementsToRemove);
            Assert.IsTrue(collection.Count == initCount - numElementsToRemove);
            var xRemovedItems = Enumerable.Range(0, numElementsToRemove)
                                .Select(val => val * multiple)
                                .ToArray();

            Assert.AreEqual(removedItems.Count, xRemovedItems.Length);
            Assert.IsTrue(!removedItems.Except(xRemovedItems).Any());
            Assert.IsTrue(!xRemovedItems.Except(removedItems).Any());
            Enumerable.Range(0, maxCount)
            .Except(xRemovedItems)
            .ForEach(val => Assert.IsTrue(collection.Contains(val)));
            xRemovedItems.ForEach(val => Assert.IsFalse(collection.Contains(val)));
        }
Exemplo n.º 2
0
        public void RemoveWhereTest()
        {
            var collection = new MyObservableCollection <int>();

            collection.AddRange(Enumerable.Range(0, 31));
            collection.RemoveWhere(val =>
            {
                int remainder;
                int div = Math.DivRem(val, 3, out remainder);
                return(remainder == 0);
            });
            collection.ForEach(val =>
            {
                int remainder;
                int div = Math.DivRem(val, 3, out remainder);
                Assert.IsFalse(remainder == 0);
            });
        }