示例#1
0
        public void Reverse()
        {
            var actual = MyEnumerable
                         .Range(0, 5)
                         .Reverse();

            Assert.Equal(new[] { 4, 3, 2, 1, 0 }, actual);
        }
示例#2
0
        public void Select()
        {
            var actual = MyEnumerable
                         .Range(0, 3)
                         .Select(i => i * 2);

            Assert.Equal(new[] { 0, 2, 4 }, actual);
        }
示例#3
0
        public void Where()
        {
            var actual = MyEnumerable
                         .Range(0, 5)
                         .Where(i => i % 2 == 0);

            Assert.Equal(new[] { 0, 2, 4 }, actual);
        }
示例#4
0
        public void Take()
        {
            var actual = MyEnumerable
                         .Range(0, 5)
                         .Take(3);

            Assert.Equal(new[] { 0, 1, 2 }, actual);
        }
示例#5
0
        public void SelectMany()
        {
            var numbers = MyEnumerable.Range(1, 2);
            var letters = new[] { 'A', 'B' };
            var actual  = numbers.SelectMany(num => letters, Tuple.Create);

            Assert.Equal(new[] {
                Tuple.Create(1, 'A'),
                Tuple.Create(1, 'B'),
                Tuple.Create(2, 'A'),
                Tuple.Create(2, 'B')
            }, actual);
        }
示例#6
0
        public void SelectManyCartesianProduct()
        {
            var numbers = MyEnumerable.Range(1, 3);
            var letters = new[] { 'x', 'y', 'z' };

            var actual = numbers.SelectMany(
                number => letters,
                Tuple.Create
                );

            CollectionAssert.AreEqual(
                new[] {
                Tuple.Create(1, 'x'),
                Tuple.Create(1, 'y'),
                Tuple.Create(1, 'z'),
                Tuple.Create(2, 'x'),
                Tuple.Create(2, 'y'),
                Tuple.Create(2, 'z'),
                Tuple.Create(3, 'x'),
                Tuple.Create(3, 'y'),
                Tuple.Create(3, 'z')
            }, actual);
        }
示例#7
0
        public void ReverseTest()
        {
            var actual = MyEnumerable.Range(1, 5).Reverse();

            CollectionAssert.AreEqual(new[] { 5, 4, 3, 2, 1 }, actual);
        }
示例#8
0
        public void RangeTest()
        {
            var actual = MyEnumerable.Range(1, 10);

            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
        }
示例#9
0
        public void Range()
        {
            var actual = MyEnumerable.Range(0, 5);

            Assert.Equal(new[] { 0, 1, 2, 3, 4 }, actual);
        }