mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-05-13 13:27:58 +00:00
feat: add SulfurasStrategy
This commit is contained in:
parent
41c3a9d510
commit
253c445e31
@ -71,6 +71,18 @@ class BackstagePassStrategy:
|
|||||||
item.sell_in -= 1
|
item.sell_in -= 1
|
||||||
|
|
||||||
|
|
||||||
|
class SulfurasStrategy:
|
||||||
|
"""
|
||||||
|
No-op strategy for Sulfuras, Hand of Ragnaros.
|
||||||
|
|
||||||
|
Legendary items never degrade and never need to be sold.
|
||||||
|
Neither quality nor sell_in is ever mutated.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def update(self, item: "Item", days: int) -> None:
|
||||||
|
pass # legendary items are immutable; parameters required by Protocol
|
||||||
|
|
||||||
|
|
||||||
class GildedRose(object):
|
class GildedRose(object):
|
||||||
|
|
||||||
def __init__(self, items):
|
def __init__(self, items):
|
||||||
|
|||||||
@ -9,7 +9,7 @@ if str(_EXERCISE_ROOT) not in sys.path:
|
|||||||
|
|
||||||
from gilded_rose import (
|
from gilded_rose import (
|
||||||
Item, GildedRose, NormalStrategy, AgedBrieStrategy,
|
Item, GildedRose, NormalStrategy, AgedBrieStrategy,
|
||||||
BackstagePassStrategy,
|
BackstagePassStrategy, SulfurasStrategy,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -146,5 +146,28 @@ class TestBackstagePassStrategy(unittest.TestCase):
|
|||||||
self.assertEqual(8, item.sell_in)
|
self.assertEqual(8, item.sell_in)
|
||||||
|
|
||||||
|
|
||||||
|
class TestSulfurasStrategy(unittest.TestCase):
|
||||||
|
"""Tests for SulfurasStrategy — legendary item, never changes."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.strategy = SulfurasStrategy()
|
||||||
|
|
||||||
|
def test_quality_never_changes(self):
|
||||||
|
item = Item("Sulfuras, Hand of Ragnaros", sell_in=0, quality=80)
|
||||||
|
self.strategy.update(item, days=1)
|
||||||
|
self.assertEqual(80, item.quality)
|
||||||
|
|
||||||
|
def test_sell_in_never_changes(self):
|
||||||
|
item = Item("Sulfuras, Hand of Ragnaros", sell_in=0, quality=80)
|
||||||
|
self.strategy.update(item, days=1)
|
||||||
|
self.assertEqual(0, item.sell_in)
|
||||||
|
|
||||||
|
def test_unchanged_after_many_days(self):
|
||||||
|
item = Item("Sulfuras, Hand of Ragnaros", sell_in=0, quality=80)
|
||||||
|
self.strategy.update(item, days=100)
|
||||||
|
self.assertEqual(80, item.quality)
|
||||||
|
self.assertEqual(0, item.sell_in)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user