Beispiel #1
0
 public void Select_SourceIsArrayTakeTake()
 {
     var source = new[] { 1, 2, 3, 4 }.Select(i => i * 2).Take(2).Take(1);
     Assert.Equal(new[] { 2 }, source);
     Assert.Equal(new[] { 2 }, source.Take(10));
 }
Beispiel #2
0
 public void Select_SourceIsArray_Take()
 {
     var source = new[] { 1, 2, 3, 4 }.Select(i => i * 2);
     Assert.Equal(new[] { 2, 4 }, source.Take(2));
     Assert.Equal(new[] { 2, 4 }, source.Take(3).Take(2));
     Assert.Empty(source.Take(-1));
     Assert.Equal(new[] { 2, 4, 6, 8 }, source.Take(4));
     Assert.Equal(new[] { 2, 4, 6, 8 }, source.Take(40));
     Assert.Equal(new[] { 2 }, source.Take(1));
     Assert.Equal(new[] { 4 }, source.Skip(1).Take(1));
     Assert.Equal(new[] { 6 }, source.Take(3).Skip(2));
     Assert.Equal(new[] { 2 }, source.Take(3).Take(1));
 }
Beispiel #3
0
        public void Select_SourceIsArray_Last()
        {
            var source = new[] { 1, 2, 3, 4 }.Select(i => i * 2);
            Assert.Equal(8, source.Last());
            Assert.Equal(8, source.LastOrDefault());

            Assert.Equal(6, source.Take(3).Last());
            Assert.Equal(6, source.Take(3).LastOrDefault());

            var empty = new int[0].Select(i => i * 2);
            Assert.Throws<InvalidOperationException>(() => empty.Last());
            Assert.Equal(0, empty.LastOrDefault());
            Assert.Throws<InvalidOperationException>(() => empty.Skip(1).Last());
            Assert.Equal(0, empty.Skip(1).LastOrDefault());
        }