feat: solve part 2
This commit is contained in:
@@ -29,7 +29,7 @@ public class TurnTests
|
||||
public void OrderBy_WhenGivenListOfTurns_ItShouldBeAbleToOrderThemAccordingToHandStrength()
|
||||
{
|
||||
var turns = TestData.TestTurns
|
||||
.Select(Turn.Parse)
|
||||
.Select(t => Turn.Parse(t))
|
||||
.ToList();
|
||||
|
||||
turns
|
||||
@@ -51,7 +51,7 @@ public class TurnTests
|
||||
public void OrderByDescending_WhenGivenListOfTurns_ItShouldBeAbleToOrderThemAccordingToHandStrength()
|
||||
{
|
||||
var turns = TestData.TestTurns
|
||||
.Select(Turn.Parse)
|
||||
.Select(t => Turn.Parse(t))
|
||||
.ToList();
|
||||
|
||||
turns
|
||||
@@ -69,11 +69,33 @@ public class TurnTests
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrderBy_WhenGivenListOfTurnsAndJokersAreTreatedAsWild_ItShouldBeAbleToOrderThemAccordingToHandStrength()
|
||||
{
|
||||
var turns = TestData.TestTurns
|
||||
.Select(t => Turn.Parse(t, true))
|
||||
.ToList();
|
||||
|
||||
turns
|
||||
.OrderBy(t => t.Hand)
|
||||
.Select(t => t.ToString())
|
||||
.Should()
|
||||
.BeEquivalentTo(
|
||||
[
|
||||
"32T3K 765",
|
||||
"KK677 28",
|
||||
"T55J5 684",
|
||||
"QQQJA 483",
|
||||
"KTJJT 220",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Turn_GivenListOfTurns_ItShouldBeAbleToCalculateTotalWinnings()
|
||||
{
|
||||
TestData.TestTurns
|
||||
.Select(Turn.Parse)
|
||||
.Select(t => Turn.Parse(t))
|
||||
.OrderBy(t => t.Hand)
|
||||
.Select((turn, index) => turn.Bid * (index + 1))
|
||||
.Sum()
|
||||
@@ -81,8 +103,89 @@ public class TurnTests
|
||||
.Be(6440);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Turn_GivenListOfTurnsAndJokersAreWild_ItShouldBeAbleToCalculateTotalWinnings()
|
||||
{
|
||||
TestData.TestTurns
|
||||
.Select(t => Turn.Parse(t, true))
|
||||
.OrderBy(t => t.Hand)
|
||||
.Select((turn, index) => turn.Bid * (index + 1))
|
||||
.Sum()
|
||||
.Should()
|
||||
.Be(5905);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(TestData.TestTurnsWithJokersData), MemberType = typeof(TestData))]
|
||||
public void Turn_GivenListOfTurnsWithJokers_ItShouldHaveCorrectHandType(string turn, HandType expectedHandType)
|
||||
{
|
||||
Turn.Parse(turn, true).Hand.Type.Should().Be(expectedHandType);
|
||||
}
|
||||
|
||||
public static class TestData
|
||||
{
|
||||
public static readonly string[] InputTurnsWithJokers = File.ReadAllLines("INPUT.txt").Where(l => l.Contains('J')).ToArray();
|
||||
|
||||
public static IEnumerable<object[]> TestTurnsWithJokersData =>
|
||||
new List<object[]>
|
||||
{
|
||||
new object[]
|
||||
{
|
||||
"4446J 425",
|
||||
HandType.FourOfAKind,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"26J93 60",
|
||||
HandType.OnePair,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"TQ9JQ 554",
|
||||
HandType.ThreeOfAKind,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"J373A 525",
|
||||
HandType.ThreeOfAKind,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"44JJ4 738",
|
||||
HandType.FiveOfAKind,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"JTK95 684",
|
||||
HandType.OnePair,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"5J39Q 743",
|
||||
HandType.OnePair,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"222J2 833",
|
||||
HandType.FiveOfAKind,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"JJJ44 668",
|
||||
HandType.FiveOfAKind,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"4JK47 317",
|
||||
HandType.ThreeOfAKind,
|
||||
},
|
||||
new object[]
|
||||
{
|
||||
"66J4J 253",
|
||||
HandType.FourOfAKind,
|
||||
}
|
||||
};
|
||||
|
||||
public static readonly string[] TestTurns =
|
||||
[
|
||||
"32T3K 765",
|
||||
|
||||
Reference in New Issue
Block a user