Created
October 7, 2010 16:31
-
-
Save MoriTanosuke/615405 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.kopis.katas; | |
public class FizzBuzz { | |
public String generate(int number) { | |
String result = null; | |
if(number == 0) { | |
result = "0"; | |
} else if(number % 3 == 0 && number % 5 == 0) { | |
result = "FizzBuzz"; | |
} else if(number % 3 == 0) { | |
result = "Fizz"; | |
} else if(number % 5 == 0) { | |
result = "Buzz"; | |
} else { | |
result = String.valueOf(number); | |
} | |
if(result.contains("3")) { | |
result = "Fizz"; | |
} else if(result.contains("5")) { | |
result = "Buzz"; | |
} | |
return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.kopis.katas; | |
import static org.junit.Assert.*; | |
import mockit.integration.junit4.JMockit; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
@RunWith(JMockit.class) | |
public class FizzBuzzTest { | |
@Test | |
public void testValids() { | |
int[] numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 99, 180}; | |
String[] expected = new String[] {"0", "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "Fizz", "14", "FizzBuzz", "Fizz", "FizzBuzz"}; | |
FizzBuzz fb = new FizzBuzz(); | |
int index = 0; | |
for (int number : numbers) { | |
assertEquals(expected[index++], fb.generate(number)); | |
} | |
} | |
@Test | |
public void testNewRequirements() { | |
int[] numbers = {13, 43, 99, 25, 55, 185, 90}; | |
String[] expected = new String[] {"Fizz", "Fizz", "Fizz", "Buzz", "Buzz", "Buzz", "FizzBuzz"}; | |
FizzBuzz fb = new FizzBuzz(); | |
int index = 0; | |
for (int number : numbers) { | |
assertEquals(expected[index++], fb.generate(number)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment