Procházet zdrojové kódy

completed FizzBuzz with Will's test

Jevit Tith před 6 roky
rodič
revize
ccb94584f3
2 změnil soubory, kde provedl 136 přidání a 16 odebrání
  1. 17
    0
      src/main/java/FizzBuzz.java
  2. 119
    16
      src/test/java/FizzBuzzTest.java

+ 17
- 0
src/main/java/FizzBuzz.java Zobrazit soubor

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

+ 119
- 16
src/test/java/FizzBuzzTest.java Zobrazit soubor

@@ -2,32 +2,135 @@ import org.junit.Assert;
2 2
 import org.junit.Test;
3 3
 
4 4
 public class FizzBuzzTest {
5
+    @Test
6
+    public void ifThreeAndFiveTest(){
7
+        // Given
8
+        int number1 = 15;
9
+        String expectedNumber = "FizzBuzz";
10
+        //When
11
+        String actualNumber = FizzBuzz.of(number1);
12
+        //then
13
+        Assert.assertEquals(expectedNumber, actualNumber);
14
+    }
15
+
16
+    @Test
17
+    public void ifThreeAndFiveTest2(){
18
+        // Given
19
+        int number1 = 300000000;
20
+        String expectedNumber = "FizzBuzz";
21
+        //When
22
+        String actualNumber = FizzBuzz.of(number1);
23
+        //then
24
+        Assert.assertEquals(expectedNumber, actualNumber);
25
+    }
26
+
27
+    @Test
28
+    public void ifThreeAndFiveTest3(){
29
+        // Given
30
+        int number1 = -3000;
31
+        String expectedNumber = "FizzBuzz";
32
+        //When
33
+        String actualNumber = FizzBuzz.of(number1);
34
+        //then
35
+        Assert.assertEquals(expectedNumber, actualNumber);
36
+    }
37
+
38
+    @Test
39
+    public void ifThreeTest(){
40
+        // Given
41
+        int number1 = 99;
42
+        String expectedNumber = "Fizz";
43
+        //When
44
+        String actualNumber = FizzBuzz.of(number1);
45
+        //then
46
+        Assert.assertEquals(expectedNumber, actualNumber);
47
+    }
48
+
49
+    @Test
50
+    public void ifThreeTest2(){
51
+        // Given
52
+        int number1 = 6;
53
+        String expectedNumber = "Fizz";
54
+        //When
55
+        String actualNumber = FizzBuzz.of(number1);
56
+        //then
57
+        Assert.assertEquals(expectedNumber, actualNumber);
58
+    }
59
+
60
+    @Test
61
+    public void ifThreeTest3(){
62
+        // Given
63
+        int number1 = -24;
64
+        String expectedNumber = "Fizz";
65
+        //When
66
+        String actualNumber = FizzBuzz.of(number1);
67
+        //then
68
+        Assert.assertEquals(expectedNumber, actualNumber);
69
+    }
70
+
71
+    @Test
72
+    public void ifFiveTest(){
73
+        // Given
74
+        int number1 = 25;
75
+        String expectedNumber = "Buzz";
76
+        //When
77
+        String actualNumber = FizzBuzz.of(number1);
78
+        //then
79
+        Assert.assertEquals(expectedNumber, actualNumber);
80
+    }
81
+
82
+    @Test
83
+    public void ifFiveTest2(){
84
+        // Given
85
+        int number1 = 5000;
86
+        String expectedNumber = "Buzz";
87
+        //When
88
+        String actualNumber = FizzBuzz.of(number1);
89
+        //then
90
+        Assert.assertEquals(expectedNumber, actualNumber);
91
+    }
5 92
 
6 93
     @Test
7
-    public void fizzTest (){
8
-        String expected = "Fizz";
9
-        String actual = FizzBuzz.count(9);
10
-        Assert.assertEquals(expected,actual);
94
+    public void ifFiveTest3(){
95
+        // Given
96
+        int number1 = -95;
97
+        String expectedNumber = "Buzz";
98
+        //When
99
+        String actualNumber = FizzBuzz.of(number1);
100
+        //then
101
+        Assert.assertEquals(expectedNumber, actualNumber);
11 102
     }
12 103
 
13 104
     @Test
14
-    public void BuzzTest (){
15
-        String expected = "Buzz";
16
-        String actual = FizzBuzz.count(10);
17
-        Assert.assertEquals(expected,actual);
105
+    public void ifNoneTest(){
106
+        // Given
107
+        int number1 = 0;
108
+        String expectedNumber = "0";
109
+        //When
110
+        String actualNumber = FizzBuzz.of(number1);
111
+        //then
112
+        Assert.assertEquals(expectedNumber, actualNumber);
18 113
     }
19 114
 
20 115
     @Test
21
-    public void BuzzTest (){
22
-        String expected = "FizzBuzz";
23
-        String actual = FizzBuzz.count(15);
24
-        Assert.assertEquals(expected,actual);
116
+    public void ifNoneTest2(){
117
+        // Given
118
+        int number1 = -47;
119
+        String expectedNumber = "-47";
120
+        //When
121
+        String actualNumber = FizzBuzz.of(number1);
122
+        //then
123
+        Assert.assertEquals(expectedNumber, actualNumber);
25 124
     }
26 125
 
27 126
     @Test
28
-    public void numbertest (){
29
-        String expected = "19";
30
-        String actual = FizzBuzz.count(19);
31
-        Assert.assertEquals(expected,actual);
127
+    public void ifNoneTest3(){
128
+        // Given
129
+        int number1 = 574;
130
+        String expectedNumber = "574";
131
+        //When
132
+        String actualNumber = FizzBuzz.of(number1);
133
+        //then
134
+        Assert.assertEquals(expectedNumber, actualNumber);
32 135
     }
33 136
 }