public void Distinct_removes_duplicates_using_provided_equality_function() { var values = new[] { "a", "b", "A" }; Assert.True( new[] { "a", "b" }.SequenceEqual( values.Distinct((a, b) => a.Equals(b, StringComparison.OrdinalIgnoreCase)))); }
public void DistinctTest() { // ARRANGE var list = new[] { "a", "aa", "aaa", "b", "bb", "bbb" }; // ACT var distinct = list.Distinct(x => x.Length).ToList(); // ASSERT CollectionAssert.AreEqual(new[] { "a", "aa", "aaa" }, distinct); }
public void ShouldFilterOutDuplicateGcSettings() { var gcSettings = new[] { new GcBenchmarkSetting(GcMetric.TotalCollections, GcGeneration.Gen0, AssertionType.Throughput, Assertion.Empty), new GcBenchmarkSetting(GcMetric.TotalCollections, GcGeneration.Gen0, AssertionType.Total, Assertion.Empty), new GcBenchmarkSetting(GcMetric.TotalCollections, GcGeneration.Gen1, AssertionType.Throughput, Assertion.Empty), new GcBenchmarkSetting(GcMetric.TotalCollections, GcGeneration.Gen1, AssertionType.Total, Assertion.Empty) }; var distinctGcSettings = gcSettings.Distinct(GcBenchmarkSetting.GcBenchmarkDistinctComparer.Instance); // according to normal equality, all 4 should be distinct as they have different assertion settings Assert.Equal(4, gcSettings.Distinct().Count()); // but using our special EqualityComparer<T>, they really track only 2 distinct metrics Assert.Equal(2, distinctGcSettings.Count()); }
public void ShouldFilterOutDuplicateMemorySettings() { var memorySettings = new[] { new MemoryBenchmarkSetting(MemoryMetric.TotalBytesAllocated, Assertion.Empty), new MemoryBenchmarkSetting(MemoryMetric.TotalBytesAllocated, new Assertion(MustBe.ExactlyEqualTo, 1.0d, null)), }; var distinctMemorySettings = memorySettings.Distinct(MemoryBenchmarkSetting.MemoryBenchmarkDistinctComparer.Instance); Assert.Equal(2, memorySettings.Length); Assert.Equal(1, distinctMemorySettings.Count()); }
public void ShouldFilterOutDuplicateCounterSettings() { var counterSettings = new[] { new CounterBenchmarkSetting("counter1", AssertionType.Throughput, Assertion.Empty), new CounterBenchmarkSetting("counter1", AssertionType.Total, Assertion.Empty), new CounterBenchmarkSetting("counter2", AssertionType.Throughput, Assertion.Empty), new CounterBenchmarkSetting("counter2", AssertionType.Total, Assertion.Empty), }; var distinctMemorySettings = counterSettings.Distinct(CounterBenchmarkSetting.CounterBenchmarkDistinctComparer.Instance).ToList(); Assert.Equal(4, counterSettings.Length); Assert.Equal(2, distinctMemorySettings.Count()); Assert.Equal(1, distinctMemorySettings.Count(x => x.CounterName.CounterName.Equals("counter1"))); Assert.Equal(1, distinctMemorySettings.Count(x => x.CounterName.CounterName.Equals("counter2"))); }
public void TestDistinct() { var numbers = new[] {1, 2, 3, 3, 1, 1,}; var uniqueNumbers = numbers.Distinct(); Assert.That(uniqueNumbers.Count(), Is.EqualTo(3)); }