• Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language Pascal
  • License
    MIT License
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

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

Repository Details

Example from first chapter of 'Refactoring' by Martin Fowler, with tests and translations

Support this and all my katas via Patreon

Theatrical Players Refactoring Kata

The first chapter of 'Refactoring' by Martin Fowler, 2nd Edition contains a worked example of this exercise, in javascript. That chapter is available to download for free. This repo contains the starting point for this exercise in several languages, with tests, so you can try it out for yourself.

I made a video "Refactoring with Martin Fowler | Theatrical Players Code Kata" that explains a little bit about the exercise and why you should give it a try.

What you need to change

Refactoring is usually driven by a need to make changes. In the book, Fowler adds code to print the statement as HTML in addition to the existing plain text version. He also mentions that the theatrical players want to add new kinds of plays to their repertoire, for example history and pastoral.

Automated tests

In his book Fowler mentions that the first step in refactoring is always the same - to ensure you have a solid set of tests for that section of code. However, Fowler did not include the test code for this example in his book. I have used an Approval testing approach and added some tests. I find Approval testing to be a powerful technique for rapidly getting existing code under test and to support refactoring. You should review these tests and make sure you understand what they cover and what kinds of refactoring mistakes they would expect to find.

Acknowledgements

Thankyou to Martin Fowler for kindly giving permission to use his code.

More Repositories

1

GildedRose-Refactoring-Kata

Starting code for the GildedRose Refactoring Kata in many programming languages.
C++
3,428
star
2

Tennis-Refactoring-Kata

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

Racing-Car-Katas

The starting code for several code katas on a racing car theme
Java
267
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