浏览代码

All tests pased

Jose Bedolla 6 年前
父节点
当前提交
2f5c1dd407
共有 3 个文件被更改,包括 132 次插入0 次删除
  1. 12
    0
      pom.xml
  2. 40
    0
      src/main/java/FizzBuzz.java
  3. 80
    0
      src/test/java/FizzBuzzTest.java

+ 12
- 0
pom.xml 查看文件

@@ -31,6 +31,18 @@
31 31
             <version>4.12</version>
32 32
             <scope>test</scope>
33 33
         </dependency>
34
+        <dependency>
35
+            <groupId>org.junit.jupiter</groupId>
36
+            <artifactId>junit-jupiter-api</artifactId>
37
+            <version>RELEASE</version>
38
+            <scope>compile</scope>
39
+        </dependency>
40
+        <dependency>
41
+            <groupId>org.testng</groupId>
42
+            <artifactId>testng</artifactId>
43
+            <version>RELEASE</version>
44
+            <scope>compile</scope>
45
+        </dependency>
34 46
     </dependencies>
35 47
 
36 48
 </project>

+ 40
- 0
src/main/java/FizzBuzz.java 查看文件

@@ -1,2 +1,42 @@
1
+
1 2
 public class FizzBuzz {
3
+
4
+    public FizzBuzz()
5
+    {
6
+
7
+    }
8
+
9
+    public String FizzBuzzOf(int first) {
10
+
11
+        if((first % 3 ==0)&&(first %5 == 0))
12
+        {
13
+            return "FizzBuzz";
14
+        }
15
+        return String.valueOf(first); // make test for this
16
+    }
17
+
18
+    public String Buzz(int first) {
19
+
20
+        if(first %5 == 0)
21
+        {
22
+            return "Buzz";
23
+        }
24
+        return String.valueOf(first);
25
+
26
+    }
27
+
28
+    public String Fizz(int first) {
29
+
30
+        if(first % 3 ==0)
31
+        {
32
+            return "Fizz";
33
+        }
34
+
35
+            return String.valueOf(first);
36
+    }
37
+
38
+
39
+
40
+
41
+
2 42
 }

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

@@ -1,2 +1,82 @@
1
+import org.junit.Test;
2
+import org.junit.Assert;
3
+
4
+
1 5
 public class FizzBuzzTest {
6
+
7
+    public FizzBuzzTest() {
8
+    }
9
+    FizzBuzz FbObject = new FizzBuzz();
10
+
11
+    @Test
12
+    public void testFor3()
13
+    {
14
+
15
+        int number = 3;
16
+        String expected = "Fizz";
17
+     //when
18
+        String actual = FbObject.Fizz(number);
19
+      //then
20
+        Assert.assertEquals(expected, actual);
21
+
22
+    }
23
+
24
+    @Test
25
+    public void testFor3a()
26
+    {
27
+        int number = 2;
28
+        String expected = "2";
29
+        //when
30
+        String actual = FbObject.Fizz(number);
31
+        //then
32
+        Assert.assertEquals(expected, actual);
33
+
34
+    }
35
+
36
+    @Test
37
+    public void testFor5()
38
+    {
39
+        int number = 5;
40
+        String expected = "Buzz";
41
+        //when
42
+        String actual = FbObject.Buzz(number);
43
+        //then
44
+        Assert.assertEquals(expected, actual);
45
+    }
46
+
47
+    @Test
48
+    public void testFor5a()
49
+    {
50
+        int number = 23;
51
+        String expected = "23";
52
+        //when
53
+        String actual = FbObject.Buzz(number);
54
+        //then
55
+        Assert.assertEquals(expected, actual);
56
+
57
+    }
58
+
59
+    @Test
60
+    public void testBoth()
61
+    {
62
+        int number = 15;
63
+        String expected = "FizzBuzz";
64
+        //when
65
+        String actual = FbObject.FizzBuzzOf(number);
66
+        //then
67
+        Assert.assertEquals(expected,actual);
68
+    }
69
+
70
+    @Test
71
+    public void testBothA()
72
+    {
73
+        int number = 91;
74
+        String expected = "91";
75
+        //when
76
+        String actual = FbObject.FizzBuzzOf(number);
77
+        //then
78
+        Assert.assertEquals(expected, actual);
79
+
80
+    }
81
+
2 82
 }