Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions LinqFaster/Distinct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public static void DistinctInPlaceF<TSource>(this List<TSource> source, IEqualit
throw Error.ArgumentNull("source");
}

if (source.Count == 0)
{
return;
}

if (comparer == null)
{
comparer = Comparer<TSource>.Default;
Expand Down
23 changes: 22 additions & 1 deletion Tests/DistinctTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
using NUnit.Framework;
using JM.LinqFaster;
using System.Linq;
using static Tests.Test;
using System.Collections.Generic;

namespace Tests
{
[TestFixture]
class DistinctTests {


[Test]
public void DistinctInPlaceEmptyList()
{
var emptyList = new List<int>();

emptyList.DistinctInPlaceF();
}

[Test]
public void DistinctInPlaceIntegerList()
{
var list = new List<int>() { 1, 2, 2, 3, 3, 3 };
var a = new List<int>(list);
var b = list.Distinct().ToList();

a.DistinctInPlaceF();

Assert.That(a, Is.EqualTo(b));
}
}
}