r extract func

This commit is contained in:
Koleh David 2025-02-06 15:02:07 +10:30
parent f822dc9325
commit ca617bda36
2 changed files with 47 additions and 44 deletions

View File

@ -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)

View File

@ -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)