diff --git a/README.md b/README.md index 7d742a9..af02112 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ ## Table of Contents - [History](#history) - [Kata Description](#kata-description) +- [Extension: Aged Wine](#extension-aged-wine) ## History @@ -60,3 +61,13 @@ Just for clarification, an item can never have its Quality increase above 50, however "Sulfuras" is a legendary item and as such its Quality is 80 and it never alters. +## Extension: Aged Wine + +"Aged Wine" is an added product that matures like "Aged Brie": + +- Quality increases by 1 per day +- Quality increases by 2 per day once the sell by date has passed +- Quality is never more than 50 +- SellIn decreases by 1 per day + +The item is recognized by the names "Aged Wine" and "AgedWine". diff --git a/src/Core/ProposedCode/Domain/ItemKind.cs b/src/Core/ProposedCode/Domain/ItemKind.cs index 199f351..f625c06 100644 --- a/src/Core/ProposedCode/Domain/ItemKind.cs +++ b/src/Core/ProposedCode/Domain/ItemKind.cs @@ -12,6 +12,8 @@ public sealed record Standard : ItemKind; public sealed record AgedBrie : ItemKind; + public sealed record AgedWine : ItemKind; + public sealed record Backstage : ItemKind; public sealed record Conjured : ItemKind; @@ -24,6 +26,8 @@ public static ItemKind FromName(string itemName) { "Aged Brie" => new AgedBrie(), "AgedBrie" => new AgedBrie(), + "Aged Wine" => new AgedWine(), + "AgedWine" => new AgedWine(), "Backstage passes to a TAFKAL80ETC concert" => new Backstage(), "Backstage" => new Backstage(), "Conjured Mana Cake" => new Conjured(), @@ -32,4 +36,4 @@ public static ItemKind FromName(string itemName) _ => 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..56fcc11 100644 --- a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs +++ b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs @@ -12,7 +12,7 @@ public ItemState Mature(ItemKind kind, ItemState state) { return kind switch { - ItemKind.AgedBrie => this.MatureAgedBrie(state), + ItemKind.AgedBrie or ItemKind.AgedWine => this.MatureAgedBrie(state), ItemKind.Backstage => this.MatureBackstage(state), ItemKind.Conjured => this.MatureConjured(state), ItemKind.Sulfuras => state, @@ -77,4 +77,4 @@ private ItemState MatureConjured(ItemState state) return new(newQuality, newSellIn); } -} \ No newline at end of file +} diff --git a/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs b/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs index 040e12d..4b09bbf 100644 --- a/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs +++ b/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs @@ -13,16 +13,19 @@ public class ItemKindTests [Theory] [InlineData("Aged Brie", typeof(ItemKind.AgedBrie))] [InlineData("AgedBrie", typeof(ItemKind.AgedBrie))] + [InlineData("Aged Wine", typeof(ItemKind.AgedWine))] + [InlineData("AgedWine", typeof(ItemKind.AgedWine))] [InlineData("Backstage passes to a TAFKAL80ETC concert", typeof(ItemKind.Backstage))] [InlineData("Backstage", typeof(ItemKind.Backstage))] [InlineData("Conjured Mana Cake", typeof(ItemKind.Conjured))] [InlineData("Conjured", typeof(ItemKind.Conjured))] [InlineData("Sulfuras, Hand of Ragnaros", typeof(ItemKind.Sulfuras))] [InlineData("Elixir of the Mongoose", typeof(ItemKind.Standard))] + [InlineData("Aged Cheese", typeof(ItemKind.Standard))] public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType) { var result = ItemKind.FromName(itemName); result.Should().BeOfType(expectedType); } -} \ No newline at end of file +} diff --git a/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs b/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs index 55d645c..2c67d5c 100644 --- a/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs +++ b/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs @@ -43,6 +43,23 @@ public void Mature_WhenKindIsAgedBrie_FollowsExpectedRules(int quality, int sell result.SellIn.Value.Should().Be(expectedSellIn); } + [Theory] + [InlineData(20, 4, 21, 3)] + [InlineData(20, 0, 22, -1)] + [InlineData(49, 0, 50, -1)] + [InlineData(50, 4, 50, 3)] + [InlineData(50, 0, 50, -1)] + [InlineData(0, 5, 1, 4)] + public void Mature_WhenKindIsAgedWine_FollowsExpectedRules(int quality, int sellIn, int expectedQuality, int expectedSellIn) + { + var state = new ItemState(new Quality(quality), new SellIn(sellIn)); + + var result = this.policy.Mature(new ItemKind.AgedWine(), state); + + result.Quality.Value.Should().Be(expectedQuality); + result.SellIn.Value.Should().Be(expectedSellIn); + } + [Theory] [InlineData(20, 15, 21, 14)] [InlineData(20, 11, 21, 10)] @@ -89,4 +106,4 @@ public void Mature_WhenKindIsSulfuras_PreservesProvidedState() result.Should().Be(state); } -} \ No newline at end of file +} diff --git a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs index 4690ec6..9fc06c7 100644 --- a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs +++ b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs @@ -15,6 +15,9 @@ public class ItemMaturationServiceTests [InlineData("Elixir of the Mongoose", 10, 5, 9, 4)] [InlineData("Aged Brie", 10, 2, 11, 1)] [InlineData("AgedBrie", 10, 2, 11, 1)] + [InlineData("Aged Wine", 10, 2, 11, 1)] + [InlineData("AgedWine", 10, 0, 12, -1)] + [InlineData("Aged Wine", 50, 3, 50, 2)] [InlineData("Backstage passes to a TAFKAL80ETC concert", 20, 10, 22, 9)] [InlineData("Backstage", 20, 5, 23, 4)] [InlineData("Conjured Mana Cake", 10, 5, 8, 4)] @@ -35,4 +38,4 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit result.Quality.Should().Be(expectedQuality); result.SellIn.Should().Be(expectedSellIn); } -} \ No newline at end of file +}