forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntersectTests.cs
More file actions
88 lines (73 loc) · 2.91 KB
/
IntersectTests.cs
File metadata and controls
88 lines (73 loc) · 2.91 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
87
88
// 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.Collections.Generic;
using Xunit;
namespace System.Linq.Tests
{
public class IntersectTests : EnumerableBasedTests
{
[Fact]
public void BothEmpty()
{
int[] first = { };
int[] second = { };
Assert.Empty(first.AsQueryable().Intersect(second.AsQueryable()));
}
[Fact]
public void FirstNullCustomComparer()
{
IQueryable<string> first = null;
string[] second = { "ekiM", "bBo" };
var ane = AssertExtensions.Throws<ArgumentNullException>("source1", () => first.Intersect(second.AsQueryable(), new AnagramEqualityComparer()));
}
[Fact]
public void SecondNullCustomComparer()
{
string[] first = { "Tim", "Bob", "Mike", "Robert" };
IQueryable<string> second = null;
var ane = AssertExtensions.Throws<ArgumentNullException>("source2", () => first.AsQueryable().Intersect(second, new AnagramEqualityComparer()));
}
[Fact]
public void FirstNullNoComparer()
{
IQueryable<string> first = null;
string[] second = { "ekiM", "bBo" };
var ane = AssertExtensions.Throws<ArgumentNullException>("source1", () => first.Intersect(second.AsQueryable()));
}
[Fact]
public void SecondNullNoComparer()
{
string[] first = { "Tim", "Bob", "Mike", "Robert" };
IQueryable<string> second = null;
var ane = AssertExtensions.Throws<ArgumentNullException>("source2", () => first.AsQueryable().Intersect(second));
}
[Fact]
public void SingleNullWithEmpty()
{
string[] first = { null };
string[] second = new string[0];
Assert.Empty(first.AsQueryable().Intersect(second.AsQueryable(), EqualityComparer<string>.Default));
}
[Fact]
public void CustomComparer()
{
string[] first = { "Tim", "Bob", "Mike", "Robert" };
string[] second = { "ekiM", "bBo" };
string[] expected = { "Bob", "Mike" };
Assert.Equal(expected, first.AsQueryable().Intersect(second.AsQueryable(), new AnagramEqualityComparer()));
}
[Fact]
public void Intersect1()
{
var count = (new int[] { 0, 1, 2 }).AsQueryable().Intersect((new int[] { 1, 2, 3 }).AsQueryable()).Count();
Assert.Equal(2, count);
}
[Fact]
public void Intersect2()
{
var count = (new int[] { 0, 1, 2 }).AsQueryable().Intersect((new int[] { 1, 2, 3 }).AsQueryable(), EqualityComparer<int>.Default).Count();
Assert.Equal(2, count);
}
}
}