1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT License.
- // See the LICENSE file in the project root for more information.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Xunit;
- namespace Tests
- {
- public class TakeLast : AsyncEnumerableTests
- {
- [Fact]
- public void TakeLast_Null()
- {
- Assert.Throws<ArgumentNullException>(() => AsyncEnumerable.TakeLast(default(IAsyncEnumerable<int>), 5));
- }
- [Fact]
- public async Task TakeLast_Negative()
- {
- var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().TakeLast(-2);
- var e = xs.GetAsyncEnumerator();
- await NoNextAsync(e);
- }
- [Fact]
- public async Task TakeLast_Positive()
- {
- var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().TakeLast(2);
- var e = xs.GetAsyncEnumerator();
- await HasNextAsync(e, 3);
- await HasNextAsync(e, 4);
- await NoNextAsync(e);
- }
- [Fact]
- public async Task TakeLast_TooMany()
- {
- var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().TakeLast(5);
- var e = xs.GetAsyncEnumerator();
- await HasNextAsync(e, 1);
- await HasNextAsync(e, 2);
- await HasNextAsync(e, 3);
- await HasNextAsync(e, 4);
- await NoNextAsync(e);
- }
- [Fact]
- public async Task TakeLast_BreakEarly_Take()
- {
- var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().TakeLast(3).Take(2);
- var e = xs.GetAsyncEnumerator();
- await HasNextAsync(e, 2);
- await HasNextAsync(e, 3);
- await NoNextAsync(e);
- }
- [Fact]
- public async Task TakeLast_SequenceIdentity()
- {
- var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().TakeLast(2);
- await SequenceIdentity(xs);
- }
- [Fact]
- public async Task TakeLast_BugFix_TakeLast_Zero_TakesForever()
- {
- var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().TakeLast(0);
- var e = xs.GetAsyncEnumerator();
- await NoNextAsync(e);
- }
- }
- }
|