From 73ee1d29498ae06b8327059f8547cf658f9ea0fc Mon Sep 17 00:00:00 2001 From: Bart De Smet Date: Tue, 26 Feb 2019 21:11:49 -0800 Subject: [PATCH] Clean up tests for Average. --- .../Linq/Operators/Average.Generated.cs | 240 ++++++++++++ .../Linq/Operators/Average.Generated.tt | 48 +++ .../System/Linq/Operators/Average.cs | 348 ------------------ 3 files changed, 288 insertions(+), 348 deletions(-) delete mode 100644 Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.cs diff --git a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.Generated.cs b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.Generated.cs index 88017bb473..ce067f574e 100644 --- a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.Generated.cs +++ b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.Generated.cs @@ -13,6 +13,12 @@ namespace Tests { public class AverageAsync : AsyncEnumerableTests { + [Fact] + public async Task AverageAsync_Int32_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Int32_Empty() { @@ -28,6 +34,13 @@ public async Task AverageAsync_Int32_Many() Assert.Equal(xs.Average(), await ys.AverageAsync()); } + [Fact] + public async Task AverageAsync_Selector_Int32_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); + } + [Fact] public async Task AverageAsync_Selector_Int32_Empty() { @@ -43,6 +56,13 @@ public async Task AverageAsync_Selector_Int32_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Int32_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitAsync_Selector_Int32_Empty() { @@ -59,6 +79,13 @@ public async Task AverageAwaitAsync_Selector_Int32_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Int32_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Int32_Empty() { @@ -75,6 +102,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Int32_Many() } #endif + [Fact] + public async Task AverageAsync_Int32_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Int32_Nullable_Empty() { @@ -105,6 +138,14 @@ public async Task AverageAsync_Selector_Int32_Nullable_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Int32_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + + [Fact] public async Task AverageAwaitAsync_Selector_Int32_Nullable_Empty() { @@ -121,6 +162,13 @@ public async Task AverageAwaitAsync_Selector_Int32_Nullable_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Int32_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Int32_Nullable_Empty() { @@ -137,6 +185,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Int32_Nullable_Many } #endif + [Fact] + public async Task AverageAsync_Int64_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Int64_Empty() { @@ -152,6 +206,13 @@ public async Task AverageAsync_Int64_Many() Assert.Equal(xs.Average(), await ys.AverageAsync()); } + [Fact] + public async Task AverageAsync_Selector_Int64_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); + } + [Fact] public async Task AverageAsync_Selector_Int64_Empty() { @@ -167,6 +228,13 @@ public async Task AverageAsync_Selector_Int64_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Int64_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitAsync_Selector_Int64_Empty() { @@ -183,6 +251,13 @@ public async Task AverageAwaitAsync_Selector_Int64_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Int64_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Int64_Empty() { @@ -199,6 +274,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Int64_Many() } #endif + [Fact] + public async Task AverageAsync_Int64_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Int64_Nullable_Empty() { @@ -229,6 +310,14 @@ public async Task AverageAsync_Selector_Int64_Nullable_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Int64_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + + [Fact] public async Task AverageAwaitAsync_Selector_Int64_Nullable_Empty() { @@ -245,6 +334,13 @@ public async Task AverageAwaitAsync_Selector_Int64_Nullable_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Int64_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Int64_Nullable_Empty() { @@ -261,6 +357,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Int64_Nullable_Many } #endif + [Fact] + public async Task AverageAsync_Single_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Single_Empty() { @@ -276,6 +378,13 @@ public async Task AverageAsync_Single_Many() Assert.Equal(xs.Average(), await ys.AverageAsync()); } + [Fact] + public async Task AverageAsync_Selector_Single_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); + } + [Fact] public async Task AverageAsync_Selector_Single_Empty() { @@ -291,6 +400,13 @@ public async Task AverageAsync_Selector_Single_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Single_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitAsync_Selector_Single_Empty() { @@ -307,6 +423,13 @@ public async Task AverageAwaitAsync_Selector_Single_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Single_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Single_Empty() { @@ -323,6 +446,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Single_Many() } #endif + [Fact] + public async Task AverageAsync_Single_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Single_Nullable_Empty() { @@ -353,6 +482,14 @@ public async Task AverageAsync_Selector_Single_Nullable_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Single_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + + [Fact] public async Task AverageAwaitAsync_Selector_Single_Nullable_Empty() { @@ -369,6 +506,13 @@ public async Task AverageAwaitAsync_Selector_Single_Nullable_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Single_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Single_Nullable_Empty() { @@ -385,6 +529,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Single_Nullable_Man } #endif + [Fact] + public async Task AverageAsync_Double_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Double_Empty() { @@ -400,6 +550,13 @@ public async Task AverageAsync_Double_Many() Assert.Equal(xs.Average(), await ys.AverageAsync()); } + [Fact] + public async Task AverageAsync_Selector_Double_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); + } + [Fact] public async Task AverageAsync_Selector_Double_Empty() { @@ -415,6 +572,13 @@ public async Task AverageAsync_Selector_Double_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Double_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitAsync_Selector_Double_Empty() { @@ -431,6 +595,13 @@ public async Task AverageAwaitAsync_Selector_Double_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Double_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Double_Empty() { @@ -447,6 +618,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Double_Many() } #endif + [Fact] + public async Task AverageAsync_Double_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Double_Nullable_Empty() { @@ -477,6 +654,14 @@ public async Task AverageAsync_Selector_Double_Nullable_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Double_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + + [Fact] public async Task AverageAwaitAsync_Selector_Double_Nullable_Empty() { @@ -493,6 +678,13 @@ public async Task AverageAwaitAsync_Selector_Double_Nullable_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Double_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Double_Nullable_Empty() { @@ -509,6 +701,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Double_Nullable_Man } #endif + [Fact] + public async Task AverageAsync_Decimal_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Decimal_Empty() { @@ -524,6 +722,13 @@ public async Task AverageAsync_Decimal_Many() Assert.Equal(xs.Average(), await ys.AverageAsync()); } + [Fact] + public async Task AverageAsync_Selector_Decimal_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); + } + [Fact] public async Task AverageAsync_Selector_Decimal_Empty() { @@ -539,6 +744,13 @@ public async Task AverageAsync_Selector_Decimal_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Decimal_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitAsync_Selector_Decimal_Empty() { @@ -555,6 +767,13 @@ public async Task AverageAwaitAsync_Selector_Decimal_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Decimal_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Decimal_Empty() { @@ -571,6 +790,12 @@ public async Task AverageAwaitWithCancellationAsync_Selector_Decimal_Many() } #endif + [Fact] + public async Task AverageAsync_Decimal_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); + } + [Fact] public async Task AverageAsync_Decimal_Nullable_Empty() { @@ -601,6 +826,14 @@ public async Task AverageAsync_Selector_Decimal_Nullable_Many() Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_Decimal_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + + [Fact] public async Task AverageAwaitAsync_Selector_Decimal_Nullable_Empty() { @@ -617,6 +850,13 @@ public async Task AverageAwaitAsync_Selector_Decimal_Nullable_Many() } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_Decimal_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_Decimal_Nullable_Empty() { diff --git a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.Generated.tt b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.Generated.tt index 067549d6a4..38beb77161 100644 --- a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.Generated.tt +++ b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.Generated.tt @@ -43,6 +43,12 @@ foreach (var t in types) { var cs = toCSharp(t); #> + [Fact] + public async Task AverageAsync_<#=t.Name#>_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable<<#=cs#>>)).AsTask()); + } + [Fact] public async Task AverageAsync_<#=t.Name#>_Empty() { @@ -58,6 +64,13 @@ foreach (var t in types) Assert.Equal(xs.Average(), await ys.AverageAsync()); } + [Fact] + public async Task AverageAsync_Selector_<#=t.Name#>_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable<<#=cs#>>), x => x).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); + } + [Fact] public async Task AverageAsync_Selector_<#=t.Name#>_Empty() { @@ -73,6 +86,13 @@ foreach (var t in types) Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_<#=t.Name#>_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable<<#=cs#>>), x => new ValueTask<<#=cs#>>(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>>)).AsTask()); + } + [Fact] public async Task AverageAwaitAsync_Selector_<#=t.Name#>_Empty() { @@ -89,6 +109,13 @@ foreach (var t in types) } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_<#=t.Name#>_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable<<#=cs#>>), (x, ct) => new ValueTask<<#=cs#>>(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_<#=t.Name#>_Empty() { @@ -105,6 +132,12 @@ foreach (var t in types) } #endif + [Fact] + public async Task AverageAsync_<#=t.Name#>_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable<<#=cs#>?>)).AsTask()); + } + [Fact] public async Task AverageAsync_<#=t.Name#>_Nullable_Empty() { @@ -135,6 +168,14 @@ foreach (var t in types) Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); } + [Fact] + public async Task AverageAwaitAsync_Selector_<#=t.Name#>_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable<<#=cs#>?>), x => new ValueTask<<#=cs#>?>(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func?>>)).AsTask()); + } + + [Fact] public async Task AverageAwaitAsync_Selector_<#=t.Name#>_Nullable_Empty() { @@ -151,6 +192,13 @@ foreach (var t in types) } #if !NO_DEEP_CANCELLATION + [Fact] + public async Task AverageAwaitWithCancellationAsync_Selector_<#=t.Name#>_Nullable_Null() + { + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable<<#=cs#>?>), (x, ct) => new ValueTask<<#=cs#>?>(x)).AsTask()); + await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func?>>)).AsTask()); + } + [Fact] public async Task AverageAwaitWithCancellationAsync_Selector_<#=t.Name#>_Nullable_Empty() { diff --git a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.cs b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.cs deleted file mode 100644 index f6154e421a..0000000000 --- a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Average.cs +++ /dev/null @@ -1,348 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Xunit; - -namespace Tests -{ - public class Average : AsyncEnumerableTests - { - [Fact] - public async Task Average_Null() - { - // Average(IAE

) - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable)).AsTask()); - - // Average(IAE

, CT) - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), CancellationToken.None).AsTask()); - - // Average(IAE, Func) - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x).AsTask()); - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func)).AsTask()); - - // Average(IAE, Func, CT) - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(default(IAsyncEnumerable), x => x, CancellationToken.None).AsTask()); - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAsync(AsyncEnumerable.Empty(), default(Func), CancellationToken.None).AsTask()); - - // Average(IAE, Func>) - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x)).AsTask()); - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>)).AsTask()); - - // Average(IAE, Func>, CT) - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(default(IAsyncEnumerable), x => new ValueTask(x), CancellationToken.None).AsTask()); - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - -#if !NO_DEEP_CANCELLATION - // Average(IAE, Func>, CT) - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(default(IAsyncEnumerable), (x, ct) => new ValueTask(x), CancellationToken.None).AsTask()); - - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default, CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); - await Assert.ThrowsAsync(() => AsyncEnumerable.AverageAwaitWithCancellationAsync(AsyncEnumerable.Empty(), default(Func>), CancellationToken.None).AsTask()); -#endif - } - - [Fact] - public async Task Average1() - { - var xs = new[] { 1, 2, 3 }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average2() - { - var xs = new[] { 1, default(int?), 3 }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average3() - { - var xs = new[] { 1L, 2L, 3L }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average4() - { - var xs = new[] { 1L, default(long?), 3L }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average5() - { - var xs = new[] { 1.0, 2.0, 3.0 }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average6() - { - var xs = new[] { 1.0, default(double?), 3.0 }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average7() - { - var xs = new[] { 1.0f, 2.0f, 3.0f }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average8() - { - var xs = new[] { 1.0f, default(float?), 3.0f }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average9() - { - var xs = new[] { 1.0m, 2.0m, 3.0m }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average10() - { - var xs = new[] { 1.0m, default(decimal?), 3.0m }; - var ys = xs.ToAsyncEnumerable(); - Assert.Equal(xs.Average(), await ys.AverageAsync()); - Assert.Equal(xs.Average(), await ys.AverageAsync(x => x)); - Assert.Equal(xs.Average(), await ys.AverageAwaitAsync(x => new ValueTask(x))); - } - - [Fact] - public async Task Average11() - { - var xs = new int[0]; - var ys = xs.ToAsyncEnumerable(); - await Assert.ThrowsAsync(() => ys.AverageAsync().AsTask()); - } - - [Fact] - public async Task Average12() - { - var xs = new int?[0]; - var ys = xs.ToAsyncEnumerable(); - Assert.Null(await ys.AverageAsync()); - } - - [Fact] - public async Task Average13() - { - var xs = new long[0]; - var ys = xs.ToAsyncEnumerable(); - await Assert.ThrowsAsync(() => ys.AverageAsync().AsTask()); - } - - [Fact] - public async Task Average14() - { - var xs = new long?[0]; - var ys = xs.ToAsyncEnumerable(); - Assert.Null(await ys.AverageAsync()); - } - - [Fact] - public async Task Average15() - { - var xs = new double[0]; - var ys = xs.ToAsyncEnumerable(); - await Assert.ThrowsAsync(() => ys.AverageAsync().AsTask()); - } - - [Fact] - public async Task Average16() - { - var xs = new double?[0]; - var ys = xs.ToAsyncEnumerable(); - Assert.Null(await ys.AverageAsync()); - } - - [Fact] - public async Task Average17() - { - var xs = new float[0]; - var ys = xs.ToAsyncEnumerable(); - await Assert.ThrowsAsync(() => ys.AverageAsync().AsTask()); - } - - [Fact] - public async Task Average18() - { - var xs = new float?[0]; - var ys = xs.ToAsyncEnumerable(); - Assert.Null(await ys.AverageAsync()); - } - - [Fact] - public async Task Average19() - { - var xs = new decimal[0]; - var ys = xs.ToAsyncEnumerable(); - await Assert.ThrowsAsync(() => ys.AverageAsync().AsTask()); - } - - [Fact] - public async Task Average20() - { - var xs = new decimal?[0]; - var ys = xs.ToAsyncEnumerable(); - Assert.Null(await ys.AverageAsync()); - } - } -}