mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-06 02:02:31 +00:00
r extract func
This commit is contained in:
parent
f822dc9325
commit
ca617bda36
@ -1,41 +1,3 @@
|
||||
# -*- 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
|
||||
@ -44,3 +6,44 @@ class Item:
|
||||
|
||||
def __repr__(self):
|
||||
return "%s, %s, %s" % (self.name, self.sell_in, self.quality)
|
||||
|
||||
|
||||
class GildedRose:
|
||||
def __init__(self, items: list[Item]):
|
||||
self.items = items
|
||||
|
||||
def update_item(self, item):
|
||||
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
|
||||
|
||||
def update_quality(self):
|
||||
for item in self.items:
|
||||
self.update_item(item)
|
||||
|
||||
@ -5,12 +5,6 @@ from approvaltests.combination_approvals import verify_all_combinations
|
||||
|
||||
|
||||
class GildedRoseTest(unittest.TestCase):
|
||||
def do_stuff(self, name, sell_in, quality):
|
||||
item = Item(name, sell_in, quality)
|
||||
gilded_rose = GildedRose([item])
|
||||
gilded_rose.update_quality()
|
||||
return str(item)
|
||||
|
||||
def test_update_quality(self):
|
||||
input_names = [
|
||||
"foo",
|
||||
@ -29,3 +23,9 @@ class GildedRoseTest(unittest.TestCase):
|
||||
input_qualities,
|
||||
],
|
||||
)
|
||||
|
||||
def do_stuff(self, name, sell_in, quality):
|
||||
item = Item(name, sell_in, quality)
|
||||
gilded_rose = GildedRose([item])
|
||||
gilded_rose.update_quality()
|
||||
return str(item)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user