FizzBuzz Kata
Instructions
FizzBuzz is a simple number game in which you count, but replace certain numbers with the words "Fizz" and/or "Buzz", adhering to certain rules.
- Create an application that prints out the numbers 1 through 16, separated by newlines.
- Create FizzBuzz class with
FormatNumber(int number)
method. - Given number divisible by 3, the method should return "Fizz".
- Given number divisible by 5, the method should return "Buzz".
- Given number divisible by 3 and 5, the method should return "FizzBuzz".
- Given any other number, the method should return the string representation of the number.
Sample Output
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
String Calculator Kata
Instructions
- Create a StringCalculator with a method Add(string numbers) that returns an integer.
- Start with the simplest test case of an empty string, then 1 number, then 2.
- Solve things as simply as possible!
- An empty string should return a sum of 0.
- numbers can include 0, 1, or 2 integers (e.g. "", "1", "1,2").
- Add returns the sum of the integers provided in the string numbers.
- Remember to refactor after each test.
- Allow the Add method to handle an unknown number of numbers (in the string).
- Allow the Add method to handle new lines between numbers (as well as commas):
- Example: "1\n2,3" returns 6.
- Example: "1,\n" is invalid, but no need to test for it. For this kata we are only concerned with testing correct inputs.
- Allow the Add method to handle a different delimiter:
- To change the delimiter, the beginning of the string should be a separate line formatted like this: "//[delimiter]\n[numbers]"
- Example: "//;\n1;2" returns 3 (the delimiter is ";").
- This first line is optional; all existing scenarios (using "," or "\n") should work as before.
- Calling Add with a negative number will throw an exception "Negatives not allowed: " and then listing all negative numbers that were in the list of numbers.
- Example: "-1,2" throws "Negatives not allowed: -1".
- Example: "2,-4,3,-5" throws "Negatives not allowed: -4,-5".
- Numbers greater than 1000 should be ignored.
- Example: "1001,2" returns 2.
- Delimiters can be any length, using this syntax: "//[|||]\n1|||2|||3" returns 6.
- Allow multiple delimiters, using this syntax: "//[|][%]\n1|2%3" returns 6.
- Handle multiple delimiters of any length.