NiraParikh 6 年前
父节点
当前提交
dc35ba87ac
共有 5 个文件被更改,包括 100 次插入1 次删除
  1. 二进制
      .DS_Store
  2. 二进制
      src/.DS_Store
  3. 30
    1
      src/main/java/FizzBuzz.java
  4. 二进制
      src/test/.DS_Store
  5. 70
    0
      src/test/java/FizzBuzzTest.java

二进制
.DS_Store 查看文件


二进制
src/.DS_Store 查看文件


+ 30
- 1
src/main/java/FizzBuzz.java 查看文件

@@ -1,2 +1,31 @@
1
-public class FizzBuzz {
1
+class FizzBuzz {
2
+
3
+    public static String divisible (int x){
4
+        String str = "";
5
+        if (x % 3 == 0){
6
+            str += "Fizz";
7
+        } else {
8
+            str += str.format ("%d",x);
9
+        }
10
+        return str;
11
+    }
12
+
13
+    public static String divisible1 (int x){
14
+        String str = "";
15
+        if (x % 5 == 0){
16
+            str += "Buzz";
17
+        } else {
18
+             str +=  str.format ("%d",x);
19
+        }
20
+        return str;
21
+    }
22
+    public static String divisible2 (int x){
23
+        String str = "";
24
+        if ((x % 3 == 0) && (x % 5 == 0)){
25
+            str += "FizzBuzz";
26
+        }else {
27
+            str +=  str.format ("%d",x);
28
+        }
29
+        return str;
30
+    }
2 31
 }

二进制
src/test/.DS_Store 查看文件


+ 70
- 0
src/test/java/FizzBuzzTest.java 查看文件

@@ -1,2 +1,72 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
1 4
 public class FizzBuzzTest {
5
+    @Test
6
+    public void  FizzBuzz1() {
7
+
8
+        //Given
9
+        FizzBuzz buzz = new FizzBuzz();
10
+         int x = 12;
11
+         String expected = "Fizz";
12
+         //When
13
+        String actual = FizzBuzz.divisible(x);
14
+        Assert.assertEquals(expected,actual);
15
+    }
16
+    @Test
17
+    public void  FizzBuzzThree() {
18
+
19
+        //Given
20
+        FizzBuzz buzz = new FizzBuzz();
21
+        int x = 2;
22
+        String expected = "2";
23
+        //When
24
+        String actual = FizzBuzz.divisible(x);
25
+        Assert.assertEquals(expected,actual);
26
+    }
27
+    @Test
28
+    public void  FizzBuzz2() {
29
+
30
+        //Given
31
+        FizzBuzz buzz1 = new FizzBuzz();
32
+        int x = 20;
33
+        String expected = "Buzz";
34
+        //When
35
+        String actual = FizzBuzz.divisible1(x);
36
+        Assert.assertEquals(expected,actual);
37
+    }
38
+    @Test
39
+    public void  FizzBuzzFour() {
40
+
41
+        //Given
42
+        FizzBuzz buzz1 = new FizzBuzz();
43
+        int x = 3;
44
+        String expected = "3";
45
+        //When
46
+        String actual = FizzBuzz.divisible1(x);
47
+        Assert.assertEquals(expected,actual);
48
+    }
49
+
50
+    @ Test
51
+    public void FizzBuzz3 (){
52
+
53
+        //Given
54
+        FizzBuzz buzz2 = new FizzBuzz();
55
+        int x = 30;
56
+        String expected = "FizzBuzz";
57
+        //when
58
+        String actual = FizzBuzz.divisible2(x);
59
+        Assert.assertEquals(expected, actual);
60
+    }
61
+    @ Test
62
+    public void FizzBuzzFive (){
63
+
64
+        //Given
65
+        FizzBuzz buzz3 = new FizzBuzz();
66
+        int x = 8;
67
+        String expected = "8";
68
+        //when
69
+        String actual = FizzBuzz.divisible2(x);
70
+        Assert.assertEquals(expected, actual);
71
+    }
2 72
 }