-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
ContainsTests.cs
108 lines (95 loc) · 4.02 KB
/
ContainsTests.cs
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using Xunit;
namespace System.Linq.Parallel.Tests
{
public static class ContainsTests
{
public static IEnumerable<object[]> OnlyOneData(int[] counts)
{
foreach (int count in counts.DefaultIfEmpty(Sources.OuterLoopCount))
{
foreach (int position in new[] { 0, count / 2, Math.Max(0, count - 1) }.Distinct())
{
yield return new object[] { count, position };
}
}
}
//
// Contains
//
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
[InlineData(16)]
public static void Contains_NoMatching(int count)
{
Assert.False(ParallelEnumerable.Range(0, count).Contains(count));
Assert.False(ParallelEnumerable.Range(0, count).Contains(count, null));
Assert.False(ParallelEnumerable.Range(0, count).Contains(count, EqualityComparer<int>.Create((l, r) => false)));
}
[Fact]
[OuterLoop]
public static void Contains_NoMatching_Longrunning()
{
Contains_NoMatching(Sources.OuterLoopCount);
}
[Theory]
[InlineData(16)]
public static void Contains_MultipleMatching(int count)
{
Assert.True(ParallelEnumerable.Range(0, count).Contains(count, EqualityComparer<int>.Create((l, r) => (l % 2) == (r % 2))));
}
[Fact]
[OuterLoop]
public static void Contains_MultipleMatching_Longrunning()
{
Contains_MultipleMatching(Sources.OuterLoopCount);
}
[Theory]
[MemberData(nameof(OnlyOneData), new[] { 2, 16 })]
public static void Contains_OneMatching(int count, int position)
{
Assert.True(ParallelEnumerable.Range(0, count).Contains(position));
Assert.True(ParallelEnumerable.Range(0, count).Contains(position, null));
Assert.True(ParallelEnumerable.Range(0, count).Contains(position, EqualityComparer<int>.Create((l, r) => l == position && r == position)));
}
[Theory]
[OuterLoop]
[MemberData(nameof(OnlyOneData), new int[] { /* Sources.OuterLoopCount */ })]
public static void Contains_OneMatching_Longrunning(int count, int position)
{
Contains_OneMatching(count, position);
}
[Fact]
public static void Contains_OperationCanceledException()
{
AssertThrows.EventuallyCanceled((source, canceler) => source.Contains(-1, new CancelingEqualityComparer<int>(canceler)));
}
[Fact]
public static void Contains_AggregateException_Wraps_OperationCanceledException()
{
AssertThrows.OtherTokenCanceled((source, canceler) => source.Contains(-1, new CancelingEqualityComparer<int>(canceler)));
AssertThrows.SameTokenNotCanceled((source, canceler) => source.Contains(-1, new CancelingEqualityComparer<int>(canceler)));
}
[Fact]
public static void Contains_OperationCanceledException_PreCanceled()
{
AssertThrows.AlreadyCanceled(source => source.Contains(0));
AssertThrows.AlreadyCanceled(source => source.Contains(0, EqualityComparer<int>.Default));
}
[Fact]
public static void Contains_AggregateException()
{
AssertThrows.Wrapped<DeliberateTestException>(() => ParallelEnumerable.Range(0, 1).Contains(1, new FailingEqualityComparer<int>()));
}
[Fact]
public static void Contains_ArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("source", () => ((ParallelQuery<bool>)null).Contains(false));
AssertExtensions.Throws<ArgumentNullException>("source", () => ((ParallelQuery<bool>)null).Contains(false, EqualityComparer<bool>.Default));
}
}
}