forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnionTests.cs
More file actions
83 lines (67 loc) · 2.77 KB
/
UnionTests.cs
File metadata and controls
83 lines (67 loc) · 2.77 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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Xunit;
namespace System.Linq.Tests
{
public class UnionTests : EnumerableBasedTests
{
[Fact]
public void CustomComparer()
{
string[] first = { "Bob", "Robert", "Tim", "Matt", "miT" };
string[] second = { "ttaM", "Charlie", "Bbo" };
string[] expected = { "Bob", "Robert", "Tim", "Matt", "Charlie" };
var comparer = new AnagramEqualityComparer();
Assert.Equal(expected, first.AsQueryable().Union(second.AsQueryable(), comparer), comparer);
}
[Fact]
public void FirstNullCustomComparer()
{
IQueryable<string> first = null;
string[] second = { "ttaM", "Charlie", "Bbo" };
var ane = Assert.Throws<ArgumentNullException>("source1", () => first.Union(second.AsQueryable(), new AnagramEqualityComparer()));
}
[Fact]
public void SecondNullCustomComparer()
{
string[] first = { "Bob", "Robert", "Tim", "Matt", "miT" };
IQueryable<string> second = null;
var ane = Assert.Throws<ArgumentNullException>("source2", () => first.AsQueryable().Union(second, new AnagramEqualityComparer()));
}
[Fact]
public void FirstNullNoComparer()
{
IQueryable<string> first = null;
string[] second = { "ttaM", "Charlie", "Bbo" };
var ane = Assert.Throws<ArgumentNullException>("source1", () => first.Union(second.AsQueryable()));
}
[Fact]
public void SecondNullNoComparer()
{
string[] first = { "Bob", "Robert", "Tim", "Matt", "miT" };
IQueryable<string> second = null;
var ane = Assert.Throws<ArgumentNullException>("source2", () => first.AsQueryable().Union(second));
}
[Fact]
public void CommonElementsShared()
{
int[] first = { 1, 2, 3, 4, 5, 6 };
int[] second = { 6, 7, 7, 7, 8, 1 };
int[] expected = { 1, 2, 3, 4, 5, 6, 7, 8 };
Assert.Equal(expected, first.AsQueryable().Union(second.AsQueryable()));
}
[Fact]
public void Union1()
{
var count = (new int[] { 0, 1, 2 }).AsQueryable().Union((new int[] { 1, 2, 3 }).AsQueryable()).Count();
Assert.Equal(4, count);
}
[Fact]
public void Union2()
{
var count = (new int[] { 0, 1, 2 }).AsQueryable().Union((new int[] { 1, 2, 3 }).AsQueryable(), EqualityComparer<int>.Default).Count();
Assert.Equal(4, count);
}
}
}