diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..24a0c26 --- /dev/null +++ b/init.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +set -eu + +dotnet build GildedRoseKata.sln --no-restore --verbosity quiet diff --git a/src/Core/ProposedCode/Domain/ItemKind.cs b/src/Core/ProposedCode/Domain/ItemKind.cs index 199f351..dd0ab6f 100644 --- a/src/Core/ProposedCode/Domain/ItemKind.cs +++ b/src/Core/ProposedCode/Domain/ItemKind.cs @@ -16,6 +16,10 @@ public sealed record Backstage : ItemKind; public sealed record Conjured : ItemKind; + public sealed record PhoenixFeather : ItemKind; + + public sealed record DragonfireWine : ItemKind; + public sealed record Sulfuras : ItemKind; public static ItemKind FromName(string itemName) @@ -28,8 +32,10 @@ public static ItemKind FromName(string itemName) "Backstage" => new Backstage(), "Conjured Mana Cake" => new Conjured(), "Conjured" => new Conjured(), + "Phoenix Feather" => new PhoenixFeather(), + "Dragonfire Wine" => new DragonfireWine(), "Sulfuras, Hand of Ragnaros" => new Sulfuras(), _ => new Standard(), }; } -} \ No newline at end of file +} diff --git a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs index 0221621..506e98b 100644 --- a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs +++ b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs @@ -15,6 +15,8 @@ public ItemState Mature(ItemKind kind, ItemState state) ItemKind.AgedBrie => this.MatureAgedBrie(state), ItemKind.Backstage => this.MatureBackstage(state), ItemKind.Conjured => this.MatureConjured(state), + ItemKind.PhoenixFeather => this.MaturePhoenixFeather(state), + ItemKind.DragonfireWine => this.MatureDragonfireWine(state), ItemKind.Sulfuras => state, _ => this.MatureStandard(state), }; @@ -77,4 +79,49 @@ private ItemState MatureConjured(ItemState state) return new(newQuality, newSellIn); } -} \ No newline at end of file + + private ItemState MaturePhoenixFeather(ItemState state) + { + var newSellIn = state.SellIn.NextDay(); + + if (state.SellIn.IsExpired) + { + return new(state.Quality.Decrease(4), newSellIn); + } + + var dailyGain = state.SellIn.Value == 5 ? 3 : 1; + var newQuality = state.Quality.Increase(dailyGain); + + if (newSellIn.IsExpired) + { + newQuality = newQuality.Decrease(4); + } + + return new(newQuality, newSellIn); + } + + private ItemState MatureDragonfireWine(ItemState state) + { + var newSellIn = state.SellIn.NextDay(); + + if (state.SellIn.IsExpired) + { + return new(state.Quality.Reset(), newSellIn); + } + + var dailyGain = state.SellIn switch + { + _ when state.SellIn.IsBelow(6) => 3, + _ when state.SellIn.IsBelow(11) => 2, + _ => 1, + }; + var newQuality = state.Quality.Increase(dailyGain); + + if (newSellIn.IsExpired) + { + newQuality = newQuality.Reset(); + } + + return new(newQuality, newSellIn); + } +} diff --git a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs index 4690ec6..c1a9409 100644 --- a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs +++ b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs @@ -35,4 +35,50 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit result.Quality.Should().Be(expectedQuality); result.SellIn.Should().Be(expectedSellIn); } -} \ No newline at end of file + + [Theory] + [InlineData(10, 5, 13, 4)] + [InlineData(10, 4, 11, 3)] + [InlineData(10, 0, 7, -1)] + [InlineData(49, 5, 50, 4)] + [InlineData(8, 0, 5, -1)] + public void F001_PhoenixFeather_GainsMilestoneBonusAndCoolsAfterExpiry(int quality, int sellIn, int expectedQuality, int expectedSellIn) + { + var service = new ItemMaturationService(); + var item = new Item + { + Name = "Phoenix Feather", + Quality = quality, + SellIn = sellIn, + }; + + var result = service.Mature(item); + + result.Quality.Should().Be(expectedQuality); + result.SellIn.Should().Be(expectedSellIn); + } + + [Theory] + [InlineData(10, 11, 11, 10)] + [InlineData(10, 10, 12, 9)] + [InlineData(10, 6, 12, 5)] + [InlineData(10, 5, 13, 4)] + [InlineData(10, 1, 13, 0)] + [InlineData(10, 0, 0, -1)] + [InlineData(49, 5, 50, 4)] + public void F002_DragonfireWine_FermentsThroughStagesAndSpoilsAfterExpiry(int quality, int sellIn, int expectedQuality, int expectedSellIn) + { + var service = new ItemMaturationService(); + var item = new Item + { + Name = "Dragonfire Wine", + Quality = quality, + SellIn = sellIn, + }; + + var result = service.Mature(item); + + result.Quality.Should().Be(expectedQuality); + result.SellIn.Should().Be(expectedSellIn); + } +}