Soujanya Buragapu 6 years ago
parent
commit
f2a4934f9e
5 changed files with 145 additions and 4 deletions
  1. BIN
      .DS_Store
  2. BIN
      src/.DS_Store
  3. BIN
      src/main/.DS_Store
  4. 71
    2
      src/main/java/FizzBuzz.java
  5. 74
    2
      src/test/java/FizzBuzzTest.java

BIN
.DS_Store View File


BIN
src/.DS_Store View File


BIN
src/main/.DS_Store View File


+ 71
- 2
src/main/java/FizzBuzz.java View File

@@ -1,2 +1,71 @@
1
-public class FizzBuzz {
2
-}
1
+public class FizzBuzz
2
+{
3
+    public static String testNumberDivisibleByThree(int number)
4
+    {
5
+        String divisibleByThree = "";
6
+        if (number % 3 == 0)
7
+        {
8
+            divisibleByThree = "Fizz";
9
+        } else
10
+            {
11
+            divisibleByThree = divisibleByThree.format("%d", number);
12
+        }
13
+        return divisibleByThree;
14
+    }
15
+    public String testNumberNotDivisibleByThree(int number)
16
+    {
17
+        String notthree = "";
18
+        if (number % 3 == 0) {
19
+            notthree = "Fizz";
20
+        } else {
21
+            notthree = notthree.format("%d", number);
22
+        }
23
+        return notthree;
24
+    }
25
+    public static String testNumberDivisibleByFive(int number) {
26
+        String byfive = "";
27
+        if (number % 5 == 0) {
28
+            byfive = "Buzz";
29
+        } else
30
+            {
31
+                byfive = byfive.format("%d", number);
32
+        }
33
+        return byfive;
34
+    }
35
+    public String testNumberNotDivisibleByFive(int number)
36
+    {
37
+        String notfive = "";
38
+        if (number % 5 == 0)
39
+        {
40
+            notfive = "Buzz";
41
+        } else
42
+        {
43
+            notfive = notfive.format("%d", number);
44
+        }
45
+        return notfive;
46
+    }
47
+    public static String testDivisibleByFifteen(int number)
48
+    {
49
+        String byfifteen = "";
50
+        if (number % 15 == 0 )
51
+        {
52
+            byfifteen = "FizzBuzz";
53
+        } else
54
+            {
55
+                byfifteen = byfifteen.format("%d", number);
56
+        }
57
+        return byfifteen;
58
+    }
59
+    public String testNotDivisibleByFifteen(int number)
60
+    {
61
+        String notbyfifteen = "";
62
+        if (number % 15 == 0 )
63
+        {
64
+            notbyfifteen = "FizzBuzz";
65
+        } else
66
+        {
67
+            notbyfifteen = notbyfifteen.format("%d", number);
68
+        }
69
+        return notbyfifteen;
70
+    }
71
+}

+ 74
- 2
src/test/java/FizzBuzzTest.java View File

@@ -1,2 +1,74 @@
1
-public class FizzBuzzTest {
2
-}
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+public class FizzBuzzTest
4
+{
5
+    @Test
6
+    public void testNumberDivisibleByThree() {
7
+        //Given
8
+        FizzBuzz bythree = new FizzBuzz();
9
+        int number = 6;
10
+        String expected = "Fizz";
11
+
12
+        //when
13
+        String actual = bythree.testNumberDivisibleByThree(number);
14
+
15
+        //Then
16
+        Assert.assertEquals(expected, actual);
17
+    }
18
+    @Test
19
+    public void testNumberNotDivisibleByThree() {
20
+        //Given
21
+        FizzBuzz notbythree = new FizzBuzz();
22
+        int number = 4;
23
+        String expected = "4";
24
+        //when
25
+        String actual = notbythree.testNumberNotDivisibleByThree(number);
26
+        //Then
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+    @Test
30
+    public void testNumberDivisibleByFive()
31
+    {
32
+        FizzBuzz byfive = new FizzBuzz();
33
+        int number = 10;
34
+        String expected = "Buzz";
35
+        //when
36
+        String actual = byfive.testNumberDivisibleByFive(number);
37
+        //Then
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+    @Test
41
+    public void testNumberNotDivisibleByFive()
42
+    {
43
+        //Given
44
+        FizzBuzz notbyfive = new FizzBuzz();
45
+        int number = 7;
46
+        String expected = "7";
47
+        //when
48
+        String actual = notbyfive.testNumberNotDivisibleByFive(number);
49
+        //Then
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+    @Test
53
+    public void testDivisibleByFifteen()
54
+    {
55
+        FizzBuzz byfifteen = new FizzBuzz();
56
+        int number = 15;
57
+        String expected = "FizzBuzz";
58
+        //when
59
+        String actual = byfifteen.testDivisibleByFifteen(number);
60
+        //Then
61
+        Assert.assertEquals(expected, actual);
62
+    }
63
+    @Test
64
+    public void testNotDivisibleByFifteen()
65
+    {
66
+        FizzBuzz notbyfifteen = new FizzBuzz();
67
+        int number = 17;
68
+        String expected = "17";
69
+        //when
70
+        String actual = notbyfifteen.testNotDivisibleByFifteen(number);
71
+        //Then
72
+        Assert.assertEquals(expected, actual);
73
+    }
74
+}