Playing with TDD
https://github.com/wix/tdd-katas
Write a Greeter
class with greet
function that receives a name as input and outputs Hello <name>
. The signature of greet
should not change throughout the kata. You are allowed to construct Greeter
object as you please.
greet
trims the inputgreet
capitalizes the first letter of the namegreet
returnsGood morning <name>
when the time is 06:00-12:00greet
returnsGood evening <name>
when the time is 18:00-22:00greet
returnsGood night <name>
when the time is 22:00-06:00greet
logs into console each time it is called
Write a method add
under an object StringCalculator
that, given a delimited string, returns the sum of the numbers in the string.
- An empty string returns zero
'' => 0
- A single number returns the value
'1' => 1 '2' => 2
- Two numbers, comma delimited, returns the sum
'1,2' => 3 '10,20' => 30
- Two numbers, newline delimited, returns the sum
'1\n2' => 3
- Three numbers, delimited either way, returns the sum
'1\n2,3\n4' => 10
- Negative numbers throw an exception with the message
'-1,2,-3' => 'negatives not allowed: -1,-3'
- Numbers greater than 1000 are ignored
- A single char delimiter can be defined on the first line starting with
//
(e.g//#\n1#2
for a ‘#’ as the delimiter) - A multi char delimiter can be defined on the first line starting with
//
(e.g.//###\n1###2
for ‘###’ as the delimiter)
Write a function generate
under a module PrimeFactors that, given an integer, returns the list containing the prime factors in numerical sequence.
- 1 should return []
- 2 should return [2]
- 3 should return [3]
- 4 should return [2,2]
- 5 should return [5]
- 6 should return [2,3]
- 7 should return [7]
- 8 should return [2,2,2]
- 9 should return [3,3]
- 4620 should return [2,2,3,5,7,11]
Write a BowlingGame
object with methods roll(pins)
and getScore()
.
This will be the game engine which follows the rules of bowling:
- The game consists of 10 frames, in each frame the player has the ability to knock down 10 pins.
- The score for the frame is the total number of pins knocked down + bonuses for
strikes
andspares
. - A
spare
is when the player knocks down all 10 pins in 2 tries. The bonus for a spare is the next roll. - A
strike
is when the player knocks down all 10 pins in 1 try. The bonus is the next 2 rolls. - In the tenth frame a player who rolls a spare / strike gets an extra roll(s) to complete the frame.
- No more than 3 rolls can be rolled in the 10th frame.