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
29 changes: 29 additions & 0 deletions specs/conjured-items/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Implementation plan: Conjured items

## Technical context

The repository uses C# on .NET 8. The proposed implementation classifies item names with `ItemKind`, applies rules through `ItemMaturingPolicy`, and enforces quality bounds in the `Quality` value object. Tests use xUnit and FluentAssertions; CI runs `dotnet test`.

## Approach

Extend `ItemKind.FromName` to classify any name starting with `Conjured` as `ItemKind.Conjured`, preserving the existing policy that decreases quality by two before expiry and four after expiry. Keep quality clamping in `Quality`; verify it through maturation tests. Retain regression coverage for all non-Conjured item kinds and their existing rules.

## Files

- `src/Core/ProposedCode/Domain/ItemKind.cs` — recognize all names with the `Conjured` prefix.
- `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` — cover the named example and a different Conjured-prefixed name, plus a nonmatching name.
- `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` — verify normal and expired Conjured quality changes, nonnegative quality, and unchanged behavior across non-Conjured item kinds.

## Risks

Prefix matching intentionally classifies more names as Conjured than the current exact-name cases. Sell-by expiry follows the existing `SellIn` and maturation-policy semantics. No public interfaces or migrations need to change.

## Test plan

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

- **FR-001:** Service tests verify that “Conjured Mana Cake” and another Conjured-prefixed name lose two quality before expiry.
- **FR-002:** Service tests verify four quality lost for an expired Conjured item.
- **FR-003:** Service tests verify quality remains zero when the decrease would take it below zero.
- **FR-004:** Regression cases verify existing behavior for standard, Aged Brie, Backstage, and Sulfuras items.
- **FR-005:** The test suite includes cases for FR-001 through FR-004.
49 changes: 49 additions & 0 deletions specs/conjured-items/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Feature specification: Conjured items
UI work: no
conjured-items.md

## User scenarios

**Recognize Conjured items.** An inventory manager wants items whose names start with “Conjured” to lose quality faster, so their quality reflects their special status.

- **Given** an item whose name starts with “Conjured” and whose sell-by date has not passed, **when** the inventory is updated, **then** its quality decreases twice as fast as a normal item’s.

**Handle expired Conjured items.** An inventory manager wants Conjured items to lose quality faster after their sell-by date, so expired stock is reflected accurately.

- **Given** a Conjured item whose sell-by date has passed, **when** the inventory is updated, **then** its quality decreases four times as fast as a normal item’s.

**Keep quality nonnegative.** An inventory manager wants item quality to remain valid as it decreases.

- **Given** an item with quality that would fall below zero during an inventory update, **when** the inventory is updated, **then** its quality is zero, not negative.

**Preserve other item behavior.** An inventory manager wants existing inventory behavior to remain reliable while Conjured items are added.

- **Given** an item whose name does not start with “Conjured”, **when** the inventory is updated, **then** its behavior is unchanged.

## Requirements

- **FR-001:** The system shall decrease the quality of any item whose name starts with “Conjured” twice as fast as a normal item before its sell-by date.
- **FR-002:** The system shall decrease the quality of a Conjured item four times as fast as a normal item after its sell-by date.
- **FR-003:** The system shall never allow an item’s quality to fall below zero.
- **FR-004:** The system shall leave the existing behavior of every item whose name does not start with “Conjured” unchanged.
- **FR-005:** The project shall include tests for each requirement.

## Success criteria

- **SC-001:** An item named “Conjured Mana Cake” and another item with a different name starting with “Conjured” both lose quality twice as fast as a normal item before their sell-by dates.
- **SC-002:** An expired Conjured item loses quality four times as fast as a normal item.
- **SC-003:** Tests confirm that quality does not become negative.
- **SC-004:** Tests confirm that existing behavior for every non-Conjured item is unchanged.
- **SC-005:** Automated tests cover FR-001 through FR-004.

## Acceptance criteria

- **AC-001 (FR-001):** When an inventory update processes an item whose name starts with “Conjured” before its sell-by date, the system shall decrease its quality twice as fast as a normal item.
- **AC-002 (FR-002):** When an inventory update processes a Conjured item after its sell-by date, the system shall decrease its quality four times as fast as a normal item.
- **AC-003 (FR-003):** When an inventory update would reduce an item’s quality below zero, the system shall set its quality to zero.
- **AC-004 (FR-004):** When an inventory update processes an item whose name does not start with “Conjured”, the system shall preserve that item’s existing behavior.
- **AC-005 (FR-005):** When the project’s automated tests run, the system shall have tests that verify FR-001, FR-002, FR-003, and FR-004.

## Out of scope

- User interface changes.
4 changes: 4 additions & 0 deletions specs/conjured-items/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Tasks: Conjured items
- [ ] T001 [P] Add classification tests for multiple `Conjured`-prefixed names and a nonmatching name in `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` (FR-001, FR-004, AC-001, AC-004, AC-005)
- [ ] T002 [P] Add maturation tests for regular and expired Conjured items, nonnegative quality, and unchanged non-Conjured behavior in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-001, FR-002, FR-003, FR-004, FR-005, AC-001, AC-002, AC-003, AC-004, AC-005)
- [ ] T003 Update name classification to recognize any `Conjured` prefix in `src/Core/ProposedCode/Domain/ItemKind.cs` after T001 (FR-001, AC-001)
5 changes: 2 additions & 3 deletions src/Core/ProposedCode/Domain/ItemKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public static ItemKind FromName(string itemName)
"AgedBrie" => new AgedBrie(),
"Backstage passes to a TAFKAL80ETC concert" => new Backstage(),
"Backstage" => new Backstage(),
"Conjured Mana Cake" => new Conjured(),
"Conjured" => new Conjured(),
string name when name.StartsWith("Conjured", System.StringComparison.Ordinal) => new Conjured(),
"Sulfuras, Hand of Ragnaros" => new Sulfuras(),
_ => new Standard(),
};
}
}
}
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 @@ -17,6 +17,8 @@ public class ItemKindTests
[InlineData("Backstage", typeof(ItemKind.Backstage))]
[InlineData("Conjured Mana Cake", typeof(ItemKind.Conjured))]
[InlineData("Conjured", typeof(ItemKind.Conjured))]
[InlineData("Conjured Elixir of the Mongoose", typeof(ItemKind.Conjured))]
[InlineData("Conjured Something Else", typeof(ItemKind.Conjured))]
[InlineData("Sulfuras, Hand of Ragnaros", typeof(ItemKind.Sulfuras))]
[InlineData("Elixir of the Mongoose", typeof(ItemKind.Standard))]
public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType)
Expand All @@ -25,4 +27,4 @@ public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType

result.Should().BeOfType(expectedType);
}
}
}
6 changes: 5 additions & 1 deletion tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ public class ItemMaturationServiceTests
{
[Theory]
[InlineData("Elixir of the Mongoose", 10, 5, 9, 4)]
[InlineData("Elixir of the Mongoose", 10, 0, 8, -1)]
[InlineData("Aged Brie", 10, 2, 11, 1)]
[InlineData("AgedBrie", 10, 2, 11, 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)]
[InlineData("Conjured Mana Cake", 10, 0, 6, -1)]
[InlineData("Conjured", 10, 0, 6, -1)]
[InlineData("Conjured", 0, 0, 0, -1)]
[InlineData("Conjured", 3, 0, 0, -1)]
[InlineData("Sulfuras, Hand of Ragnaros", 80, 0, 80, 0)]
public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int quality, int sellIn, int expectedQuality, int expectedSellIn)
{
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