package com.hemmerling.javatest.fizzbuzz;
import static org.junit.Assert.*;
import org.junit.Test;
public class FizzBuzz {
public static void main(String[] args) {
System.out.println("FizzBuzz");
}
}
package com.hemmerling.javatest.fizzbuzz;
import static org.junit.Assert.*;
import org.junit.Test;
public class FizzBuzzTest {
@Test
public void test() {
fail("Not yet implemented");
}
}
The functions “test01”, “test02”,.. are previous versions of the function “fizzBuzz”, which document the development of the testing and coding process.
/**
* Kata FizzBuzz, using JUnit 4.9. The test class.
* @author Rolf Hemmerling
* @date 2011-06-30
*/
package com.hemmerling.javatest.fizzbuzz;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class FizzBuzzTest {
private FizzBuzz test;
// @Before
public void setUp() throws Exception {
FizzBuzz test = new FizzBuzz();
}
@Test
public void test01() {
//fail("Not yet implemented");
FizzBuzz test = new FizzBuzz();
assertEquals("1", test.fizzBuzz(1),"1");
}
@Test
public void test02() {
FizzBuzz test = new FizzBuzz();
assertEquals("3", test.fizzBuzz(3),"Fizz");
}
@Test
public void test03() {
FizzBuzz test = new FizzBuzz();
assertEquals("5", test.fizzBuzz(5),"Buzz");
}
@Test
public void test04() {
FizzBuzz test = new FizzBuzz();
assertEquals("6", test.fizzBuzz(6),"Fizz");
}
@Test
public void test05() {
FizzBuzz test = new FizzBuzz();
assertEquals("10", test.fizzBuzz(10),"Buzz");
}
@Test
public void test06() {
FizzBuzz test = new FizzBuzz();
assertEquals("15", test.fizzBuzz(15),"FizzBuzz");
}
@Test
public void test07() {
FizzBuzz test = new FizzBuzz();
String aListe[] = {
"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz",
"11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz",
"Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz",
"31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz",
"41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz",
"Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz",
"61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz",
"71", "Fizz", "73", "74", "FizzBuzz", "76", "77", "Fizz", "79", "Buzz",
"Fizz", "82", "83", "Fizz", "Buzz", "86", "Fizz", "88", "89", "FizzBuzz",
"91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz", "Buzz" };
assertArrayEquals("Liste", test.fizzBuzzListe(),aListe);
}
The functions “fizzBuzz01”, “fizzBuzz02”,.. are previous versions of the function “fizzBuzz”, which document the development of the testing and coding process.
/**
* Kata FizzBuzz, using JUnit 4.9. The class to be tested.
* @author Rolf Hemmerling
* @date 2011-06-28
*/
package com.hemmerling.javatest.fizzbuzz;
import static org.junit.Assert.*;
import org.junit.Test;
public class FizzBuzz {
public static void main(String[] args) {
System.out.println("FizzBuzz");
}
public String fizzBuzz01( int anInputValue ) {
String aReturnValue;
aReturnValue = "" + 1;
return ( aReturnValue );
}
public String fizzBuzz02( int anInputValue ) {
String aReturnValue;
if ( anInputValue == 3 ) {
aReturnValue = "Fizz";
}
else {
aReturnValue = "" + 1;
};
return ( aReturnValue );
}
public String fizzBuzz03( int anInputValue ) {
String aReturnValue;
if ( anInputValue == 3 ) {
aReturnValue = "Fizz";
}
else {
if ( anInputValue == 5 ) {
aReturnValue = "Buzz";
}
else {
aReturnValue = "" + 1;
}
};
return ( aReturnValue );
}
public String fizzBuzz04( int anInputValue ) {
String aReturnValue;
if ( ( anInputValue % 3 ) == 0 ) {
aReturnValue = "Fizz";
}
else {
if ( anInputValue == 5 ) {
aReturnValue = "Buzz";
}
else {
aReturnValue = "" + 1;
}
};
return ( aReturnValue );
}
public String fizzBuzz05( int anInputValue ) {
String aReturnValue;
if ( ( anInputValue % 3 ) == 0 ) {
aReturnValue = "Fizz";
}
else {
if ( ( anInputValue % 5 ) == 0 ) {
aReturnValue = "Buzz";
}
else {
aReturnValue = "" + 1;
}
};
return ( aReturnValue );
}
public String fizzBuzz( int anInputValue ) {
String aReturnValue = "";
if ( ( ( anInputValue % 3 ) == 0 ) || ( ( anInputValue % 5 ) == 0 ) ) {
if ( ( anInputValue % 3 ) == 0 ) {
aReturnValue = "Fizz";
};
if ( ( anInputValue % 5 ) == 0 ) {
aReturnValue = aReturnValue + "Buzz";
};
}
else {
aReturnValue = "" + anInputValue;
};
return ( aReturnValue );
}
public String[] fizzBuzzListe() {
String aListe[] = new String[100];
for (int aCounter=0; aCounter<100; aCounter++ ) {
aListe[aCounter] = fizzBuzz(aCounter+1);
System.out.print(aCounter+1);
System.out.print(" - "+aListe[aCounter]+"\n");
};
return ( aListe );
}
}