Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Except and intersect variations (v3) #169

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
129 changes: 129 additions & 0 deletions MoreLinq.Test/ExceptAllByTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#region License and Terms
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace MoreLinq.Test
{
[TestFixture]
public class ExceptAllByTest
{
[Test]
public void SimpleExceptAllBy()
{
string[] first = { "aaa", "bb", "c", "dddd" };
string[] second = { "xx", "y" };
var result = first.ExceptAllBy(second, x => x.Length);
result.AssertSequenceEqual("aaa", "dddd");
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllByNullFirstSequence()
{
string[] first = null;
string[] second = { "aaa" };
first.ExceptAllBy(second, x => x.Length);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllByNullSecondSequence()
{
string[] first = { "aaa" };
string[] second = null;
first.ExceptAllBy(second, x => x.Length);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllByNullKeySelector()
{
string[] first = { "aaa" };
string[] second = { "aaa" };
first.ExceptAllBy(second, (Func<string, string>)null);
}

[Test]
public void ExceptAllByIsLazy()
{
new BreakingSequence<string>().ExceptAllBy(new string[0], x => x.Length);
}

[Test]
public void ExceptAllByRepeatsSourceElementsWithDuplicateKeys()
{
string[] first = { "aaa", "bb", "c", "a", "b", "c", "dddd" };
string[] second = { "xx" };
var result = first.ExceptAllBy(second, x => x.Length);
result.AssertSequenceEqual("aaa", "c", "a", "b", "c", "dddd");
}

[Test]
public void ExceptAllByWithComparer()
{
string[] first = { "first", "second", "third", "fourth" };
string[] second = { "FIRST", "thiRD", "FIFTH" };
var result = first.ExceptBy(second, word => word, StringComparer.OrdinalIgnoreCase);
result.AssertSequenceEqual("second", "fourth");
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllByNullFirstSequenceWithComparer()
{
string[] first = null;
string[] second = { "aaa" };
first.ExceptAllBy(second, x => x.Length, EqualityComparer<int>.Default);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllByNullSecondSequenceWithComparer()
{
string[] first = { "aaa" };
string[] second = null;
first.ExceptAllBy(second, x => x.Length, EqualityComparer<int>.Default);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllByNullKeySelectorWithComparer()
{
string[] first = { "aaa" };
string[] second = { "aaa" };
first.ExceptAllBy(second, null, EqualityComparer<string>.Default);
}

[Test]
public void ExceptAllByNullComparer()
{
string[] first = { "aaa", "bb", "bb", "c", "dddd", "dddd" };
string[] second = { "xx", "y" };
var result = first.ExceptAllBy(second, x => x.Length, null);
result.AssertSequenceEqual("aaa", "dddd", "dddd");
}

[Test]
public void ExceptAllByIsLazyWithComparer()
{
new BreakingSequence<string>().ExceptAllBy(new string[0], x => x, StringComparer.Ordinal);
}
}
}
129 changes: 129 additions & 0 deletions MoreLinq.Test/ExceptAllKeysTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#region License and Terms
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace MoreLinq.Test
{
[TestFixture]
public class ExceptAllKeysTest
{
[Test]
public void SimpleExceptAllKeys()
{
string[] first = { "aaa", "bb", "c", "dddd" };
int[] second = { 1, 2 };
var result = first.ExceptAllKeys(second, x => x.Length);
result.AssertSequenceEqual("aaa", "dddd");
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllKeysNullFirstSequence()
{
string[] first = null;
int[] second = { 1 };
first.ExceptAllKeys(second, x => x.Length);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllKeysNullSecondSequence()
{
string[] first = { "aaa" };
int[] second = null;
first.ExceptAllKeys(second, x => x.Length);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllKeysNullKeySelector()
{
string[] first = { "aaa" };
int[] second = { 1 };
first.ExceptAllKeys(second, (Func<string, int>)null);
}

[Test]
public void ExceptAllKeysIsLazy()
{
new BreakingSequence<string>().ExceptAllKeys(new int[0], x => x.Length);
}

[Test]
public void ExceptAllKeysRepeatsSourceElementsWithDuplicateKeys()
{
string[] first = { "aaa", "bb", "c", "a", "b", "c", "dddd" };
int[] second = { 2 };
var result = first.ExceptAllKeys(second, x => x.Length);
result.AssertSequenceEqual("aaa", "c", "a", "b", "c", "dddd");
}

[Test]
public void ExceptAllKeysWithComparer()
{
string[] first = { "first", "second", "third", "fourth" };
string[] second = { "FIRST" , "thiRD", "FIFTH" };
var result = first.ExceptAllKeys(second, word => word, StringComparer.OrdinalIgnoreCase);
result.AssertSequenceEqual("second", "fourth");
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllKeysNullFirstSequenceWithComparer()
{
string[] first = null;
int[] second = { 1 };
first.ExceptAllKeys(second, x => x.Length, EqualityComparer<int>.Default);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllKeysNullSecondSequenceWithComparer()
{
string[] first = { "aaa" };
int[] second = null;
first.ExceptAllKeys(second, x => x.Length, EqualityComparer<int>.Default);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptAllKeysNullKeySelectorWithComparer()
{
string[] first = { "aaa" };
int[] second = { 1 };
first.ExceptAllKeys(second, null, EqualityComparer<int>.Default);
}

[Test]
public void ExceptAllKeysNullComparer()
{
string[] first = { "aaa", "aaa", "bb", "c", "dddd" };
int[] second = { 1, 2 };
var result = first.ExceptAllKeys(second, x => x.Length, null);
result.AssertSequenceEqual("aaa", "aaa", "dddd");
}

[Test]
public void ExceptAllKeysIsLazyWithComparer()
{
new BreakingSequence<string>().ExceptAllKeys(new string[0], x => x, StringComparer.Ordinal);
}
}
}
129 changes: 129 additions & 0 deletions MoreLinq.Test/ExceptKeysTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#region License and Terms
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace MoreLinq.Test
{
[TestFixture]
public class ExceptKeysTest
{
[Test]
public void SimpleExceptKeys()
{
string[] first = { "aaa", "bb", "c", "dddd" };
int[] second = { 1, 2 };
var result = first.ExceptKeys(second, x => x.Length);
result.AssertSequenceEqual("aaa", "dddd");
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptKeysNullFirstSequence()
{
string[] first = null;
int[] second = { 1 };
first.ExceptKeys(second, x => x.Length);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptKeysNullSecondSequence()
{
string[] first = { "aaa" };
int[] second = null;
first.ExceptKeys(second, x => x.Length);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptKeysNullKeySelector()
{
string[] first = { "aaa" };
int[] second = { 1 };
first.ExceptKeys(second, (Func<string, int>)null);
}

[Test]
public void ExceptKeysIsLazy()
{
new BreakingSequence<string>().ExceptKeys(new int[0], x => x.Length);
}

[Test]
public void ExceptKeysDoesNotRepeatSourceElementsWithDuplicateKeys()
{
string[] first = { "aaa", "bb", "c", "a", "b", "c", "dddd" };
int[] second = { 2 };
var result = first.ExceptKeys(second, x => x.Length);
result.AssertSequenceEqual("aaa", "c", "dddd");
}

[Test]
public void ExceptKeysWithComparer()
{
string[] first = { "first", "second", "third", "fourth" };
string[] second = { "FIRST" , "thiRD", "FIFTH" };
var result = first.ExceptKeys(second, word => word, StringComparer.OrdinalIgnoreCase);
result.AssertSequenceEqual("second", "fourth");
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptKeysNullFirstSequenceWithComparer()
{
string[] first = null;
int[] second = { 1 };
first.ExceptKeys(second, x => x.Length, EqualityComparer<int>.Default);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptKeysNullSecondSequenceWithComparer()
{
string[] first = { "aaa" };
int[] second = null;
first.ExceptKeys(second, x => x.Length, EqualityComparer<int>.Default);
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptKeysNullKeySelectorWithComparer()
{
string[] first = { "aaa" };
int[] second = { 1 };
first.ExceptKeys(second, null, EqualityComparer<int>.Default);
}

[Test]
public void ExceptKeysNullComparer()
{
string[] first = { "aaa", "bb", "c", "dddd" };
int[] second = { 1, 2 };
var result = first.ExceptKeys(second, x => x.Length, null);
result.AssertSequenceEqual("aaa", "dddd");
}

[Test]
public void ExceptKeysIsLazyWithComparer()
{
new BreakingSequence<string>().ExceptKeys(new string[0], x => x, StringComparer.Ordinal);
}
}
}
Loading