// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; using System.Text; using System.Linq; using Xunit; namespace Tests { public class DistinctUntilChangedTest : Tests { [Fact] public void DistinctUntilChanged_Arguments() { AssertThrows(() => EnumerableEx.DistinctUntilChanged(null)); AssertThrows(() => EnumerableEx.DistinctUntilChanged(null, EqualityComparer.Default)); AssertThrows(() => EnumerableEx.DistinctUntilChanged(new[] { 1 }, null)); AssertThrows(() => EnumerableEx.DistinctUntilChanged(null, _ => _)); AssertThrows(() => EnumerableEx.DistinctUntilChanged(new[] { 1 }, null)); AssertThrows(() => EnumerableEx.DistinctUntilChanged(null, _ => _, EqualityComparer.Default)); AssertThrows(() => EnumerableEx.DistinctUntilChanged(new[] { 1 }, null, EqualityComparer.Default)); AssertThrows(() => EnumerableEx.DistinctUntilChanged(new[] { 1 }, _ => _, null)); } [Fact] public void DistinctUntilChanged1() { var res = new[] { 1, 2, 2, 3, 3, 3, 2, 2, 1 }.DistinctUntilChanged().ToList(); Assert.True(Enumerable.SequenceEqual(res, new[] { 1, 2, 3, 2, 1 })); } [Fact] public void DistinctUntilChanged2() { var res = new[] { 1, 1, 2, 3, 4, 5, 5, 6, 7 }.DistinctUntilChanged(x => x / 2).ToList(); Assert.True(Enumerable.SequenceEqual(res, new[] { 1, 2, 4, 6 })); } } }