diff --git a/LinqFaster/Distinct.cs b/LinqFaster/Distinct.cs index d20f426..3f063e0 100644 --- a/LinqFaster/Distinct.cs +++ b/LinqFaster/Distinct.cs @@ -24,6 +24,11 @@ public static void DistinctInPlaceF(this List source, IEqualit throw Error.ArgumentNull("source"); } + if (source.Count == 0) + { + return; + } + if (comparer == null) { comparer = Comparer.Default; diff --git a/Tests/DistinctTests.cs b/Tests/DistinctTests.cs index 727e6dd..71571e6 100644 --- a/Tests/DistinctTests.cs +++ b/Tests/DistinctTests.cs @@ -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(); + emptyList.DistinctInPlaceF(); + } + + [Test] + public void DistinctInPlaceIntegerList() + { + var list = new List() { 1, 2, 2, 3, 3, 3 }; + var a = new List(list); + var b = list.Distinct().ToList(); + + a.DistinctInPlaceF(); + + Assert.That(a, Is.EqualTo(b)); + } } }