mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
refactoring python code
This commit is contained in:
parent
5a4e92199b
commit
8d30344e64
@ -1,4 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
SULFURAS = "Sulfuras, Hand of Ragnaros"
|
||||
BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert"
|
||||
AGED_BRIE = "Aged Brie"
|
||||
|
||||
|
||||
class GildedRose(object):
|
||||
|
||||
@ -7,33 +11,30 @@ class GildedRose(object):
|
||||
|
||||
def update_quality(self):
|
||||
for item in self.items:
|
||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert":
|
||||
if item.quality > 0:
|
||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
||||
item.quality = item.quality - 1
|
||||
increment = 1
|
||||
if item.name != AGED_BRIE and item.name != BACKSTAGE_PASSES and item.name != SULFURAS:
|
||||
self.regulateQuality(-increment, item)
|
||||
else:
|
||||
if item.quality < 50:
|
||||
item.quality = item.quality + 1
|
||||
if item.name == "Backstage passes to a TAFKAL80ETC concert":
|
||||
if item.sell_in < 11:
|
||||
if item.quality < 50:
|
||||
item.quality = item.quality + 1
|
||||
if item.sell_in < 6:
|
||||
if item.quality < 50:
|
||||
item.quality = item.quality + 1
|
||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
||||
item.sell_in = item.sell_in - 1
|
||||
self.regulateQuality(increment, item)
|
||||
if item.name == BACKSTAGE_PASSES:
|
||||
if item.sell_in < 11 or item.sell_in < 6:
|
||||
self.regulateQuality(increment, item)
|
||||
|
||||
if item.name != SULFURAS:
|
||||
item.sell_in = item.sell_in - increment
|
||||
if item.sell_in < 0:
|
||||
if item.name != "Aged Brie":
|
||||
if item.name != "Backstage passes to a TAFKAL80ETC concert":
|
||||
if item.quality > 0:
|
||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
||||
item.quality = item.quality - 1
|
||||
else:
|
||||
item.quality = item.quality - item.quality
|
||||
if item.name != AGED_BRIE and item.name != BACKSTAGE_PASSES and item.name != SULFURAS:
|
||||
self.regulateQuality(-increment, item)
|
||||
else:
|
||||
if item.quality < 50:
|
||||
item.quality = item.quality + 1
|
||||
if item.name == BACKSTAGE_PASSES:
|
||||
item.quality = item.quality - item.quality
|
||||
elif item.name == AGED_BRIE:
|
||||
self.regulateQuality(increment, item)
|
||||
|
||||
def regulateQuality(self, increment, item):
|
||||
newQuality = item.quality + increment
|
||||
if 0 <= newQuality <= 50:
|
||||
item.quality = newQuality
|
||||
|
||||
|
||||
class Item:
|
||||
|
||||
@ -9,8 +9,8 @@ class GildedRoseTest(unittest.TestCase):
|
||||
items = [Item("foo", 0, 0)]
|
||||
gilded_rose = GildedRose(items)
|
||||
gilded_rose.update_quality()
|
||||
self.assertEquals("fixme", items[0].name)
|
||||
self.assertEquals("foo", items[0].name)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@ -4,7 +4,7 @@ from __future__ import print_function
|
||||
from gilded_rose import *
|
||||
|
||||
if __name__ == "__main__":
|
||||
print ("OMGHAI!")
|
||||
print("OMGHAI!")
|
||||
items = [
|
||||
Item(name="+5 Dexterity Vest", sell_in=10, quality=20),
|
||||
Item(name="Aged Brie", sell_in=2, quality=0),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user