소스 검색

Finished fizzBuzz lab

Jonathan Hinds 6 년 전
부모
커밋
2bc760ffe0
2개의 변경된 파일114개의 추가작업 그리고 0개의 파일을 삭제
  1. 21
    0
      src/main/java/FizzBuzz.java
  2. 93
    0
      src/test/java/FizzBuzzTest.java

+ 21
- 0
src/main/java/FizzBuzz.java 파일 보기

@@ -1,2 +1,23 @@
1 1
 public class FizzBuzz {
2
+
3
+    public static String of(int testNumber) {
4
+
5
+        String result = "";
6
+
7
+        if(testNumber % 3 == 0)
8
+        {
9
+            result += "Fizz";
10
+        }
11
+
12
+        if(testNumber % 5 == 0){
13
+            result += "Buzz";
14
+        }
15
+
16
+        if(!(testNumber % 5 == 0) && !(testNumber % 3 == 0))
17
+        {
18
+            result = String.valueOf(testNumber);
19
+        }
20
+
21
+        return result;
22
+    }
2 23
 }

+ 93
- 0
src/test/java/FizzBuzzTest.java 파일 보기

@@ -1,2 +1,95 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
1 4
 public class FizzBuzzTest {
5
+
6
+    @Test
7
+    public void test01()
8
+    {
9
+        //GIVEN
10
+        String expected = "Fizz";
11
+        String actual = "";
12
+        int testNumber = 3;
13
+
14
+        //WEHN
15
+        actual = FizzBuzz.of(testNumber);
16
+
17
+        //RESULT
18
+        Assert.assertEquals(expected, actual);
19
+    }
20
+
21
+    @Test
22
+    public void test02()
23
+    {
24
+        //GIVEN
25
+        String expected = "4";
26
+        String actual = "";
27
+        int testNumber = 4;
28
+
29
+        //WEHN
30
+        actual = FizzBuzz.of(testNumber);
31
+
32
+        //RESULT
33
+        Assert.assertEquals(expected, actual);
34
+    }
35
+
36
+    @Test
37
+    public void test03()
38
+    {
39
+        //GIVEN
40
+        String expected = "Buzz";
41
+        String actual = "";
42
+        int testNumber = 5;
43
+
44
+        //WEHN
45
+        actual = FizzBuzz.of(testNumber);
46
+
47
+        //RESULT
48
+        Assert.assertEquals(expected, actual);
49
+    }
50
+
51
+    @Test
52
+    public void test04()
53
+    {
54
+        //GIVEN
55
+        String expected = "4";
56
+        String actual = "";
57
+        int testNumber = 4;
58
+
59
+        //WEHN
60
+        actual = FizzBuzz.of(testNumber);
61
+
62
+        //RESULT
63
+        Assert.assertEquals(expected, actual);
64
+    }
65
+
66
+    @Test
67
+    public void test05()
68
+    {
69
+        //GIVEN
70
+        String expected = "FizzBuzz";
71
+        String actual = "";
72
+        int testNumber = 15;
73
+
74
+        //WEHN
75
+        actual = FizzBuzz.of(testNumber);
76
+
77
+        //RESULT
78
+        Assert.assertEquals(expected, actual);
79
+    }
80
+
81
+    @Test
82
+    public void test06()
83
+    {
84
+        //GIVEN
85
+        String expected = "4";
86
+        String actual = "";
87
+        int testNumber = 4;
88
+
89
+        //WEHN
90
+        actual = FizzBuzz.of(testNumber);
91
+
92
+        //RESULT
93
+        Assert.assertEquals(expected, actual);
94
+    }
2 95
 }