Browse Source

Xcuello completed lab

Xzavia Cuello 6 years ago
parent
commit
6917d21642
2 changed files with 94 additions and 1 deletions
  1. 22
    0
      src/main/java/FizzBuzz.java
  2. 72
    1
      src/test/java/FizzBuzzTest.java

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

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

+ 72
- 1
src/test/java/FizzBuzzTest.java View File

@@ -1,2 +1,73 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
1 4
 public class FizzBuzzTest {
2
-}
5
+
6
+    FizzBuzz test = new FizzBuzz();
7
+
8
+    @Test
9
+    public void ofTest1(){
10
+        //Given
11
+
12
+        int testNumber = 1;
13
+
14
+
15
+        //When
16
+        String expectedOutput = "1";
17
+        String actualOutput = test.of(testNumber);
18
+
19
+
20
+        //Then
21
+        Assert.assertEquals(expectedOutput, actualOutput);
22
+
23
+
24
+    }
25
+
26
+    @Test
27
+    public void ofTest2() {
28
+        //Given
29
+        int testNumber = 9;
30
+
31
+
32
+        //When
33
+        String expectedOutput = "Fizz";
34
+        String actualOutput = test.of(testNumber);
35
+
36
+
37
+        //Then
38
+        Assert.assertEquals(expectedOutput, actualOutput);
39
+    }
40
+
41
+    @Test
42
+    public void ofTest3() {
43
+        //Given
44
+        int testNumber = 20;
45
+
46
+
47
+        //When
48
+        String expectedOutput = "Buzz";
49
+        String actualOutput = test.of(testNumber);
50
+
51
+
52
+
53
+        //Then
54
+        Assert.assertEquals(expectedOutput, actualOutput);
55
+
56
+    }
57
+        @Test
58
+        public void ofTest4 () {
59
+            //Given
60
+            int testNumber = 15;
61
+
62
+
63
+            //When
64
+            String expectedOutput = "FizzBuzz";
65
+            String actualOutput = test.of(testNumber);
66
+
67
+
68
+            //Then
69
+            Assert.assertEquals(expectedOutput, actualOutput);
70
+        }
71
+
72
+        }
73
+