• Stars
    star
    3,428
  • Rank 13,036 (Top 0.3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 11 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Starting code for the GildedRose Refactoring Kata in many programming languages.

Gilded Rose Refactoring Kata

This Kata was originally created by Terry Hughes (http://twitter.com/TerryHughes). It is already on GitHub here. See also Bobby Johnson's description of the 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)

As Bobby Johnson points out in his article "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.

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. A while back I wrote this article "Writing Good Tests for the Gilded Rose Kata" about how you could use this kata in a coding dojo.

How to use this Kata

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" 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.

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 "Text-Based" tests provided in this repository. (Read more about that in the next section)

Whichever testing approach you choose, 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 designing tests, taking small steps, running the tests often, and incrementally improving the design.

Gilded Rose Requirements in other languages

Text-Based Approval Testing

Most language versions of this code have a TextTest fixture for Approval testing. For information about this, see the TextTests README

Translating this code

More translations are most welcome! I'm very open for pull requests that translate the starting position into additional languages.

Please note a translation should ideally include:

  • a translation of the production code for 'update_quality' and Item
  • one failing unit test complaining that "fixme" != "foo"
  • a TextTest fixture, ie a command-line program that runs update_quality on the sample data for the number of days specified.

Please don't write too much code in the starting position or add too many unit tests. The idea with the one failing unit test is to tempt people to work out how to fix it, discover it wasn't that hard, and now they understand what this test is doing they realize they can improve it.

If your programming language doesn't have an easy way to add a command-line interface, then the TextTest fixture is probably not necessary.

More Repositories

1

Tennis-Refactoring-Kata

This is a Refactoring Kata based on the rules of Tennis
TypeScript
649
star
2

Racing-Car-Katas

The starting code for several code katas on a racing car theme
Java
267
star
3

Theatrical-Players-Refactoring-Kata

Example from first chapter of 'Refactoring' by Martin Fowler, with tests and translations
Pascal
193
star
4

Parrot-Refactoring-Kata

Kata to learn about Polymorphism
XSLT
113
star
5

KataTrainReservation

A Kata exercise. This one involves writing code to reserve seats on a train.
Python
112
star
6

SupermarketReceipt-Refactoring-Kata

This is a refactoring kata for improving your coding skills
C#
100
star
7

Yatzy-Refactoring-Kata

Starting code for a Refactoring Code Kata on the Yatzy rules
C++
93
star
8

Phone-Numbers-Kata

Some sample data you could use to help test your solution to the Phone Numbers code kata, and a script to create it.
Python
36
star
9

Product-Export-Refactoring-Kata

exercise for practicing refactoring
C
23
star
10

Lift-Kata

starting position for the Lift Kata with an Approval Testing approach
C++
21
star
11

Clarify-Exception-Refactoring-Kata

For practicing refactoring, removing duplication, and making code more flexible
Java
19
star
12

CustomerSync-Refactoring-Kata

Refactoring exercise where data layer and business layer are not clearly separated
Java
19
star
13

DiamondKata

skeleton solution and test cases for comparing iterative and incremental approaches
PHP
19
star
14

Necklace-Refactoring-Kata

the goal is to practice refactoring to a Chain of Responsibility pattern
C++
18
star
15

Online-Shopping-Kata

Refactoring Kata to practice teasing out incohesive, coupled code
PHP
18
star
16

Email-Sender-Refactoring-Kata

Code from Michael Feathers presentation about "Tell, Don't Ask" at Craft 2019
Java
18
star
17

Hands-On-Approval-Testing-For-Developers-Materials

exercises for this training course offered via O'Reilly
Java
17
star
18

ValidateAndAddProduct-Refactoring-Kata

a kata for practicing both testing with Combination Approvals and 'Split Phase' refactoring
Java
17
star
19

vsftpd-server

docker image for vsftpd ftp server
Shell
13
star
20

StrangeCharacters-TestDesign-Kata

for writing tests that check correct objects are included in a list
C++
12
star
21

OvertimeCalculation-Refactoring-Kata

a refactoring exercise with a complex conditional for dividing overtime hours into two rates
Java
12
star
22

DeliveryController-Refactoring-Kata

refactoring kata where you need a mock or stub
Java
10
star
23

Scrabble-Kata

starting code and instructions to help you with the Scrabble kata
Java
10
star
24

KataMedicineClash

Sample solution and graph visualization code for the MedicineClash Code Kata
Python
10
star
25

ApprovalTools

useful little scripts
Python
8
star
26

Horse-Kata

An exercise for practicing Test-Driven Development
C#
8
star
27

IceCreamForecasting-Refactoring-Kata

an exercise for getting awkward code under test
Python
8
star
28

DungeonEscape-Refactoring-Kata

Write tests for a command line program that takes user input.
C
8
star
29

TimerExpiry-Refactoring-Kata

exercise to practice removing duplication
C
8
star
30

Single-Sign-On-Kata

a kata useful for understanding Test Doubles
C++
7
star
31

CashMachine-Refactoring-Kata

sample code for explaining the Law of Demeter
C#
7
star
32

LeapYearTestExamples

Documents a variety of ways to write unit tests for the Leap Year Kata
Java
7
star
33

FancyCommand-Refactoring-Kata

For practicing refactoring techniques like 'peel' and approval testing xml
C#
7
star
34

Encryptor-Refactoring-Kata

refactoring kata
C#
6
star
35

RefactoringGolf

Practice using your refactoring tools with 'before' and 'after' code snippets
C#
6
star
36

SafeCalculator-TestDesign-Kata

the code has a bug and needs some unit tests. You'll need a test double too.
CMake
6
star
37

VendingMachine-Approval-Kata

An exercise for learning about Approval testing and in particular designing a printer
C++
6
star
38

personnummer

library for generating Swedish personal numbers for testing purposes
Python
6
star
39

FizzBuzzKata-Samples

Some sample solutions to the FizzBuzz Kata, to provoke discussion.
C++
5
star
40

BeeFriendly

app for learning about testing in a microservices architecture
Python
5
star
41

pytest-approvaltests

Plugin to configure pytest for use with approval tests
Python
5
star
42

Yatzy-Vendor-Assessment-Kata

Exercise in finding bugs in three competing implementations of the Yatzy rules
Java
4
star
43

Approvals-Puzzles

Which of these programs are suitable to be tested with Approval Testing?
Python
4
star
44

Theater-Kata

Java
4
star
45

K8sAudit-Kata

an exercise for practicing TDD when you have dependencies on a REST API and a file system
4
star
46

starter

empty starting projects in various languages
C
4
star
47

StrangeCharacters-Refactoring-Kata

refactoring exercise to practice extract method and extract class
C++
4
star
48

EventParserDesignKata

For better understanding that how you set up your tests changes the design of your production code.
Java
4
star
49

TirePressure-Kata

code kata for learning more about test doubles and SOLID principles
PHP
4
star
50

LockController-Refactoring-Kata

for practicing testing a class with awkward dependencies
Kotlin
4
star
51

Refactor-Conditionals

some examples of ways to refactor conditional statements
C++
4
star
52

Phonebook-Python-Example-Project

example project using Python and Pytest with standard layout of files
Python
4
star
53

MarsRover-Kata

Sample solution to the Mars Rover Kata with different testing approaches
Python
4
star
54

DiscountApplier-TestDesign-Kata

the code has bugs and needs some unit tests. You'll need a test double too.
C
4
star
55

ShoppingBasket-TDD-Kata

Starting code for doing the Shopping Basket kata with TDD https://sammancoaching.org/kata_descriptions/shopping_basket.html
Swift
4
star
56

Spiral-Refactoring-Kata

This code works but could do with some attention to make it more readable and maintainable.
Kotlin
3
star
57

Encode-TestDesign-Kata

the code works and the tests pass, can you make the code easier to maintain?
C++
3
star
58

VoidFunctionNoArgs-Refactoring-Kata

exercise to practice getting a void function with no arguments under test and refactored
Java
3
star
59

EnvironmentalControllerKata

sample code for discussing test design principles
C++
3
star
60

gothpy-katas

A collection of code (mostly katas) done at the GothPy meetings
Python
3
star
61

RPG-Combat-Approval-Kata

starting position for the RPG Combat Kata with an approval testing approach
C++
3
star
62

Cloud-Migration-Refactoring-Kata

Exercise in good use of test doubles and the dangers of mandating 80% test coverage
Java
3
star
63

FIRST-Test-Design-Kata

to practice writing test cases that follow the FIRST principles
CMake
3
star
64

FizzBuzz-Refactoring-Kata

For practicing "make the change easy, then make the easy change"
Java
3
star
65

TicTacToe-Kata

Starting code for the TicTacToe Kata including a printer for the board
Python
3
star
66

UI-Katas

Kata exercises that have user interfaces.
Java
3
star
67

Roadload-Refactoring-Kata

A calculation with some duplication and no tests
C#
3
star
68

Yatzy-Approval-Kata

Excercise to help you learn how to use approval testing and TextTest in particular
Python
3
star
69

Device-Driver-Kata

a Kata for practicing the use of Mocks
C
3
star
70

RecentlyUsedList-Test-Design-Kata

for practicing test design, fixtures in particular
C++
2
star
71

GameOfLife-Refactoring-Kata

Code that works but which could do with some attention to make it more readable and maintainable.
Kotlin
2
star
72

patients

Sample application for testing
Ruby
2
star
73

Recently-Used-List-Docs

practice writing user documentation based on unit tests
C++
2
star
74

ApprovalTests.Python

python port of the ApprovalTests library http://approvaltests.sourceforge.net/
Python
2
star
75

CalcStats-TestDesign-Kata

for practicing test design using https://sammancoaching.org/kata_descriptions/calc_stats.html
C
2
star
76

sbt-texttest

SBT plugin that can run texttests in your sbt projects.
Scala
2
star
77

buildstats

keep track of how long the build is taking
Python
2
star
78

ChainOfResponsibility-Pets

A lighthearted codebase to remind you what a Chain Of Responsibility design pattern looks like
Java
2
star
79

WikiSearchKata

a kata for practicing a refactoring: template method -> strategy pattern
Python
2
star
80

Yatzy-Prompts

for introducing typist and navigator roles
C#
2
star
81

GildedRose-Approval-Kata

Same problem code as for GildedRose-Refactoring-Kata, but set up for TextTest Approval tests
Java
2
star
82

MarsRover-Screencast

the repo I used when I recorded myself solving this kata in Java
Java
2
star
83

MetricTables-Kata

starting position for a from-scratch TDD exercise
Python
2
star
84

HtmlConverter-Kata

Code kata for learning about test doubles and SOLID principles
C++
2
star
85

TestDesign-Samples

some examples to get you thinking about test design.
C++
1
star
86

TrigMath-Kata

some code for trig math calculations that you should add tests for, as an exercise
C++
1
star
87

PipelineSimulation

Python
1
star
88

Screencast-Katas

The code I end up with after doing a screencast
Python
1
star
89

Instavoiced-Architecture-Kata

Materials to supplement this kata
1
star
90

ShoppingBasket-Test-Design-Kata

to practice making full use of your test framework to get the best possible feedback when you have a bug
C++
1
star
91

MarsRover-Sample-Tests

sample tests for mars rover kata, for review
C++
1
star
92

texttest-maven-plugin

Plugin to enable you to run tests created with TextTest as part of a maven build.
Java
1
star
93

SupermarketReceipt-Java

just the java version of this refactoring kata
Java
1
star
94

Supermarket-Kata-Sample-Tests

Sample test cases for Supermarket Kata, for review and discussion
C#
1
star
95

ClosestToZero-Parameterized

practice writing parameterized tests and interpreting failures
Go
1
star
96

Auction-TestDesign-Kata

for learning about test design, specifically with Mocks
Java
1
star
97

TurnTicket-Kata

Code kata for learning more about Test Doubles and SOLID principles
Swift
1
star
98

WordWrap-TestDesign-Kata

several implementations which you can test with the same test cases
Java
1
star
99

HandbagEvent-Refactoring-Kata

Exercise to practice sorting out a bumpy road smell
Python
1
star