mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 23:41:27 +00:00
Refactored code in Python
This commit is contained in:
parent
5a4e92199b
commit
165746e465
@ -1,4 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
SULFURAS = "Sulfuras, Hand of Ragnaros"
|
||||||
|
BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
BRIE = "Aged Brie"
|
||||||
|
|
||||||
|
|
||||||
class GildedRose(object):
|
class GildedRose(object):
|
||||||
|
|
||||||
@ -7,33 +11,31 @@ class GildedRose(object):
|
|||||||
|
|
||||||
def update_quality(self):
|
def update_quality(self):
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert":
|
self.update_item_quality(item)
|
||||||
if item.quality > 0:
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
def update_item_quality(self, item):
|
||||||
item.quality = item.quality - 1
|
condition = item.name != BRIE and item.name != BACKSTAGE and item.name != SULFURAS
|
||||||
else:
|
if condition:
|
||||||
if item.quality < 50:
|
self.adjust_quality(-1, item)
|
||||||
item.quality = item.quality + 1
|
else:
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert":
|
self.adjust_quality(1, item)
|
||||||
if item.sell_in < 11:
|
if item.name == BACKSTAGE:
|
||||||
if item.quality < 50:
|
if item.sell_in < 11 or item.sell_in < 6:
|
||||||
item.quality = item.quality + 1
|
self.adjust_quality(1, item)
|
||||||
if item.sell_in < 6:
|
if item.name != SULFURAS:
|
||||||
if item.quality < 50:
|
item.sell_in = item.sell_in - 1
|
||||||
item.quality = item.quality + 1
|
if item.sell_in < 0:
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
if condition:
|
||||||
item.sell_in = item.sell_in - 1
|
self.adjust_quality(-1, item)
|
||||||
if item.sell_in < 0:
|
if item.name == BRIE:
|
||||||
if item.name != "Aged Brie":
|
self.adjust_quality(1, item)
|
||||||
if item.name != "Backstage passes to a TAFKAL80ETC concert":
|
elif item.name == BACKSTAGE:
|
||||||
if item.quality > 0:
|
item.quality = item.quality - item.quality
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
|
||||||
item.quality = item.quality - 1
|
def adjust_quality(self, adjustment, item):
|
||||||
else:
|
new_quality = item.quality + adjustment
|
||||||
item.quality = item.quality - item.quality
|
if 50 >= new_quality >= 0:
|
||||||
else:
|
item.quality = new_quality
|
||||||
if item.quality < 50:
|
|
||||||
item.quality = item.quality + 1
|
|
||||||
|
|
||||||
|
|
||||||
class Item:
|
class Item:
|
||||||
|
|||||||
@ -9,8 +9,8 @@ class GildedRoseTest(unittest.TestCase):
|
|||||||
items = [Item("foo", 0, 0)]
|
items = [Item("foo", 0, 0)]
|
||||||
gilded_rose = GildedRose(items)
|
gilded_rose = GildedRose(items)
|
||||||
gilded_rose.update_quality()
|
gilded_rose.update_quality()
|
||||||
self.assertEquals("fixme", items[0].name)
|
self.assertEquals("foo", items[0].name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user