Files

30 lines
792 B
C#

namespace R3.Tests.OperatorTests;
public class ToHashSetTest
{
[Fact]
public async Task Many()
{
var source = new int[] { 1, 10, 1, 3, 4, 6, 7, 4 }.ToObservable();
var set = await source.ToHashSetAsync();
set.ShouldBe(new int[] { 1, 10, 3, 4, 6, 7 });
}
[Fact]
public async Task SetComparer()
{
var source = new int[] { 1, 10, 1, 3, 4, 6, 7, 4 }.ToObservable();
var set = await source.ToHashSetAsync(new TestComparer());
set.ShouldBe((int[])[1, 10, 3, 4, 6, 7]);
set.Comparer.GetType().ShouldBe(typeof(TestComparer));
}
class TestComparer : IEqualityComparer<int>
{
public bool Equals(int x, int y) => x == y;
public int GetHashCode(int obj) => obj.GetHashCode();
}
}