mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
resolve kata
This commit is contained in:
parent
74291a62a6
commit
c1f9242acf
@ -1,46 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
class GildedRose(object):
|
||||
|
||||
def __init__(self, items):
|
||||
self.items = items
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
else:
|
||||
if item.quality < 50:
|
||||
item.quality = item.quality + 1
|
||||
|
||||
|
||||
class Item:
|
||||
def __init__(self, name, sell_in, quality):
|
||||
self.name = name
|
||||
self.sell_in = sell_in
|
||||
self.quality = quality
|
||||
|
||||
def __repr__(self):
|
||||
return "%s, %s, %s" % (self.name, self.sell_in, self.quality)
|
||||
item.evaluate()
|
||||
|
||||
67
python/item.py
Normal file
67
python/item.py
Normal file
@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class Item:
|
||||
def __init__(self, name, sell_in, quality):
|
||||
self.name = name
|
||||
self.sell_in = sell_in
|
||||
self.quality = quality
|
||||
|
||||
def __repr__(self):
|
||||
return "%s, %s, %s" % (self.name, self.sell_in, self.quality)
|
||||
|
||||
@abstractmethod
|
||||
def evaluate(self):
|
||||
pass
|
||||
|
||||
def increment(self):
|
||||
self.quality += 1
|
||||
|
||||
def decrement(self):
|
||||
self.quality -= 1
|
||||
|
||||
def sold(self):
|
||||
self.sell_in -= 1
|
||||
|
||||
|
||||
class AgedBrie(Item):
|
||||
def evaluate(self):
|
||||
if self.quality < 50:
|
||||
self.increment()
|
||||
self.sold()
|
||||
if self.sell_in < 0 and self.quality < 50:
|
||||
self.increment()
|
||||
|
||||
|
||||
class Backstage(Item):
|
||||
def evaluate(self):
|
||||
if self.quality < 50:
|
||||
self.increment()
|
||||
if self.sell_in < 11:
|
||||
if self.quality < 50:
|
||||
self.increment()
|
||||
if self.sell_in < 6:
|
||||
if self.quality < 50:
|
||||
self.increment()
|
||||
self.sold()
|
||||
if self.sell_in < 0 and self.quality < 50:
|
||||
self.increment()
|
||||
|
||||
|
||||
class Sulfuras(Item):
|
||||
def evaluate(self):
|
||||
if self.quality < 50:
|
||||
self.increment()
|
||||
if self.sell_in < 0 and self.quality < 50:
|
||||
self.increment()
|
||||
|
||||
|
||||
class General(Item):
|
||||
def evaluate(self):
|
||||
if self.quality > 0:
|
||||
self.decrement()
|
||||
self.sold()
|
||||
if self.sell_in < 0:
|
||||
if self.quality > 0:
|
||||
self.decrement()
|
||||
@ -1,15 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest
|
||||
|
||||
from gilded_rose import Item, GildedRose
|
||||
from gilded_rose import *
|
||||
from item import *
|
||||
|
||||
|
||||
class GildedRoseTest(unittest.TestCase):
|
||||
def test_foo(self):
|
||||
items = [Item("foo", 0, 0)]
|
||||
items = [General("foo", 0, 0)]
|
||||
gilded_rose = GildedRose(items)
|
||||
gilded_rose.update_quality()
|
||||
self.assertEquals("fixme", items[0].name)
|
||||
self.assertEqual("foo", items[0].name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -2,19 +2,20 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from gilded_rose import *
|
||||
from item import *
|
||||
|
||||
if __name__ == "__main__":
|
||||
print ("OMGHAI!")
|
||||
items = [
|
||||
Item(name="+5 Dexterity Vest", sell_in=10, quality=20),
|
||||
Item(name="Aged Brie", sell_in=2, quality=0),
|
||||
Item(name="Elixir of the Mongoose", sell_in=5, quality=7),
|
||||
Item(name="Sulfuras, Hand of Ragnaros", sell_in=0, quality=80),
|
||||
Item(name="Sulfuras, Hand of Ragnaros", sell_in=-1, quality=80),
|
||||
Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20),
|
||||
Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=10, quality=49),
|
||||
Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=5, quality=49),
|
||||
Item(name="Conjured Mana Cake", sell_in=3, quality=6), # <-- :O
|
||||
General(name="+5 Dexterity Vest", sell_in=10, quality=20),
|
||||
AgedBrie(name="Aged Brie", sell_in=2, quality=0),
|
||||
General(name="Elixir of the Mongoose", sell_in=5, quality=7),
|
||||
Sulfuras(name="Sulfuras, Hand of Ragnaros", sell_in=0, quality=80),
|
||||
Sulfuras(name="Sulfuras, Hand of Ragnaros", sell_in=-1, quality=80),
|
||||
Backstage(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20),
|
||||
Backstage(name="Backstage passes to a TAFKAL80ETC concert", sell_in=10, quality=49),
|
||||
Backstage(name="Backstage passes to a TAFKAL80ETC concert", sell_in=5, quality=49),
|
||||
General(name="Conjured Mana Cake", sell_in=3, quality=6), # <-- :O
|
||||
]
|
||||
|
||||
days = 2
|
||||
|
||||
Loading…
Reference in New Issue
Block a user