示例#1
0
        public void Add()
        {
            var xs     = Enumerable.Range(0, 10000).ToList();
            var actual = new FilteredView <int>(xs, Predicate);

            Assert.Throws <InvalidOperationException>(() => actual.Add(1));


            bool Predicate(int x)
            {
                return(x % 2 == 0);
            }
        }
示例#2
0
        public void Count2()
        {
            var xs       = Enumerable.Range(0, 10000).ToList();
            var expected = xs.Where(Predicate).Count();
            var actual   = new FilteredView <int>(xs, Predicate).Count;

            Assert.Equal(expected, actual);


            bool Predicate(int x)
            {
                return(x % 17 < 7);
            }
        }
示例#3
0
        public void Indexing2()
        {
            var xs       = Enumerable.Range(0, 10000).ToList();
            var expected = xs.Where(Predicate).ToList();
            var actual   = new FilteredView <int>(xs, Predicate);

            Assert.Equal(Copy(actual), expected);


            bool Predicate(int x)
            {
                return(x % 2 == 0);
            }
        }
示例#4
0
        public void IndexOf()
        {
            var ints = Enumerable.Range(0, 10000).ToList();
            var xs   = ints.Where(Predicate).ToList();
            var ys   = new FilteredView <int>(ints, Predicate);

            for (int i = 0; i != 10000; ++i)
            {
                var expected = xs.IndexOf(i);
                var actual   = ys.IndexOf(i);

                Assert.Equal(expected, actual);
            }


            bool Predicate(int x)
            {
                return(x % 2 == 0);
            }
        }