-
Notifications
You must be signed in to change notification settings - Fork 792
Expand file tree
/
Copy pathScan.cs
More file actions
86 lines (71 loc) · 2.71 KB
/
Copy pathScan.cs
File metadata and controls
86 lines (71 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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 Scan : AsyncEnumerableExTests
{
[Fact]
public void Scan_Null()
{
Assert.Throws<ArgumentNullException>(() => AsyncEnumerableEx.Scan(default(IAsyncEnumerable<int>), 3, (x, y) => x + y));
Assert.Throws<ArgumentNullException>(() => AsyncEnumerableEx.Scan(Return42, 3, default(Func<int, int, int>)));
Assert.Throws<ArgumentNullException>(() => AsyncEnumerableEx.Scan(default(IAsyncEnumerable<int>), (x, y) => x + y));
Assert.Throws<ArgumentNullException>(() => AsyncEnumerableEx.Scan(Return42, default(Func<int, int, int>)));
}
[Fact]
public async Task Scan1Async()
{
var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable().Scan(8, (x, y) => x + y);
var e = xs.GetAsyncEnumerator();
await HasNextAsync(e, 8);
await HasNextAsync(e, 9);
await HasNextAsync(e, 11);
await HasNextAsync(e, 14);
await NoNextAsync(e);
}
[Fact]
public async Task Scan2Async()
{
var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable().Scan((x, y) => x + y);
var e = xs.GetAsyncEnumerator();
await HasNextAsync(e, 1);
await HasNextAsync(e, 3);
await HasNextAsync(e, 6);
await NoNextAsync(e);
}
[Fact]
public async Task Scan3()
{
var ex = new Exception("Bang!");
var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable().Scan(8, new Func<int, int, int>((x, y) => { throw ex; }));
var e = xs.GetAsyncEnumerator();
await AssertThrowsAsync(e.MoveNextAsync(), ex);
}
[Fact]
public async Task Scan4()
{
var ex = new Exception("Bang!");
var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable().Scan(new Func<int, int, int>((x, y) => { throw ex; }));
var e = xs.GetAsyncEnumerator();
await AssertThrowsAsync(e.MoveNextAsync(), ex);
}
[Fact]
public async Task Scan5()
{
var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable().Scan(8, (x, y) => x + y);
await SequenceIdentity(xs);
}
[Fact]
public async Task Scan6()
{
var xs = new[] { 1, 2, 3 }.ToAsyncEnumerable().Scan((x, y) => x + y);
await SequenceIdentity(xs);
}
}
}