Created
February 17, 2016 18:47
-
-
Save dcmoore/87d89fa5ff7ceb53d1e5 to your computer and use it in GitHub Desktop.
python gilded rose kata mid-refactor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class GildedRose(object): | |
def __init__(self, items): | |
self.items = items | |
def update_quality(self): | |
for item in self.items: | |
item.update_quality | |
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) | |
class GildedItem(Item): | |
def update_quality(self): | |
if self.name != "Aged Brie" and self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name == "Backstage passes to a TAFKAL80ETC concert": | |
if self.sell_in < 11: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.sell_in < 6: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.sell_in = self.sell_in - 1 | |
if self.sell_in < 0: | |
if self.name != "Aged Brie": | |
if self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
self.quality = self.quality - self.quality | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
class AgedBrie(GildedItem): | |
def update_quality(self): | |
if self.name != "Aged Brie" and self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name == "Backstage passes to a TAFKAL80ETC concert": | |
if self.sell_in < 11: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.sell_in < 6: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.sell_in = self.sell_in - 1 | |
if self.sell_in < 0: | |
if self.name != "Aged Brie": | |
if self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
self.quality = self.quality - self.quality | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
class Sulfuras(GildedItem): | |
def update_quality(self): | |
if self.name != "Aged Brie" and self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name == "Backstage passes to a TAFKAL80ETC concert": | |
if self.sell_in < 11: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.sell_in < 6: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.sell_in = self.sell_in - 1 | |
if self.sell_in < 0: | |
if self.name != "Aged Brie": | |
if self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
self.quality = self.quality - self.quality | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
class BackstagePasses(GildedItem): | |
def update_quality(self): | |
if self.name != "Aged Brie" and self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name == "Backstage passes to a TAFKAL80ETC concert": | |
if self.sell_in < 11: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.sell_in < 6: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.sell_in = self.sell_in - 1 | |
if self.sell_in < 0: | |
if self.name != "Aged Brie": | |
if self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
self.quality = self.quality - self.quality | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
class ConjuredItem(GildedItem): | |
def update_quality(self): | |
if self.name != "Aged Brie" and self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name == "Backstage passes to a TAFKAL80ETC concert": | |
if self.sell_in < 11: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.sell_in < 6: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.sell_in = self.sell_in - 1 | |
if self.sell_in < 0: | |
if self.name != "Aged Brie": | |
if self.name != "Backstage passes to a TAFKAL80ETC concert": | |
if self.quality > 0: | |
if self.name != "Sulfuras, Hand of Ragnaros": | |
self.quality = self.quality - 1 | |
else: | |
self.quality = self.quality - self.quality | |
else: | |
if self.quality < 50: | |
self.quality = self.quality + 1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
from gilded_rose import * | |
if __name__ == "__main__": | |
print ("OMGHAI!") | |
items = [ | |
GildedItem(name="+5 Dexterity Vest", sell_in=10, quality=20), | |
AgedBrie(name="Aged Brie", sell_in=2, quality=0), | |
GildedItem(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), | |
BackstagePasses(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20), | |
BackstagePasses(name="Backstage passes to a TAFKAL80ETC concert", sell_in=10, quality=49), | |
BackstagePasses(name="Backstage passes to a TAFKAL80ETC concert", sell_in=5, quality=49), | |
ConjuredItem(name="Conjured Mana Cake", sell_in=3, quality=6), # <-- :O | |
] | |
days = 200 | |
import sys | |
if len(sys.argv) > 1: | |
days = int(sys.argv[1]) + 1 | |
for day in range(days): | |
print("-------- day %s --------" % day) | |
print("name, sellIn, quality") | |
for item in items: | |
print(item) | |
print("") | |
GildedRose(items).update_quality() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment