Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Table of Contents
- [History](#history)
- [Kata Description](#kata-description)
- [Extension: Aged Wine](#extension-aged-wine)


## History
Expand Down Expand Up @@ -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".
6 changes: 5 additions & 1 deletion src/Core/ProposedCode/Domain/ItemKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand All @@ -32,4 +36,4 @@ public static ItemKind FromName(string itemName)
_ => new Standard(),
};
}
}
}
4 changes: 2 additions & 2 deletions src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -77,4 +77,4 @@ private ItemState MatureConjured(ItemState state)

return new(newQuality, newSellIn);
}
}
}
5 changes: 4 additions & 1 deletion tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
19 changes: 18 additions & 1 deletion tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -89,4 +106,4 @@ public void Mature_WhenKindIsSulfuras_PreservesProvidedState()

result.Should().Be(state);
}
}
}
5 changes: 4 additions & 1 deletion tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -35,4 +38,4 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit
result.Quality.Should().Be(expectedQuality);
result.SellIn.Should().Be(expectedSellIn);
}
}
}
Loading