Initial commit
This commit is contained in:
commit
b087f272b4
26 changed files with 5345 additions and 0 deletions
81
Numbers.Test/NumberString/DigitEnumeratorTests.cs
Normal file
81
Numbers.Test/NumberString/DigitEnumeratorTests.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using Numbers.NumberString;
|
||||
|
||||
namespace Numbers.Test.NumberString;
|
||||
|
||||
public sealed class DigitEnumeratorTests
|
||||
{
|
||||
[Fact]
|
||||
public void MoveNext_NoMoreDigits()
|
||||
{
|
||||
var enumerator = new DigitEnumerator("abc");
|
||||
|
||||
enumerator.MoveNext().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MoveNext_MoreDigits()
|
||||
{
|
||||
var enumerator = new DigitEnumerator("abc123");
|
||||
|
||||
enumerator.MoveNext().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(EnumeratorTestData))]
|
||||
public void Current_CorrectDigit(string input, int moveSteps, int expectedDigit)
|
||||
{
|
||||
var enumerator = new DigitEnumerator(input);
|
||||
|
||||
enumerator.Current.Should().Be(-1, "enumerator not moved yet");
|
||||
for (var i = 0; i < moveSteps; i++)
|
||||
{
|
||||
enumerator.MoveNext();
|
||||
}
|
||||
|
||||
enumerator.Current.Should().Be(expectedDigit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reset()
|
||||
{
|
||||
var enumerator = new DigitEnumerator("abc123");
|
||||
enumerator.MoveNext();
|
||||
enumerator.MoveNext();
|
||||
|
||||
enumerator.Reset();
|
||||
enumerator.MoveNext();
|
||||
|
||||
enumerator.Current.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Interface()
|
||||
{
|
||||
var enumerator = new DigitEnumerator("abc123");
|
||||
|
||||
enumerator.Should().BeAssignableTo<IEnumerator<int>>();
|
||||
}
|
||||
|
||||
public static TheoryData<string, int, int> EnumeratorTestData() =>
|
||||
new()
|
||||
{
|
||||
{ "abc132", 1, 1 },
|
||||
{ "abc132", 2, 3 },
|
||||
{ "abc132", 3, 2 },
|
||||
{ "1abc23", 1, 1 },
|
||||
{ "1abc23", 2, 2 },
|
||||
{ "1abc23", 3, 3 },
|
||||
{ "a1b2c3", 1, 1 },
|
||||
{ "a1b2c3", 2, 2 },
|
||||
{ "a1b2c3", 3, 3 },
|
||||
{ "123abc", 1, 1 },
|
||||
{ "123abc", 2, 2 },
|
||||
{ "123abc", 3, 3 },
|
||||
{ "2def456", 1, 2 },
|
||||
{ "2def456", 2, 4 },
|
||||
{ "2def456", 3, 5 },
|
||||
{ "d4ef56", 1, 4 },
|
||||
{ "d4ef56", 2, 5 },
|
||||
{ "d4ef56", 3, 6 }
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue