restructure and docs

This commit is contained in:
Koleh David 2025-02-06 14:08:09 +10:30
parent f1ef293d0c
commit 2cc3c73c4f
7 changed files with 10 additions and 110 deletions

View File

@ -1,53 +1,17 @@
_Support this and all my katas via [Patreon](https://www.patreon.com/EmilyBache)_
TODO: Link to Emily's original repo and video on the refactoring process
# Gilded Rose Refactoring Kata
# Getting setup
You can find out more about this exercise in my YouTube video [Why Developers LOVE The Gilded Rose Kata](https://youtu.be/Mt4XpGxigT4). I also have a video of a worked solution in Java - [Gilded Rose Kata, Hands-on](https://youtu.be/OdnV8hc9L7I)
Firstly, setup a python 3.12 environment.
TODO link to venv
I use this kata as part of my work as a technical coach. I wrote a lot about the coaching method I use in this book [Technical Agile Coaching with the Samman method](https://leanpub.com/techagilecoach). A while back I wrote this article ["Writing Good Tests for the Gilded Rose Kata"](http://coding-is-like-cooking.info/2013/03/writing-good-tests-for-the-gilded-rose-kata/) about how you could use this kata in a [coding dojo](https://leanpub.com/codingdojohandbook).
Then, install the requirements:
```bash
pip install -r requirements.txt
```
## How to use this Kata
# Running the tests
The simplest way is to just clone the code and start hacking away improving the design. You'll want to look at the ["Gilded Rose Requirements"](https://github.com/emilybache/GildedRose-Refactoring-Kata/blob/main/GildedRoseRequirements.md) which explains what the code is for. I strongly advise you that you'll also need some tests if you want to make sure you don't break the code while you refactor.
This project uses approval tests to ensure the behavior of the code remains the same during refactoring
You could write some unit tests yourself, using the requirements to identify suitable test cases. I've provided a failing unit test in a popular test framework as a starting point for most languages.
Alternatively, use the Approval tests provided in this repository. (Read more about that in the section "Text-based Approval Testing").
The idea of the exercise is to do some deliberate practice, and improve your skills at designing test cases and refactoring. The idea is not to re-write the code from scratch, but rather to practice taking small steps, running the tests often, and incrementally improving the design.
### Gilded Rose Requirements in other languages
- [English](GildedRoseRequirements.md)
- [Español](GildedRoseRequirements_es.md)
- [Français](GildedRoseRequirements_fr.md)
- [Italiano](GildedRoseRequirements_it.md)
- [日本語](GildedRoseRequirements_jp.md)
- [Português](GildedRoseRequirements_pt-BR.md)
- [Русский](GildedRoseRequirements_ru.md)
- [ไทย](GildedRoseRequirements_th.md)
- [中文](GildedRoseRequirements_zh.txt)
- [한국어](GildedRoseRequirements_kr.md)
- [German](GildedRoseRequirements_de.md)
- [Euskara](GildedRoseRequirements_eu.md)
## Text-Based Approval Testing
Most language versions of this code have a [TextTest](https://texttest.org) fixture for Approval testing. For information about this, see the [TextTests README](https://github.com/emilybache/GildedRose-Refactoring-Kata/tree/main/texttests)
## History of the exercise
This Kata was originally created by Terry Hughes (http://twitter.com/TerryHughes). It is already on GitHub [here](https://github.com/NotMyself/GildedRose). Bobby Johnson described the kata in an article titled "Refactor This: The Gilded Rose Kata", but unfortunately it is no longer on the internet. I found it on the Wayback Machine [here](https://web.archive.org/web/20240525015111/https://iamnotmyself.com/refactor-this-the-gilded-rose-kata/).
I translated the original C# into a few other languages, (with a little help from my friends!), and slightly changed the starting position. This means I've actually done a small amount of refactoring already compared with the original form of the kata, and made it easier to get going with writing tests by giving you one failing unit test to start with. I also added test fixtures for Text-Based approval testing with TextTest (see [the TextTests](https://github.com/emilybache/GildedRose-Refactoring-Kata/tree/main/texttests))
As Bobby Johnson points out in his article "Why Most Solutions to Gilded Rose Miss The Bigger Picture" (on the Wayback Machine [here](https://web.archive.org/web/20230530152324/https://iamnotmyself.com/why-most-solutions-to-gilded-rose-miss-the-bigger-picture/)), it'll actually give you
better practice at handling a legacy code situation if you do this Kata in the original C#. However, I think this kata
is also really useful for practicing writing good tests using different frameworks and approaches, and the small changes I've made help with that. I think it's also interesting to compare what the refactored code and tests look like in different programming languages.
## Contributing
Contributions are encouraged! You could add a translations of the specification
in another language or a new starting point for your favorite programming
language. Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.

5
python/.gitignore vendored
View File

@ -1,5 +0,0 @@
*.pyc
.cache
.coverage
.idea/
*.iml

View File

@ -1,29 +0,0 @@
# Gilded Rose starting position in Python
For exercise instructions see [top level README](../README.md)
Suggestion: create a python virtual environment for this project. See the [documentation](https://docs.python.org/3/library/venv.html)
## Run the unit tests from the Command-Line
```
python test_gilded_rose.py
```
## Run the TextTest fixture from the Command-Line
For e.g. 10 days:
```
python texttest_fixture.py 10
```
You should make sure the command shown above works when you execute it in a terminal before trying to use TextTest (see below).
## Run the TextTest approval test that comes with this project
There are instructions in the [TextTest Readme](../texttests/README.md) for setting up TextTest. You will need to specify the Python executable and interpreter in [config.gr](../texttests/config.gr). Uncomment these lines:
executable:${TEXTTEST_HOME}/python/texttest_fixture.py
interpreter:python

View File

@ -1,30 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from gilded_rose 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
]
days = 2
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()