CHU1TA26 6 years ago
parent
commit
e29c3e3b85
5 changed files with 122 additions and 0 deletions
  1. BIN
      .DS_Store
  2. BIN
      src/.DS_Store
  3. 48
    0
      src/main/java/FizzBuzz.java
  4. BIN
      src/test/.DS_Store
  5. 74
    0
      src/test/java/FizzBuzzTest.java

BIN
.DS_Store View File


BIN
src/.DS_Store View File


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

@@ -1,2 +1,50 @@
1 1
 public class FizzBuzz {
2
+
3
+
4
+
5
+    public  static String divisibleBy3(int x){
6
+        String str ="";
7
+
8
+        if (x % 3==0) {
9
+            return "Fizz";
10
+        } else {
11
+
12
+
13
+         str+= str.format( "%d", x);
14
+        }
15
+
16
+
17
+        return str;
18
+    }
19
+
20
+    public  static String divisibleBy5(int x){
21
+        String str ="";
22
+
23
+        if (x % 5==0) {
24
+            return "Buzz";
25
+        } else {
26
+
27
+
28
+            str+= str.format( "%d", x);
29
+        }
30
+
31
+
32
+        return str;
33
+    }
34
+
35
+    public static String divisibleBy15(int x) {
36
+
37
+        String str= "";
38
+        if (x % 5==0 && x %3==0) {
39
+            return "FizzBuzz";
40
+        } else {
41
+
42
+
43
+            str+= str.format( "%d", x);
44
+        }
45
+
46
+
47
+        return str;
48
+
49
+    }
2 50
 }

BIN
src/test/.DS_Store View File


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

@@ -1,2 +1,76 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
1 4
 public class FizzBuzzTest {
5
+
6
+    @Test
7
+    public void fizzBuzz1(){
8
+
9
+        FizzBuzz fizz = new FizzBuzz();
10
+        // given
11
+        int x = 9;
12
+        String expected = "Fizz";
13
+        // when
14
+         String actual = FizzBuzz.divisibleBy3(x);
15
+        Assert.assertEquals(expected, actual);
16
+    }
17
+
18
+    @Test
19
+    public void fizzBuzz2(){
20
+
21
+        FizzBuzz fizz = new FizzBuzz();
22
+        // given
23
+        int x = 5;
24
+        String  expected = String.valueOf(x);
25
+        // when
26
+        String actual = FizzBuzz.divisibleBy3(x);
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void fizzBuzz3(){
32
+
33
+        FizzBuzz fizz = new FizzBuzz();
34
+        // given
35
+        int x = 50;
36
+        String expected = "Buzz";
37
+        // when
38
+        String actual = FizzBuzz.divisibleBy5(x);
39
+        Assert.assertEquals(expected, actual);
40
+    }
41
+    @Test
42
+    public void fizzBuzz4(){
43
+
44
+        FizzBuzz fizz = new FizzBuzz();
45
+        // given
46
+        int x = 8;
47
+        String expected = String.valueOf(x);
48
+        // when
49
+        String actual = FizzBuzz.divisibleBy5(x);
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+    @Test
53
+    public void fizzBuzz5(){
54
+
55
+        FizzBuzz fizz = new FizzBuzz();
56
+        // given
57
+        int x = 120;
58
+         String expected = "FizzBuzz";
59
+        // when
60
+        String actual = FizzBuzz.divisibleBy15(x);
61
+        Assert.assertEquals(expected, actual);
62
+    }
63
+    @Test
64
+    public void fizzBuzz6(){
65
+
66
+        FizzBuzz fizz = new FizzBuzz();
67
+        // given
68
+        int x = 29;
69
+        String expected =  String.valueOf(x);
70
+        // when
71
+        String actual = FizzBuzz.divisibleBy15(x);
72
+        Assert.assertEquals(expected, actual);
73
+    }
2 74
 }
75
+
76
+