Files
GildedRose-Refactoring-Kata/python/gilded_rose.py
T
Simon Fothergill 39ce08d5ea Set up python project:
- I don't use approval testing, as I like to feel closer to the code whilst testing and for tests to be self contained and not rely on external data that has to be kept up to date and bloats the directory structure.
  - I like to use pdm to manage venvs, dependancies and scripts with one modern tool.
  - I bumped the version number for my version.
  - This is an exercise, no reason to have multiple dependency lists.
  - I find pytest and the plugin easier to use and a threshold helpful.  Unittest adds unnecessary boilerplate code.
  - conftest not needed atm
  - Module level comments are helpful.
  - Use linting, type checking and formatting tools - good practice.
  - Update readme given alterations.
  - Update gitignore to new python environment

N.B.  linting errors left until tests in place.
2026-09-15 20:51:56 +01:00

54 lines
1.9 KiB
Python
Executable File

# -*- coding: utf-8 -*-
# Main logic for Inn
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)