소스 검색

my FizzBuzz

Simran Bhutani 6 년 전
부모
커밋
0be8a64c78
4개의 변경된 파일175개의 추가작업 그리고 0개의 파일을 삭제
  1. BIN
      .DS_Store
  2. BIN
      src/.DS_Store
  3. 30
    0
      src/main/java/FizzBuzz.java
  4. 145
    0
      src/test/java/FizzBuzzTest.java

BIN
.DS_Store 파일 보기


BIN
src/.DS_Store 파일 보기


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

@@ -1,2 +1,32 @@
1 1
 public class FizzBuzz {
2
+
3
+    //public static void main(String[] args) {
4
+        public static String divisibleByThree ( int number){
5
+            if ((number %3)== 0) {
6
+
7
+                return "Fizz";
8
+            }
9
+            else
10
+                {
11
+                    return String.valueOf(number);
12
+                }
13
+        }
14
+        public static String divisibleByFive ( int number){
15
+            if((number%5)==0) {
16
+                return "Buzz";
17
+            }
18
+            else
19
+            {
20
+                return String.valueOf(number);
21
+            }
22
+        }
23
+        public static String divisibleByFifteen ( int number){
24
+            if((number%15)==0) {
25
+                return "FizzBuzz";
26
+            }
27
+            else
28
+            {
29
+                return String.valueOf(number);
30
+            }
31
+        }
2 32
 }

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

@@ -1,2 +1,147 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
1 4
 public class FizzBuzzTest {
5
+
6
+    @Test
7
+    public void testThree(){
8
+        //Given: Setup
9
+        int number=3;
10
+        String expectedOutput= "Fizz";
11
+
12
+        //when (invoke the method under test)
13
+        String actualOutput=FizzBuzz.divisibleByThree(number);
14
+
15
+        //Then
16
+        Assert.assertEquals(expectedOutput, actualOutput);
17
+    }
18
+
19
+    @Test
20
+    public void testThree4(){
21
+        //Given: Setup
22
+        int number=4;
23
+        String expectedOutput= "4";
24
+
25
+        //when (invoke the method under test)
26
+        String actualOutput=FizzBuzz.divisibleByThree(number);
27
+
28
+        //Then
29
+        Assert.assertEquals(expectedOutput, actualOutput);
30
+    }
31
+
32
+    @Test
33
+    public void testThree6(){
34
+        //Given: Setup
35
+        int number=6;
36
+        String expectedOutput= "Fizz";
37
+
38
+        //when (invoke the method under test)
39
+        String actualOutput=FizzBuzz.divisibleByThree(number);
40
+
41
+        //Then
42
+        Assert.assertEquals(expectedOutput, actualOutput);
43
+    }
44
+
45
+    @Test
46
+    public void testThree8(){
47
+        //Given: Setup
48
+        int number=8;
49
+        String expectedOutput= "8";
50
+
51
+        //when (invoke the method under test)
52
+        String actualOutput=FizzBuzz.divisibleByThree(number);
53
+
54
+        //Then
55
+        Assert.assertEquals(expectedOutput, actualOutput);
56
+    }
57
+
58
+    @Test
59
+    public void testFive(){
60
+        //Given Setup
61
+        int number=5;
62
+        String expectedOutput="Buzz";
63
+
64
+        //when
65
+        String actualOutput=FizzBuzz.divisibleByFive(number);
66
+
67
+        //then
68
+        Assert.assertEquals(expectedOutput, actualOutput);
69
+    }
70
+
71
+    @Test
72
+    public void testFive2(){
73
+        //Given Setup
74
+        int number=2;
75
+        String expectedOutput="2";
76
+
77
+        //when
78
+        String actualOutput=FizzBuzz.divisibleByFive(number);
79
+
80
+        //then
81
+        Assert.assertEquals(expectedOutput, actualOutput);
82
+    }
83
+
84
+    @Test
85
+    public void testFive7(){
86
+        //Given Setup
87
+        int number=7;
88
+        String expectedOutput="7";
89
+
90
+        //when
91
+        String actualOutput=FizzBuzz.divisibleByFive(number);
92
+
93
+        //then
94
+        Assert.assertEquals(expectedOutput, actualOutput);
95
+    }
96
+
97
+    @Test
98
+    public void testFive10(){
99
+        //Given Setup
100
+        int number=10;
101
+        String expectedOutput="Buzz";
102
+
103
+        //when
104
+        String actualOutput=FizzBuzz.divisibleByFive(number);
105
+
106
+        //then
107
+        Assert.assertEquals(expectedOutput, actualOutput);
108
+    }
109
+
110
+
111
+    @Test
112
+    public void testFifteen(){
113
+        //given
114
+        int number=15;
115
+        String expectedOutput= "FizzBuzz";
116
+
117
+        //when
118
+
119
+        String actualOutput=FizzBuzz.divisibleByFifteen(number);
120
+
121
+        //then
122
+        Assert.assertEquals(expectedOutput, actualOutput);
123
+
124
+
125
+    }
126
+
127
+
128
+    @Test
129
+    public void testFifteen18(){
130
+        //given
131
+        int number=18;
132
+        String expectedOutput= "18";
133
+
134
+        //when
135
+
136
+        String actualOutput=FizzBuzz.divisibleByFifteen(number);
137
+
138
+        //then
139
+        Assert.assertEquals(expectedOutput, actualOutput);
140
+
141
+
142
+    }
143
+
144
+    
2 145
 }
146
+
147
+