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
8 changes: 7 additions & 1 deletion src/Core/ProposedCode/Domain/ItemKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public sealed record Conjured : ItemKind;

public sealed record Sulfuras : ItemKind;

public sealed record DragonEgg : ItemKind;

public sealed record MoonlitElixir : ItemKind;

public static ItemKind FromName(string itemName)
{
return itemName switch
Expand All @@ -29,7 +33,9 @@ public static ItemKind FromName(string itemName)
"Conjured Mana Cake" => new Conjured(),
"Conjured" => new Conjured(),
"Sulfuras, Hand of Ragnaros" => new Sulfuras(),
"Dragon Egg" => new DragonEgg(),
"Moonlit Elixir" => new MoonlitElixir(),
_ => new Standard(),
};
}
}
}
28 changes: 27 additions & 1 deletion src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public ItemState Mature(ItemKind kind, ItemState state)
ItemKind.Backstage => this.MatureBackstage(state),
ItemKind.Conjured => this.MatureConjured(state),
ItemKind.Sulfuras => state,
ItemKind.DragonEgg => this.MatureDragonEgg(state),
ItemKind.MoonlitElixir => this.MatureMoonlitElixir(state),
_ => this.MatureStandard(state),
};
}
Expand Down Expand Up @@ -77,4 +79,28 @@ private ItemState MatureConjured(ItemState state)

return new(newQuality, newSellIn);
}
}

private ItemState MatureDragonEgg(ItemState state)
{
var newSellIn = state.SellIn.NextDay();
var newQuality = state.SellIn switch
{
_ when state.SellIn.Value <= 0 => state.Quality.Reset(),
_ when state.SellIn.IsBelow(6) => state.Quality.Increase(3),
_ when state.SellIn.IsBelow(11) => state.Quality.Increase(2),
_ => state.Quality.Increase(),
};

return new(newQuality, newSellIn);
}

private ItemState MatureMoonlitElixir(ItemState state)
{
var decreaseAmount = state.SellIn.Value > 0 ? 1 : 2;
var newQuality = state.SellIn.Value > 0 && state.SellIn.Value % 14 == 0
? state.Quality.Increase(2)
: state.Quality.Decrease(decreaseAmount);

return new(newQuality, state.SellIn.NextDay());
}
}
43 changes: 42 additions & 1 deletion tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,45 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit
result.Quality.Should().Be(expectedQuality);
result.SellIn.Should().Be(expectedSellIn);
}
}

[Theory]
[InlineData(40, 12, 41, 11)]
[InlineData(40, 10, 42, 9)]
[InlineData(49, 5, 50, 4)]
[InlineData(40, 0, 0, -1)]
[InlineData(1, -1, 0, -2)]
public void F001_DragonEggMaturesThroughGrowthHatchingAndDecayStages(int quality, int sellIn, int expectedQuality, int expectedSellIn)
{
ItemKind.FromName("Dragon Egg").Should().NotBeOfType<ItemKind.Standard>();

var result = new ItemMaturationService().Mature(new Item
{
Name = "Dragon Egg",
Quality = quality,
SellIn = sellIn,
});

result.Quality.Should().Be(expectedQuality);
result.SellIn.Should().Be(expectedSellIn);
}

[Theory]
[InlineData(48, 14, 50, 13)]
[InlineData(10, 13, 9, 12)]
[InlineData(3, 0, 1, -1)]
[InlineData(1, -1, 0, -2)]
public void F002_MoonlitElixirFollowsLunarAndSpoilageCycles(int quality, int sellIn, int expectedQuality, int expectedSellIn)
{
ItemKind.FromName("Moonlit Elixir").Should().NotBeOfType<ItemKind.Standard>();

var result = new ItemMaturationService().Mature(new Item
{
Name = "Moonlit Elixir",
Quality = quality,
SellIn = sellIn,
});

result.Quality.Should().Be(expectedQuality);
result.SellIn.Should().Be(expectedSellIn);
}
}
Loading