Skip to content

Commit b532ef2

Browse files
committed
solve fizzbuzz feature and add test for other numbers feature
1 parent e948fef commit b532ef2

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/java/edu/thoughtworks/training/FizzBuzz.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
public class FizzBuzz {
44
public String represent(int number) {
5-
if (number%3 == 0) return "Fizz";
6-
else return "Buzz";
5+
String representation = new String();
6+
if (number % 3 == 0) representation += "Fizz";
7+
if (number % 5 == 0) representation += "Buzz";
8+
return representation;
79
}
810
}

src/test/java/edu/thoughtworks/training/FizzBuzzShould.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ public void returnFizzBuzzWhenNumberIsBothDivisibleBy3And5() {
2626
assertThat("FizzBuzz doesn't return FizzBuzz on multiples of 3 and 5",
2727
fizzBuzz.represent(15), is("FizzBuzz"));
2828
}
29+
30+
@Test
31+
public void returnItselfWhenNumberNotDivisibleBy3Or5() {
32+
FizzBuzz fizzBuzz = new FizzBuzz();
33+
assertThat("FizzBuzz doesn't return number when number is not divisible by 3 or 5",
34+
fizzBuzz.represent(8), is("8"));
35+
36+
}
2937
}

0 commit comments

Comments
 (0)