Browse Source

Created Tests and then made FizzBuzz pass them

Saurav Kamath 6 years ago
parent
commit
3c86052e06
2 changed files with 46 additions and 0 deletions
  1. 7
    0
      src/main/java/FizzBuzz.java
  2. 39
    0
      src/test/java/FizzBuzzTest.java

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

@@ -1,2 +1,9 @@
1 1
 public class FizzBuzz {
2
+    public static String FizzBuzz(int i){
3
+        if (i % 3 == 0 && i % 5 == 0) return "FizzBuzz";
4
+        else if(i % 3 == 0) return "Fizz";
5
+        else if (i % 5 == 0) return "Buzz";
6
+
7
+        else return String.valueOf(i);
8
+    }
2 9
 }

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

@@ -1,2 +1,41 @@
1
+import org.junit.*;
2
+
1 3
 public class FizzBuzzTest {
4
+    @Test
5
+    public void checkThreeTest(){
6
+        //Given
7
+        int input = 3;
8
+        String expected = "Fizz";
9
+        //When
10
+        String actual = FizzBuzz.FizzBuzz(input);
11
+        Assert.assertEquals(expected,actual);
12
+    }
13
+    @Test
14
+    public void checkFiveTest(){
15
+        //Given
16
+        int input = 5;
17
+        String expected = "Buzz";
18
+        //When
19
+        String actual = FizzBuzz.FizzBuzz(input);
20
+        Assert.assertEquals(expected,actual);
21
+    }
22
+    @Test
23
+    public void checkFifteenTest(){
24
+        //Given
25
+        int input = 15;
26
+        String expected = "FizzBuzz";
27
+        //When
28
+        String actual = FizzBuzz.FizzBuzz(input);
29
+        Assert.assertEquals(expected,actual);
30
+    }
31
+    @Test
32
+    public void checkElseTest(){
33
+        //Given
34
+        int input = 8;
35
+        String expected = "8";
36
+        //When
37
+        String actual = FizzBuzz.FizzBuzz(input);
38
+        Assert.assertEquals(expected,actual);
39
+    }
40
+
2 41
 }