Skip to content

Commit 49316b5

Browse files
committed
feat: add ennobling conjured items
1 parent be4a26b commit 49316b5

3 files changed

Lines changed: 48 additions & 17 deletions

File tree

src/gilded_rose/inn.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ class Item: # pylint: disable=too-few-public-methods
1919
@property
2020
def _ennobling(self):
2121
"""Returns whether the item ennobles over time."""
22-
return self.name == AGED_BRIE
22+
return self.name.endswith(AGED_BRIE)
2323

2424
@property
2525
def _legendary(self):
2626
"""Returns whether the item is legendary or not."""
27-
return self.name == SULFURAS
27+
return self.name.endswith(SULFURAS)
28+
29+
@property
30+
def _backstage_passes(self):
31+
"""Returns whether the item is a backstage pass or not."""
32+
return self.name.endswith(BACKSTAGE_PASSES)
2833

2934
@property
3035
def _conjured(self):
3136
"""Returns whether the item is a conjured item or not."""
3237
return self.name.startswith(CONJURED_PREFIX)
3338

34-
@property
35-
def _backstage_passes(self):
36-
"""Returns whether the item is a backstage pass or not."""
37-
return self.name == BACKSTAGE_PASSES
38-
3939
def compute_after_a_day(self) -> "Item":
4040
"""Compute the state of the item after a day."""
4141
quality_variation = 1 if self.sell_in > 0 else 2
@@ -45,7 +45,7 @@ def compute_after_a_day(self) -> "Item":
4545
sell_in = self.sell_in - 1
4646

4747
if self._ennobling:
48-
quality = min(50, self.quality + quality_variation)
48+
quality = min(50, self.quality + quality_variation * quality_multiplier)
4949

5050
if self._legendary:
5151
quality = 80

tests/builder.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dataclasses import dataclass
44
from typing import Self
55

6-
from gilded_rose.inn import AGED_BRIE, BACKSTAGE_PASSES, SULFURAS, Item
6+
from gilded_rose.inn import AGED_BRIE, BACKSTAGE_PASSES, CONJURED_PREFIX, SULFURAS, Item
77

88

99
@dataclass
@@ -15,22 +15,29 @@ class ItemBuilder:
1515
_is_backstage_passes: bool = False
1616
_sell_in_date: int = 4
1717
_quality: int = 5
18+
_conjured: bool = False
1819

1920
def _name(self) -> str:
2021
"""Compute the item's name depending on its characteristics."""
22+
prefix = CONJURED_PREFIX if self._conjured else ""
2123
if self._ennobles:
22-
return AGED_BRIE
24+
return prefix + AGED_BRIE
2325
if self._is_legendary:
24-
return SULFURAS
26+
return prefix + SULFURAS
2527
if self._is_backstage_passes:
26-
return BACKSTAGE_PASSES
27-
return "foo"
28+
return prefix + BACKSTAGE_PASSES
29+
return prefix + "foo"
2830

2931
def with_quality(self, quality: int) -> Self:
3032
"""Add a specific quality to the item to build."""
3133
self._quality = quality
3234
return self
3335

36+
def conjured(self) -> Self:
37+
"""Mark the item to build as a conjured item."""
38+
self._conjured = True
39+
return self
40+
3441
def expired(self) -> Self:
3542
"""Mark the item as expired."""
3643
self._sell_in_date = 0

tests/test_inn.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from gilded_rose.inn import GildedRose, Item
44
from tests.builder import an_item
55

6-
AGED_BRIE = "Aged Brie"
7-
86

97
def test_quality_degrades_over_time():
108
"""Test that the quality of an item decreases over time."""
@@ -60,7 +58,7 @@ def test_quality_cannot_get_negative():
6058
def test_aged_brie_ennobles_quality_over_time():
6159
"""Test that the quality of Aged Brie increases over time."""
6260
# Arrange
63-
items = [Item(AGED_BRIE, sell_in=10, quality=20)]
61+
items = [an_item().ennobling().sell_in(10).with_quality(20).build()]
6462
gilded_rose = GildedRose(items)
6563

6664
# Act
@@ -178,11 +176,37 @@ def test_conjured_items_degrade_twice_as_fast():
178176
def test_conjured_items_degrade_4_times_as_fast_after_sell_in_date_is_passed():
179177
"""Test that the quality of conjured items degrades four times as fast after the sell-in date."""
180178
# Arrange
181-
items = [Item("Conjured Mana Cake", sell_in=0, quality=6)]
179+
items = [an_item().conjured().expired().with_quality(6).build()]
182180
gilded_rose = GildedRose(items)
183181

184182
# Act
185183
gilded_rose.update_quality()
186184

187185
# Assert
188186
assert gilded_rose.items[0].quality == 2
187+
188+
189+
def test_conjured_ennobling_items_ennobles_twice_as_fast():
190+
"""Test that conjured ennobling items increase quality twice as fast."""
191+
# Arrange
192+
items = [an_item().conjured().ennobling().sell_in(10).with_quality(20).build()]
193+
gilded_rose = GildedRose(items)
194+
195+
# Act
196+
gilded_rose.update_quality()
197+
198+
# Assert
199+
assert gilded_rose.items[0].quality == 22
200+
201+
202+
def test_conjured_ennobling_items_ennobles_four_times_as_fast_after_sell_in_date_is_passed():
203+
"""Test that conjured ennobling items increase quality four times as fast after the sell-in date."""
204+
# Arrange
205+
items = [an_item().conjured().ennobling().expired().with_quality(20).build()]
206+
gilded_rose = GildedRose(items)
207+
208+
# Act
209+
gilded_rose.update_quality()
210+
211+
# Assert
212+
assert gilded_rose.items[0].quality == 24

0 commit comments

Comments
 (0)