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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Pretty simple, right? Well this is where it gets interesting:
- Once the sell by date has passed, Quality degrades twice as fast
- The Quality of an item is never negative
- "Aged Brie" actually increases in Quality the older it gets
- "Aged Cheddar" behaves like "Aged Brie" (Quality increases the older it gets)
- The Quality of an item is never more than 50
- "Sulfuras", being a legendary item, never has to be sold or decreases
in Quality
Expand All @@ -59,4 +60,3 @@ method and Items property static if you like, we'll cover for you).
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.

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 AgedCheddar : 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 Cheddar" => new AgedCheddar(),
"AgedCheddar" => new AgedCheddar(),
"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.AgedCheddar => 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);
}
}
}
4 changes: 3 additions & 1 deletion tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ItemKindTests
[Theory]
[InlineData("Aged Brie", typeof(ItemKind.AgedBrie))]
[InlineData("AgedBrie", typeof(ItemKind.AgedBrie))]
[InlineData("Aged Cheddar", typeof(ItemKind.AgedCheddar))]
[InlineData("AgedCheddar", typeof(ItemKind.AgedCheddar))]
[InlineData("Backstage passes to a TAFKAL80ETC concert", typeof(ItemKind.Backstage))]
[InlineData("Backstage", typeof(ItemKind.Backstage))]
[InlineData("Conjured Mana Cake", typeof(ItemKind.Conjured))]
Expand All @@ -25,4 +27,4 @@ public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType

result.Should().BeOfType(expectedType);
}
}
}
18 changes: 17 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,22 @@ 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)]
public void Mature_WhenKindIsAgedCheddar_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.AgedCheddar(), 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 +105,4 @@ public void Mature_WhenKindIsSulfuras_PreservesProvidedState()

result.Should().Be(state);
}
}
}
6 changes: 5 additions & 1 deletion tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ 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 Cheddar", 10, 2, 11, 1)]
[InlineData("AgedCheddar", 10, 2, 11, 1)]
[InlineData("Aged Cheddar", 50, 2, 50, 1)]
[InlineData("Aged Cheddar", 10, 0, 12, -1)]
[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 +39,4 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit
result.Quality.Should().Be(expectedQuality);
result.SellIn.Should().Be(expectedSellIn);
}
}
}
Loading