Browse Source

Program to pass the FizzBuzz Test using TDD

Akeem Cherry 6 years ago
parent
commit
bbb63bd822
2 changed files with 49 additions and 0 deletions
  1. 17
    0
      src/main/java/FizzBuzz.java
  2. 32
    0
      src/test/java/FizzBuzzTest.java

+ 17
- 0
src/main/java/FizzBuzz.java View File

@@ -1,2 +1,19 @@
1 1
 public class FizzBuzz {
2
+    public String fizzBuzz(int i) {
3
+        if (i % 3 == 0 && i % 5 == 0) {
4
+            return "FizzBuzz";
5
+        }
6
+
7
+        if (i % 3 == 0) {
8
+            return "Fizz";
9
+        }
10
+
11
+        if (i % 5 == 0){
12
+                return "Buzz";
13
+            }
14
+
15
+        else {
16
+            return Integer.toString(i);
17
+        }
18
+    }
2 19
 }

+ 32
- 0
src/test/java/FizzBuzzTest.java View File

@@ -1,2 +1,34 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
1 4
 public class FizzBuzzTest {
5
+    FizzBuzz fizzBuzzer = new FizzBuzz();
6
+
7
+    @Test
8
+    public void TestFizzBuzzThree() {
9
+        String actual = fizzBuzzer.fizzBuzz(3);
10
+        String expected = "Fizz";
11
+        Assert.assertEquals(expected, actual);
12
+    }
13
+
14
+    @Test
15
+    public void TestFizzBuzzFive() {
16
+        String actual = fizzBuzzer.fizzBuzz(5);
17
+        String expected = "Buzz";
18
+        Assert.assertEquals(expected, actual);
19
+    }
20
+
21
+    @Test
22
+    public void TestFizzBuzzFifteen() {
23
+        String actual = fizzBuzzer.fizzBuzz(15);
24
+        String expected = "FizzBuzz";
25
+        Assert.assertEquals(expected, actual);
26
+    }
27
+
28
+    @Test
29
+    public void TestFizzBuzzNineteen() {
30
+        String actual = fizzBuzzer.fizzBuzz(19);
31
+        String expected = "19";
32
+        Assert.assertEquals(expected, actual);
33
+    }
2 34
 }