|
1 | 1 | // ReSharper disable PossibleMultipleEnumeration |
2 | 2 | using FsCheck; |
3 | | -using FsCheck.Xunit; |
| 3 | +using FsCheck.Fluent; |
4 | 4 | using Funcky.Test.Internal; |
5 | 5 |
|
6 | 6 | namespace Funcky.Async.Test.Extensions.AsyncEnumerableExtensions; |
7 | 7 |
|
8 | 8 | public sealed class AverageOrNoneTest |
9 | 9 | { |
10 | | - public AverageOrNoneTest() |
11 | | - { |
12 | | - Arb.Register<AsyncGenerator<int?>>(); |
13 | | - Arb.Register<AsyncGenerator<int>>(); |
14 | | - Arb.Register<AsyncGenerator<long?>>(); |
15 | | - Arb.Register<AsyncGenerator<long>>(); |
16 | | - Arb.Register<AsyncGenerator<float?>>(); |
17 | | - Arb.Register<AsyncGenerator<float>>(); |
18 | | - Arb.Register<AsyncGenerator<double?>>(); |
19 | | - Arb.Register<AsyncGenerator<double>>(); |
20 | | - Arb.Register<AsyncGenerator<decimal?>>(); |
21 | | - Arb.Register<AsyncGenerator<decimal>>(); |
22 | | - } |
23 | | - |
24 | 10 | // Int32/int Tests |
25 | | - [Property] |
| 11 | + [FunckyAsyncProperty] |
26 | 12 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageAsyncForInt32(IAsyncEnumerable<int> sequence) |
27 | 13 | => CompareAverageAndHandleEmptyInt32SequenceAsync(sequence).Result.ToProperty(); |
28 | 14 |
|
29 | | - [Property] |
| 15 | + [FunckyAsyncProperty] |
30 | 16 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageForNullableAsyncForInt32(IAsyncEnumerable<int?> sequence) |
31 | 17 | => (Option.FromNullable(sequence.AverageAsync().Result) |
32 | 18 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync().Result).ToProperty(); |
33 | 19 |
|
34 | | - [Property] |
| 20 | + [FunckyAsyncProperty] |
35 | 21 | public Property AverageOrNoneAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt32(IAsyncEnumerable<int?> sequence, Func<int?, int?> selector) |
36 | 22 | => (Option.FromNullable(sequence.AverageAsync(selector).Result) |
37 | 23 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
38 | 24 |
|
39 | | - [Property] |
40 | | - public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt32(IAsyncEnumerable<int?> sequence, Func<int?, ValueTask<int?>> selector) |
41 | | - => (Option.FromNullable(sequence.AverageAwaitAsync(selector).Result) |
42 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 25 | + [FunckyAsyncProperty] |
| 26 | + public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt32(IAsyncEnumerable<int?> sequence, AwaitSelector<int?> selector) |
| 27 | + => (Option.FromNullable(sequence.AverageAwaitAsync(selector.Get).Result) |
| 28 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
43 | 29 |
|
44 | | - [Property] |
45 | | - public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt32(IAsyncEnumerable<int?> sequence, Func<int?, CancellationToken, ValueTask<int?>> selector) |
46 | | - => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector).Result) |
47 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 30 | + [FunckyAsyncProperty] |
| 31 | + public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt32(IAsyncEnumerable<int?> sequence, AwaitSelectorWithCancellation<int?> selector) |
| 32 | + => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector.Get).Result) |
| 33 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
48 | 34 |
|
49 | 35 | // Int64/long Tests |
50 | | - [Property] |
| 36 | + [FunckyAsyncProperty] |
51 | 37 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageAsyncForInt64(IAsyncEnumerable<long> sequence) |
52 | 38 | => CompareAverageAndHandleEmptyInt64SequenceAsync(sequence).Result.ToProperty(); |
53 | 39 |
|
54 | | - [Property] |
| 40 | + [FunckyAsyncProperty] |
55 | 41 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageForNullableAsyncForInt64(IAsyncEnumerable<long?> sequence) |
56 | 42 | => (Option.FromNullable(sequence.AverageAsync().Result) |
57 | 43 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync().Result).ToProperty(); |
58 | 44 |
|
59 | | - [Property] |
| 45 | + [FunckyAsyncProperty] |
60 | 46 | public Property AverageOrNoneAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt64(IAsyncEnumerable<long?> sequence, Func<long?, long?> selector) |
61 | 47 | => (Option.FromNullable(sequence.AverageAsync(selector).Result) |
62 | 48 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
63 | 49 |
|
64 | | - [Property] |
65 | | - public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt64(IAsyncEnumerable<long?> sequence, Func<long?, ValueTask<long?>> selector) |
66 | | - => (Option.FromNullable(sequence.AverageAwaitAsync(selector).Result) |
67 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 50 | + [FunckyAsyncProperty] |
| 51 | + public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt64(IAsyncEnumerable<long?> sequence, AwaitSelector<long?> selector) |
| 52 | + => (Option.FromNullable(sequence.AverageAwaitAsync(selector.Get).Result) |
| 53 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
68 | 54 |
|
69 | | - [Property] |
70 | | - public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt64(IAsyncEnumerable<int?> sequence, Func<int?, CancellationToken, ValueTask<int?>> selector) |
71 | | - => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector).Result) |
72 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 55 | + [FunckyAsyncProperty] |
| 56 | + public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForInt64(IAsyncEnumerable<int?> sequence, AwaitSelectorWithCancellation<int?> selector) |
| 57 | + => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector.Get).Result) |
| 58 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
73 | 59 |
|
74 | 60 | // Single/float Tests |
75 | | - [Property] |
| 61 | + [FunckyAsyncProperty] |
76 | 62 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageAsyncForSingle(IAsyncEnumerable<float> sequence) |
77 | 63 | => CompareAverageAndHandleEmptySingleSequenceAsync(sequence).Result.ToProperty(); |
78 | 64 |
|
79 | | - [Property] |
| 65 | + [FunckyAsyncProperty] |
80 | 66 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageForNullableAsyncForSingle(IAsyncEnumerable<float?> sequence) |
81 | 67 | => (Option.FromNullable(sequence.AverageAsync().Result) |
82 | 68 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync().Result).ToProperty(); |
83 | 69 |
|
84 | | - [Property] |
| 70 | + [FunckyAsyncProperty] |
85 | 71 | public Property AverageOrNoneAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForSingle(IAsyncEnumerable<float?> sequence, Func<float?, float?> selector) |
86 | 72 | => (Option.FromNullable(sequence.AverageAsync(selector).Result) |
87 | 73 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
88 | 74 |
|
89 | | - [Property] |
90 | | - public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForSingle(IAsyncEnumerable<float?> sequence, Func<float?, ValueTask<float?>> selector) |
91 | | - => (Option.FromNullable(sequence.AverageAwaitAsync(selector).Result) |
92 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 75 | + [FunckyAsyncProperty] |
| 76 | + public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForSingle(IAsyncEnumerable<float?> sequence, AwaitSelector<float?> selector) |
| 77 | + => (Option.FromNullable(sequence.AverageAwaitAsync(selector.Get).Result) |
| 78 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
93 | 79 |
|
94 | | - [Property] |
95 | | - public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForSingle(IAsyncEnumerable<float?> sequence, Func<float?, CancellationToken, ValueTask<float?>> selector) |
96 | | - => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector).Result) |
97 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 80 | + [FunckyAsyncProperty] |
| 81 | + public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForSingle(IAsyncEnumerable<float?> sequence, AwaitSelectorWithCancellation<float?> selector) |
| 82 | + => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector.Get).Result) |
| 83 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
98 | 84 |
|
99 | 85 | // Double/double Tests |
100 | | - [Property] |
| 86 | + [FunckyAsyncProperty] |
101 | 87 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageAsyncForDouble(IAsyncEnumerable<double> sequence) |
102 | 88 | => CompareAverageAndHandleEmptyDoubleSequenceAsync(sequence).Result.ToProperty(); |
103 | 89 |
|
104 | | - [Property] |
| 90 | + [FunckyAsyncProperty] |
105 | 91 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageForNullableAsyncForDouble(IAsyncEnumerable<double?> sequence) |
106 | 92 | => (Option.FromNullable(sequence.AverageAsync().Result) |
107 | 93 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync().Result).ToProperty(); |
108 | 94 |
|
109 | | - [Property] |
| 95 | + [FunckyAsyncProperty] |
110 | 96 | public Property AverageOrNoneAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDouble(IAsyncEnumerable<double?> sequence, Func<double?, double?> selector) |
111 | 97 | => (Option.FromNullable(sequence.AverageAsync(selector).Result) |
112 | 98 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
113 | 99 |
|
114 | | - [Property] |
115 | | - public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDouble(IAsyncEnumerable<double?> sequence, Func<double?, ValueTask<double?>> selector) |
116 | | - => (Option.FromNullable(sequence.AverageAwaitAsync(selector).Result) |
117 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 100 | + [FunckyAsyncProperty] |
| 101 | + public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDouble(IAsyncEnumerable<double?> sequence, AwaitSelector<double?> selector) |
| 102 | + => (Option.FromNullable(sequence.AverageAwaitAsync(selector.Get).Result) |
| 103 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
118 | 104 |
|
119 | | - [Property] |
120 | | - public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDouble(IAsyncEnumerable<double?> sequence, Func<double?, CancellationToken, ValueTask<double?>> selector) |
121 | | - => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector).Result) |
122 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 105 | + [FunckyAsyncProperty] |
| 106 | + public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDouble(IAsyncEnumerable<double?> sequence, AwaitSelectorWithCancellation<double?> selector) |
| 107 | + => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector.Get).Result) |
| 108 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
123 | 109 |
|
124 | 110 | // Decimal/decimal Tests |
125 | | - [Property] |
| 111 | + [FunckyAsyncProperty] |
126 | 112 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageAsyncForDecimal(IAsyncEnumerable<decimal> sequence) |
127 | 113 | => CompareAverageAndHandleEmptyDecimalSequenceAsync(sequence).Result.ToProperty(); |
128 | 114 |
|
129 | | - [Property] |
| 115 | + [FunckyAsyncProperty] |
130 | 116 | public Property AverageOrNoneAsyncGivesTheSameResultAsAverageForNullableAsyncForDecimal(IAsyncEnumerable<decimal?> sequence) |
131 | 117 | => (Option.FromNullable(sequence.AverageAsync().Result) |
132 | 118 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync().Result).ToProperty(); |
133 | 119 |
|
134 | | - [Property] |
| 120 | + [FunckyAsyncProperty] |
135 | 121 | public Property AverageOrNoneAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDecimal(IAsyncEnumerable<decimal?> sequence, Func<decimal?, decimal?> selector) |
136 | 122 | => (Option.FromNullable(sequence.AverageAsync(selector).Result) |
137 | 123 | == sequence.Select(Option.FromNullable).AverageOrNoneAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
138 | 124 |
|
139 | | - [Property] |
140 | | - public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDecimal(IAsyncEnumerable<decimal?> sequence, Func<decimal?, ValueTask<decimal?>> selector) |
141 | | - => (Option.FromNullable(sequence.AverageAwaitAsync(selector).Result) |
142 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 125 | + [FunckyAsyncProperty] |
| 126 | + public Property AverageOrNoneAwaitAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDecimal(IAsyncEnumerable<decimal?> sequence, AwaitSelector<decimal?> selector) |
| 127 | + => (Option.FromNullable(sequence.AverageAwaitAsync(selector.Get).Result) |
| 128 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
143 | 129 |
|
144 | | - [Property] |
145 | | - public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDecimal(IAsyncEnumerable<decimal?> sequence, Func<decimal?, CancellationToken, ValueTask<decimal?>> selector) |
146 | | - => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector).Result) |
147 | | - == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector)).Result).ToProperty(); |
| 130 | + [FunckyAsyncProperty] |
| 131 | + public Property AverageAwaitWithCancellationAsyncWithSelectorGivesTheSameResultAsAverageForNullableAsyncForDecimal(IAsyncEnumerable<decimal?> sequence, AwaitSelectorWithCancellation<decimal?> selector) |
| 132 | + => (Option.FromNullable(sequence.AverageAwaitWithCancellationAsync(selector.Get).Result) |
| 133 | + == sequence.Select(Option.FromNullable).AverageOrNoneAwaitWithCancellationAsync(SelectorTransformation.TransformNullableSelector(selector.Get)).Result).ToProperty(); |
148 | 134 |
|
149 | 135 | private static async Task<bool> CompareAverageAndHandleEmptyInt32SequenceAsync(IAsyncEnumerable<int> sequence) |
150 | 136 | => await sequence.AnyAsync() |
|
0 commit comments