-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Linq; | ||
using FluentAssertions; | ||
using Local.Collections; | ||
using Xunit; | ||
|
||
namespace Local.Tests.Collections | ||
{ | ||
public class FirstOrDefaultShould : LinqTests | ||
{ | ||
[Theory, MemberData(nameof(Items))] | ||
public void FindFirstByPredicate(int[] items) | ||
{ | ||
static bool Predicate(int i) => i == 1; | ||
|
||
var vector = new LocalVector<int>(items); | ||
|
||
vector | ||
.FirstOrDefault(Predicate) | ||
.Should().Be(items.FirstOrDefault(Predicate)); | ||
} | ||
|
||
[Theory, MemberData(nameof(Items))] | ||
public void FindFirstByPredicateWithArg(int[] items) | ||
{ | ||
const int argument = 1; | ||
|
||
var vector = new LocalVector<int>(items); | ||
|
||
vector | ||
.FirstOrDefault((i, arg) => i == arg, argument) | ||
.Should().Be(items.FirstOrDefault(i => i == argument)); | ||
} | ||
|
||
[Fact] | ||
public void NotThrowIfNotFoundByPredicate() | ||
{ | ||
new LocalVector<int>() | ||
.FirstOrDefault(i => i == 1) | ||
.Should().Be(0); | ||
} | ||
|
||
[Fact] | ||
public void NotThrowIfNotFoundByPredicateWithArg() | ||
{ | ||
const int argument = 1; | ||
|
||
new LocalVector<int>() | ||
.FirstOrDefault((i, arg) => i == arg, argument) | ||
.Should().Be(0); | ||
} | ||
|
||
[Theory, MemberData(nameof(Items))] | ||
public void ReturnFirstOrDefaultElement(int[] items) | ||
{ | ||
var vector = new LocalVector<int>(items); | ||
|
||
vector | ||
.FirstOrDefault() | ||
.Should().Be(items.FirstOrDefault()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters