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
36 changes: 36 additions & 0 deletions specs/add-a-new-product-to-gilded-rose/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Implementation plan: Add Mature Cheese

## Technical context

The proposed implementation uses C# on .NET 8. Product classification and maturation rules live in `src/Core/ProposedCode`; immutable `ItemKind`, `Quality`, `SellIn`, and `ItemState` types encapsulate the domain behavior. Tests use xUnit and FluentAssertions. CI restores, builds, and tests the solution with the .NET CLI.

## Approach

Treat the specification’s examples as confirming the proposed defaults: match the exact name `Mature Cheese`, increase quality by 1 when the starting `sellIn` is positive and by 2 otherwise, cap quality at 50, and add no other age-based behavior. Reuse `Quality`’s existing 0–50 normalization, which also handles out-of-range legacy quality when the item state is created.

Add a dedicated `ItemKind.MatureCheese`, map only the exact product name to it, and handle it explicitly in `ItemMaturingPolicy`. Base the quality increase on the state’s starting `SellIn`, then decrement `SellIn` once. Leave the existing product cases and original update service unchanged. Add focused classification and policy tests, and service tests for matching, bounds, and preservation of the input item.

## Files

- `src/Core/ProposedCode/Domain/ItemKind.cs` — add the Mature Cheese product kind and exact-name mapping.
- `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` — implement its increase, cap via `Quality`, and daily sell-by decrement.
- `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` — verify exact-name classification and similar names remain standard.
- `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` — cover sell-by boundaries, repeated updates, quality bounds, and existing product regressions.
- `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` — verify end-to-end name handling, independent items, and that maturation does not mutate the input item.

## Risks

`ItemKind` is a public domain type, so adding a case requires updating the policy’s dispatch. `Quality` clamps out-of-range input when creating an `ItemState`; tests should verify that this existing policy keeps Mature Cheese within bounds. The legacy `UpdateQualityService` has separate rules; changing it would risk altering established behavior, so the feature should remain in the proposed maturation path. No migration or UI changes are needed.

## Test plan

Run `dotnet test tests/Core.Tests/GildedRoseKata.Core.Tests.csproj`.

- **FR-001, FR-007:** classification tests verify exact `Mature Cheese` matching and that similar names remain standard.
- **FR-002–FR-004:** policy tests verify +1 for positive starting `sellIn`, +2 for zero or negative starting `sellIn`, and a one-day decrement on each update.
- **FR-005–FR-006:** policy and quality-boundary tests verify quality remains within 0–50, including out-of-range starting values.
- **FR-008:** existing product policy and service regression tests verify other product behavior is unchanged.
- **FR-009:** service tests verify the input item remains unchanged; no creation, display, or search behavior is added.
- **FR-010–FR-011:** tests cover multiple independent Mature Cheese items, mixed product kinds, and deterministic results.
- **FR-012:** the targeted automated suite covers the new rules and existing product regressions.
- **FR-013:** tests verify only the specified quality and sell-by behavior is applied.
115 changes: 115 additions & 0 deletions specs/add-a-new-product-to-gilded-rose/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Feature specification: Add Mature Cheese to Gilded Rose
gilded_rose_new_product_business_rules.md
UI work: no

## User scenarios

**Daily inventory update:** As an inventory manager, I want Mature Cheese quality and sell-by values updated each day so that inventory reflects its aging.

- Given Mature Cheese with `sellIn = 5` and `quality = 10`, when the inventory is updated, then it has `sellIn = 4` and `quality = 11`.
- Given Mature Cheese with `sellIn = 1` and `quality = 10`, when the inventory is updated, then it has `sellIn = 0` and `quality = 11`.
- Given Mature Cheese with `sellIn = 0` and `quality = 10`, when the inventory is updated, then it has `sellIn = -1` and `quality = 12`.
- Given Mature Cheese with `sellIn = -1` and `quality = 10`, when the inventory is updated, then it has `sellIn = -2` and `quality = 12`.

**Quality validation:** As an inventory manager, I want Mature Cheese quality kept within valid bounds so that invalid values are not produced.

- Given Mature Cheese at or near the quality limits, when the inventory is updated, then its quality remains between 0 and 50 inclusive.

**Mixed inventory:** As an inventory manager, I want Mature Cheese rules applied only to the matching product so that other inventory items retain their behavior.

- Given multiple Mature Cheese items and other products in one inventory, when the inventory is updated, then each Mature Cheese follows its rules and other products retain their existing rules.

**Read-only access:** As a user viewing or searching inventory, I want Mature Cheese values to remain unchanged until the daily update so that access does not alter inventory.

- Given a Mature Cheese item, when it is created, read, displayed, or searched, then its `quality` and `sellIn` remain unchanged.

## Requirements

FR-001. The system shall recognize `Mature Cheese` as an aging food product and apply its new behavior only to the exact product name. [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?]

FR-002. When `sellIn` is greater than 0 before an update, the system shall increase Mature Cheese quality by 1. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?]

FR-003. When `sellIn` is 0 or less before an update, the system shall increase Mature Cheese quality by 2. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?]

FR-004. The system shall decrease Mature Cheese `sellIn` by 1 for each daily inventory update and update the item with the resulting values.

FR-005. The system shall cap Mature Cheese quality at 50 after an increase. [NEEDS CLARIFICATION: Is 50 the correct maximum quality?]

FR-006. The system shall keep Mature Cheese quality between 0 and 50 inclusive, including when input data has out-of-range quality; invalid imported values shall follow the existing quality-normalization policy.

FR-007. The system shall leave products whose names are similar but not an exact match to `Mature Cheese` under their existing rules.

FR-008. The system shall leave existing product behavior unchanged, including Aged Brie, Backstage passes, Sulfuras, and Conjured items.

FR-009. The system shall not change Mature Cheese `quality` or `sellIn` during creation, reading, displaying, or searching; values change only during the daily inventory update.

FR-010. The system shall apply the Mature Cheese rules independently to each matching item in inventories containing multiple Mature Cheese items or mixed product types.

FR-011. The system shall produce the same result for the same starting item and daily update operation.

FR-012. The system shall have automated unit-test coverage for the Mature Cheese business rules and regression coverage for existing product behavior.

FR-013. The system shall apply no additional Mature Cheese behavior, such as becoming unsafe or losing value after a maximum age, beyond the rules specified here. [NEEDS CLARIFICATION: Should Mature Cheese have any special behavior such as becoming unsafe or losing value after a maximum age?]

FR-014. The system shall confine implementation changes for this feature to proposed code and leave original code unchanged.

## Success criteria

SC-001. A daily update produces the specified results for starting `sellIn` values above zero, equal to zero, and below zero.

SC-002. Quality values of 0, 1, 49, and 50, including out-of-range imported values, result in Mature Cheese quality between 0 and 50 inclusive after an update.

SC-003. Multiple consecutive updates, multiple Mature Cheese items, mixed inventories, and similar-but-not-exact product names produce the specified behavior.

SC-004. Regression checks confirm that existing products retain their previous behavior and outputs.

SC-005. Automated tests cover the proposed cases, including `increases_quality_by_one_before_sell_by`, `increases_quality_by_two_on_sell_by_date`, `increases_quality_by_two_after_sell_by`, `does_not_increase_quality_above_fifty`, `keeps_quality_at_fifty`, `decreases_sell_in_by_one_each_day`, and `does_not_change_existing_product_behaviour`.

SC-006. Business rules are confirmed before implementation, and acceptance criteria pass as automated tests.

SC-007. Changes for this feature are confined to proposed code, and original code remains unchanged.

## Acceptance criteria

AC-001 (FR-001): When an item named exactly `Mature Cheese` is processed, the system shall apply the Mature Cheese aging-product rules. [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?]

AC-002 (FR-002): When Mature Cheese has `sellIn = 5` or `sellIn = 1` and `quality = 10` at the start of an update, the system shall increase quality to 11. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?]

AC-003 (FR-003): When Mature Cheese has `sellIn = 0` or `sellIn = -1` and `quality = 10` at the start of an update, the system shall increase quality to 12. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?]

AC-004 (FR-004): When a daily update is performed on Mature Cheese, the system shall decrease its `sellIn` by 1 and return or store the updated values.

AC-005 (FR-005): When Mature Cheese with `sellIn = 5` and `quality = 49`, `sellIn = 0` and `quality = 49`, or quality 50 is updated, the system shall produce quality 50 in each case. [NEEDS CLARIFICATION: Is 50 the correct maximum quality?]

AC-006 (FR-006): When Mature Cheese with quality below 0 or above 50 is updated, the system shall apply the existing quality-normalization policy and produce a quality between 0 and 50 inclusive.

AC-007 (FR-007): When an item with a name similar to but not exactly `Mature Cheese` is updated, the system shall apply that item’s existing product rules.

AC-008 (FR-008): When Aged Brie, Backstage passes, Sulfuras, or Conjured items are updated, the system shall produce the same behavior and outputs as before this change.

AC-009 (FR-009): When Mature Cheese is created, read, displayed, or searched without a daily inventory update, the system shall leave its `quality` and `sellIn` unchanged.

AC-010 (FR-010): When an inventory containing multiple Mature Cheese items and other products is updated, the system shall apply the Mature Cheese rules to each matching item and existing rules to the other products.

AC-011 (FR-011): When the same starting item is subjected to the same daily update operation, the system shall produce the same result.

AC-012 (FR-012): When the Mature Cheese business rules or existing product behavior are changed, the system shall have automated unit and regression tests that verify the applicable outcomes.

AC-013 (FR-013): When Mature Cheese ages under the specified rules, the system shall not introduce additional age-based safety or value behavior. [NEEDS CLARIFICATION: Should Mature Cheese have any special behavior such as becoming unsafe or losing value after a maximum age?]

AC-014 (FR-014): When Mature Cheese support is added, the system shall confine implementation changes to proposed code and leave original code unchanged.

## Out of scope

- User-interface work.
- Changes to existing product behavior.
- Refactoring unrelated product behavior.
- Modifications to original code.
- Mature Cheese rules beyond the specified quality and sell-by behavior, pending clarification of any additional maximum-age behavior.

## Open questions

- [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?]
- [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?]
- [NEEDS CLARIFICATION: Is 50 the correct maximum quality?]
- [NEEDS CLARIFICATION: Should Mature Cheese have any special behavior such as becoming unsafe or losing value after a maximum age?]
5 changes: 5 additions & 0 deletions specs/add-a-new-product-to-gilded-rose/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- [ ] T001 [P] Add exact-name and similar-name classification tests in `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` (FR-001, FR-007, FR-012; AC-001, AC-007, AC-012)
- [ ] T002 [P] Add Mature Cheese policy tests for sell-by boundaries, repeated updates, quality bounds, legacy values, and unchanged existing product behavior in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-002, FR-003, FR-004, FR-005, FR-006, FR-008, FR-011, FR-012, FR-013; AC-002, AC-003, AC-004, AC-005, AC-006, AC-008, AC-011, AC-012, AC-013)
- [ ] T003 [P] Add service tests for end-to-end name handling, multiple independent items, deterministic results, and input preservation in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-009, FR-010, FR-011, FR-012; AC-009, AC-010, AC-011, AC-012)
- [ ] T004 [P] Add the Mature Cheese kind and exact-name mapping after T001 in `src/Core/ProposedCode/Domain/ItemKind.cs` (FR-001, FR-007, FR-014; AC-001, AC-007, AC-014)
- [ ] T005 Implement Mature Cheese quality increases and daily sell-by decrement after T002 and T004 in `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` (FR-002, FR-003, FR-004, FR-005, FR-006, FR-008, FR-011, FR-013, FR-014; AC-002, AC-003, AC-004, AC-005, AC-006, AC-008, AC-011, AC-013, AC-014)
5 changes: 4 additions & 1 deletion src/Core/ProposedCode/Domain/ItemKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public sealed record Conjured : ItemKind;

public sealed record Sulfuras : ItemKind;

public sealed record MatureCheese : ItemKind;

public static ItemKind FromName(string itemName)
{
return itemName switch
Expand All @@ -29,7 +31,8 @@ public static ItemKind FromName(string itemName)
"Conjured Mana Cake" => new Conjured(),
"Conjured" => new Conjured(),
"Sulfuras, Hand of Ragnaros" => new Sulfuras(),
"Mature Cheese" => new MatureCheese(),
_ => new Standard(),
};
}
}
}
12 changes: 11 additions & 1 deletion src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public ItemState Mature(ItemKind kind, ItemState state)
ItemKind.Backstage => this.MatureBackstage(state),
ItemKind.Conjured => this.MatureConjured(state),
ItemKind.Sulfuras => state,
ItemKind.MatureCheese => this.MatureCheese(state),
_ => this.MatureStandard(state),
};
}
Expand Down Expand Up @@ -77,4 +78,13 @@ private ItemState MatureConjured(ItemState state)

return new(newQuality, newSellIn);
}
}

private ItemState MatureCheese(ItemState state)
{
var qualityIncrease = state.SellIn.Value > 0 ? 1 : 2;
var newQuality = state.Quality.Increase(qualityIncrease);
var newSellIn = state.SellIn.NextDay();

return new(newQuality, newSellIn);
}
}
6 changes: 5 additions & 1 deletion tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public class ItemKindTests
[InlineData("Conjured Mana Cake", typeof(ItemKind.Conjured))]
[InlineData("Conjured", typeof(ItemKind.Conjured))]
[InlineData("Sulfuras, Hand of Ragnaros", typeof(ItemKind.Sulfuras))]
[InlineData("Mature Cheese", typeof(ItemKind.MatureCheese))]
[InlineData("Elixir of the Mongoose", typeof(ItemKind.Standard))]
[InlineData("mature cheese", typeof(ItemKind.Standard))]
[InlineData("Mature Cheese ", typeof(ItemKind.Standard))]
[InlineData("Mature Cheeses", typeof(ItemKind.Standard))]
public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType)
{
var result = ItemKind.FromName(itemName);

result.Should().BeOfType(expectedType);
}
}
}
64 changes: 63 additions & 1 deletion tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,68 @@
result.SellIn.Value.Should().Be(expectedSellIn);
}

[Theory]
[InlineData(10, 5, 11, 4)]
[InlineData(10, 1, 11, 0)]
[InlineData(10, 0, 12, -1)]
[InlineData(10, -1, 12, -2)]
public void Mature_WhenKindIsMatureCheese_UsesPreDecrementSellIn(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.MatureCheese(), state);

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

[Theory]
[InlineData(49, 5, 50)]
[InlineData(49, 0, 50)]
[InlineData(50, 5, 50)]
[InlineData(50, 0, 50)]
[InlineData(0, 5, 1)]
[InlineData(1, 0, 3)]
public void Mature_WhenKindIsMatureCheese_ClampsQualityToZeroThroughFifty(int quality, int sellIn, int expectedQuality)
{
var state = new ItemState(new Quality(quality), new SellIn(sellIn));

var result = this.policy.Mature(new ItemKind.MatureCheese(), state);

result.Quality.Value.Should().Be(expectedQuality);
result.Quality.Value.Should().BeInRange(Quality.Minimum, Quality.Maximum);
}

[Theory]
[InlineData(-5, 5, 1)]
[InlineData(55, 5, 50)]
public void Mature_WhenKindIsMatureCheese_HandlesOutOfRangeLegacyQuality(int quality, int sellIn, int expectedQuality)

Check failure on line 118 in tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs

View workflow job for this annotation

GitHub Actions / build / build

Update this method so that its implementation is not identical to 'Mature_WhenKindIsMatureCheese_ClampsQualityToZeroThroughFifty'.

Check failure on line 118 in tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs

View workflow job for this annotation

GitHub Actions / build / build

Update this method so that its implementation is not identical to 'Mature_WhenKindIsMatureCheese_ClampsQualityToZeroThroughFifty'.
{
var state = new ItemState(new Quality(quality), new SellIn(sellIn));

var result = this.policy.Mature(new ItemKind.MatureCheese(), state);

result.Quality.Value.Should().Be(expectedQuality);
result.Quality.Value.Should().BeInRange(Quality.Minimum, Quality.Maximum);
}

[Fact]
public void Mature_WhenKindIsMatureCheese_UpdatesQualityAndSellInAcrossRepeatedDays()
{
var state = ItemState.Create(new ItemKind.MatureCheese(), 48, 1);

var firstDay = this.policy.Mature(new ItemKind.MatureCheese(), state);
var secondDay = this.policy.Mature(new ItemKind.MatureCheese(), firstDay);
var thirdDay = this.policy.Mature(new ItemKind.MatureCheese(), secondDay);

firstDay.Quality.Value.Should().Be(49);
firstDay.SellIn.Value.Should().Be(0);
secondDay.Quality.Value.Should().Be(50);
secondDay.SellIn.Value.Should().Be(-1);
thirdDay.Quality.Value.Should().Be(50);
thirdDay.SellIn.Value.Should().Be(-2);
}

[Fact]
public void Mature_WhenKindIsSulfuras_PreservesProvidedState()
{
Expand All @@ -89,4 +151,4 @@

result.Should().Be(state);
}
}
}
Loading
Loading