by Paula Muldoon
This was initially a training exercise at Kurt Geiger. At that time, I didn't plan to commit this to GitHub - hence having six tests in a single commit.
I modified slightly the README of the original, to make the requirements clearer. I also changed the design from a single class to multiple classes, to clarify the responsibilities in each class. The design for this code is inspired by Sandi Metz, particularly POODR.
Especially with this kata, there is an infinite amount of variations on greetings and edge cases. On the principle of YAGNI, I limited myself to testing the specific examples provided by the authors rather than guessing what other contortions these specs might produce.
- Run
composer init
and create thecomposer.json
file - To run tests:
phpunit tests
- TDD
This Kata is designed to help practice what a test of a pure function ought to look like. It is intentionally designed to start with a very easy, non-branching base case which slowly becomes addled with complexity as additional requirements are added that will require significant branching and eventually a pressure to compose additional units.
This Kata was suggested by Nick Gauthier and inspired a bit by Bob from Exercism.
This Kata is designed to be used with Detroit-school TDD.
Write a method greet(name)
that interpolates name
in a simple greeting.
Example: when name
is "Bob"
, the method should return the string "Hello, Bob."
.
Handle nulls by introducing a stand-in.
Example: when name
is null, then the method should return the string "Hello, my friend."
Handle uppercase names by returning an uppercase greeting.
Example: when name
is "JERRY"
then the method should return the string "HELLO JERRY!"
Handle an array of two names.
Example: when name
is ["Jill", "Jane"]
, then the method should return the string "Hello, Jill and Jane."
Handle arrays of 3 or more names.
Example: when name
is ["Amy", "Brian", "Charlotte"]
, then the method should return the string "Hello, Amy, Brian, and Charlotte."
Handle arrays of mixed case names.
Example: when name
is ["Amy", "BRIAN", "Charlotte"]
, then the method should return the string "Hello, Amy and Charlotte. AND HELLO BRIAN!"
Handle arrays of names where a single item in the array contains two names.
Example: when name
is ["Bob", "Charlie, Dianne"]
, then the method should return the string "Hello, Bob, Charlie, and Dianne."
.
Handle deliberate commas indicated by escaped double quotation marks.
Example: when name
is ["Bob", ""Charlie, Dianne""], then the method should return the string
"Hello, Bob and Charlie, Dianne."
.