A repository to hold my Kata implementations.
These Katas are used to practice design patterns and utilise TDD.
Take each step in turn and don't look ahead.
For each kata, remember to:
- Start with the simplest test case
- Solve things as simply as possible so that you force yourself to write tests you did not think about
- Refactor after each passing test
- Create a simple String calculator with a method signature:
int Add(string numbers)
1.1. The method can take up to two numbers, separated by commas, and will return their sum.
1.2. For example “” or “1” or “1,2” as inputs.
1.3. For an empty string it will return 0. - Allow the Add method to handle an unknown amount of numbers
- Allow the Add method to handle new lines between numbers (instead of commas).
3.1. The following input is ok: “1\n2,3” (will equal 6)
3.2. The following input is NOT ok: “1,\n” (no need to prove it - just clarifying) - Support different delimiters
4.1. To change a delimiter, the beginning of the string will contain a separate line that looks like this:“//[delimiter]\n[numbers…]”
4.2. For example “//;\n1;2” should return three where the default delimiter is ‘;’.
4.3. The first line is optional. all existing scenarios should still be supported - Calling Add with a negative number will throw an exception “negatives not allowed” - and the negative that was passed.
- If there are multiple negatives, show all of them in the exception message.
- Numbers bigger than 1000 should be ignored, so adding 2 + 1001 = 2
- Delimiters can be of any length with the following format:
“//[delimiter]\n”
8.1. For example:“//[***]\n1***2***3”
should return 6 - Allow multiple delimiters like this:
“//[delim1][delim2]\n”
9.1. For example“//[*][%]\n1*2%3”
should return 6.
9.2. Make sure you can also handle multiple delimiters with length longer than one char
- Create a Greeter class with a method signature
string Greet(string name)
1.1. The method should returnHello <name>
1.2. The signature of greet should not change throughout the kata. - Greet trims the input
- Greet capitalizes the first letter of the name
- Greet returns
Good morning <name>
when the time is 06:00-12:00 - Greet returns
Good evening <name>
when the time is 18:00-22:00 - Greet returns
Good night <name>
when the time is 22:00-06:00 - Greet logs into console each time it is called
- Create a PrimeFactors class with a method signature
IEnumerable<int> Generate(int number)
1.1. The method should return 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]
- Create a game of Rock, Paper, Scissors with two players.
1.1. Rock beats Scissors
1.2. Scissors beats Paper
1.3. Paper beats Rock - If both players play the same shape then no player gets the win
- The amount of rounds played can be configurable
3.1. The winner is the player who has the most amount of round wins - If there is no way for the other player to win by continuing to play, end the game
4.1. For example, in a 3 round game if player one has 2 wins then end the game - Extend the game to also allow for Lizard and Spock.
5.1. Scissors cut Paper
5.2. Paper covers Rock
5.3. Rock crushes Lizard
5.4. Lizard poisons Spock
5.5. Spock smashes Scissors
5.6. Scissors decapitate Lizard
5.7. Lizard eats Paper
5.8. Paper disproves Spock
5.9. Spock vaporizes Rock
5.10. Rock crushes Scissors
- Create a parser which takes in arguments with flags and values.
1.1. Flags should be one character, preceded by a minus sign.
1.2. Each flag should have zero, or one value associated with it.
1.3. For example,-l -p 8080 -d /usr
indicates:
1.3.1. 3 flags: l, p, and d
1.3.2. The l flag has no value associated with it and so is a boolean
1.3.3. The p flag has an integer value of 8080
1.3.4. The d flag has a string value of /usr - Handle negative integers
2.1. For example,-n -6
indicates:
2.1.1. The n flag has an integer value of-6
- The parser should take a schema detailing what arguments the program expects.
1.1. The schema specifies the number and types of flags and values the program expects. - If a flag mentioned in the schema is missing in the arguments, a suitable default value should be returned.
3.1. For example,False
for a boolean,0
for a number, and“”
for a string. - Extend your code to support lists
4.1. For example,-g this,is,a,list -d 1,2,-3,5
indicates:
4.1.1. The g flag is a list of strings[“this”, “is”, “a”, “list”]
4.1.2. The d flag is a list of integers[1, 2, -3, 5]
- Create a Wrapper class with a static method named
Wrap
that takes 2 arguments; a string and a column number. - The function returns the string, but with line breaks inserted at just the right places to make sure that no line is longer than the column number.
2.1. For example,Wrapper.Wrap("one two three", 5)
should returnone t\r\nwo th\r\nree
- Break lines at word boundaries where possible.
3.1. For example,Wrapper.Wrap("one two three four", 7)
should returnone two\r\n three\r\n four
- Don't start or end a line with a space character
4.1. For example,Wrapper.Wrap("one two three four", 7)
should returnone two\r\nthree\r\nfour