Skip to content

Commit

Permalink
Improve tests for To*.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdesmet committed Feb 27, 2019
1 parent f0e8a53 commit 2cdc2af
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,47 @@ public async Task ToArray_Null()
}

[Fact]
public async Task ToArray1()
public async Task ToArray_IAsyncIListProvider_Simple()
{
var xs = new[] { 42, 25, 39 };
var res = xs.ToAsyncEnumerable().ToArrayAsync();
Assert.True((await res).SequenceEqual(xs));
}

[Fact]
public async Task ToArray2()
public async Task ToArray_IAsyncIListProvider_Empty1()
{
var xs = new int[0];
var res = xs.ToAsyncEnumerable().ToArrayAsync();
Assert.True((await res).SequenceEqual(xs));
}

[Fact]
public async Task ToArray_IAsyncIListProvider_Empty2()
{
var xs = new HashSet<int>();
var res = xs.ToAsyncEnumerable().ToArrayAsync();
Assert.True((await res).SequenceEqual(xs));
}

[Fact]
public async Task ToArray_Empty()
{
var xs = AsyncEnumerable.Empty<int>();
var res = xs.ToArrayAsync();
Assert.True((await res).Length == 0);
}

[Fact]
public async Task ToArray3Async()
public async Task ToArray_Throw()
{
var ex = new Exception("Bang!");
var res = Throw<int>(ex).ToArrayAsync();
await AssertThrowsAsync(res, ex);
}

[Fact]
public async Task ToArray4()
public async Task ToArray_Query()
{
var xs = await AsyncEnumerable.Range(5, 50).Take(10).ToArrayAsync();
var ex = new[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
Expand All @@ -54,7 +70,7 @@ public async Task ToArray4()
}

[Fact]
public async Task ToArray5()
public async Task ToArray_Set()
{
var res = new[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
var xs = new HashSet<int>(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,26 @@ public async Task ToHashSet_Null()
}

[Fact]
public async Task ToHashSet1()
public async Task ToHashSet_Simple()
{
var xs = new[] { 1, 2, 1, 2, 3, 4, 1, 2, 3, 4 };
var res = xs.ToAsyncEnumerable().ToHashSetAsync();
Assert.True((await res).OrderBy(x => x).SequenceEqual(new[] { 1, 2, 3, 4 }));
}

[Fact]
public async Task ToHashSet_Comparer()
{
var xs = new[] { 1, 12, 11, 2, 3, 14, 1, 12, 13, 4 };
var res = xs.ToAsyncEnumerable().ToHashSetAsync(new Eq());
Assert.True((await res).OrderBy(x => x).SequenceEqual(new[] { 1, 3, 12, 14 }));
}

private class Eq : IEqualityComparer<int>
{
public bool Equals(int x, int y) => x % 10 == y % 10;

public int GetHashCode(int obj) => obj % 10;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ public async Task ToList_Null()
}

[Fact]
public async Task ToList1()
public async Task ToList_Simple()
{
var xs = new[] { 42, 25, 39 };
var res = xs.ToAsyncEnumerable().ToListAsync();
Assert.True((await res).SequenceEqual(xs));
}

[Fact]
public async Task ToList2()
public async Task ToList_Empty()
{
var xs = AsyncEnumerable.Empty<int>();
var res = xs.ToListAsync();
Assert.True((await res).Count == 0);
}

[Fact]
public async Task ToList3Async()
public async Task ToList_Throw()
{
var ex = new Exception("Bang!");
var res = Throw<int>(ex).ToListAsync();
Expand Down

0 comments on commit 2cdc2af

Please sign in to comment.