This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
/
AFL_FizzBuzz_FirstTDD.java
111 lines (94 loc) · 3.46 KB
/
AFL_FizzBuzz_FirstTDD.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Author : Antonio Ferrer Lopez
Tweeter : @ToniFerrerLopez
This is my first KATA in java, I prepared it with the intention of practicing TDD with some partners.
The truth is that it is nothing to write home about but I really enjoyed doing it.
*/
public class AFL_FizzBuzz_FirstTDD {
private static final int FIRST_NUMBER = 0;
private static final int LAST_NUMBER = 100;
public static void main(String[] args) {
FizzBuzz fizzBuzz = new FizzBuzz();
for(int number = FIRST_NUMBER ; number<= LAST_NUMBER ; number++){
System.out.println("Numero : " + number + " RESPUESTA : " + fizzBuzz.play(number) );
}
}
public static class FizzBuzz {
public String play(int number) {
String value = "";
if (number == 0) value = "ZERO";
if(number == 1) value = "ONE";
if(number == 2) value = "TWO";
if(isDivisibleBythree(number) && isGreaterThanTwo(number)) value = "FIZZ";
if(isDivisibleByFive(number) && isGreaterThanTwo(number)) value = "BUZZ";
if(isDivisibleByFive(number) && isDivisibleBythree(number) && isGreaterThanTwo(number)) value = "FIZZBUZZ";
return value;
}
private boolean isDivisibleByFive(int number) {
return number % 5 == 0;
}
private boolean isDivisibleBythree(int number) {
return number % 3 == 0;
}
private boolean isGreaterThanTwo(int number) {
return number > 2;
}
}
}
/*SUM OF KATA :
* 1 - We have from 1 to 100 like entry point
* 2- If number is in range of 0 to 2 returns the number name on string format
* 2 - If Number is divisible by 3 returns FIZZ
* 3. If number is divisible by 5 returns BUZZ
* 4. If number is divisible by 3 and 5 return FIZZBUZZ
* */
class FizzBuzzTest {
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
private static AFL_FizzBuzz_FirstTDD.FizzBuzz fizzBuzz;
@BeforeAll
static void beforeAll() {
fizzBuzz = new AFL_FizzBuzz_FirstTDD.FizzBuzz();
}
@Test
void ifNumberIsZeroShouldReturnZero() {
String actual = fizzBuzz.play(0);
assertEquals("ZERO" , actual);
}
@Test
void ifNumberIsOneShouldReturnOne() {
String actual = fizzBuzz.play(1);
assertEquals("ONE" , actual);
}
@Test
void ifNumberIs2ShouldReturnTwo() {
String actual = fizzBuzz.play(2);
assertEquals("TWO" , actual);
}
@Test
void ifNumberIs3ShouldReturnFizz() {
String actual = fizzBuzz.play(3);
assertEquals("FIZZ" , actual);
}
@Test
void ifNumberIs5ShouldReturnBuzz() { ;
String actual = fizzBuzz.play(5);
assertEquals("BUZZ" , actual);
}
@Test
void ifNumberIsDivisibleBy3ShouldReturnFizz() {
String actual = fizzBuzz.play(6);
assertEquals("FIZZ" , actual);
}
@Test
void ifNumberIsDivisibleBy5ShouldReturnBuzz() {
String actual = fizzBuzz.play(10);
assertEquals("BUZZ" , actual);
}
@Test
void ifNumberIsDivisibleBy5AndBy3ShouldReturnFizzBuzz() {
String actual = fizzBuzz.play(15);
assertEquals("FIZZBUZZ" , actual);
}
}