Bläddra i källkod

All test written and passed.

Lauren Green 6 år sedan
förälder
incheckning
ff473ca583
2 ändrade filer med 70 tillägg och 0 borttagningar
  1. 13
    0
      src/main/java/FizzBuzz.java
  2. 57
    0
      src/test/java/FizzBuzzTest.java

+ 13
- 0
src/main/java/FizzBuzz.java Visa fil

@@ -1,2 +1,15 @@
1 1
 public class FizzBuzz {
2
+    public static String of(int number) {
3
+
4
+        if ((number % 3 == 0) && (number % 5 == 0)) {
5
+            return "FizzBuzz";
6
+        } else if (number % 3 == 0) {
7
+            return "Fizz";
8
+        } else if (number % 5 == 0) {
9
+            return "Buzz";
10
+        } else {
11
+            return Integer.toString(number);
12
+        }
13
+
14
+    }
2 15
 }

+ 57
- 0
src/test/java/FizzBuzzTest.java Visa fil

@@ -1,2 +1,59 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
1 4
 public class FizzBuzzTest {
5
+
6
+    @Test
7
+    public void fizzTest() {
8
+        //Given
9
+        int number = 12;
10
+        String expectedOutput = "Fizz";
11
+
12
+        //When
13
+        String actualOutput = FizzBuzz.of(number);
14
+
15
+        //Then
16
+        Assert.assertEquals(expectedOutput, actualOutput);
17
+    }
18
+
19
+    @Test
20
+    public void buzzTest() {
21
+        //Given
22
+        int number = 20;
23
+        String expectedOutput = "Buzz";
24
+
25
+        //When
26
+        String actualOutput = FizzBuzz.of(number);
27
+
28
+        //Then
29
+        Assert.assertEquals(expectedOutput, actualOutput);
30
+    }
31
+
32
+    @Test
33
+    public void fizzbuzzTest() {
34
+        //Given
35
+        int number = 15;
36
+        String expectedOutput = "FizzBuzz";
37
+
38
+        //When
39
+        String actualOutput = FizzBuzz.of(number);
40
+
41
+        //Then
42
+        Assert.assertEquals(expectedOutput, actualOutput);
43
+    }
44
+
45
+    @Test
46
+    public void elseTest() {
47
+        //Given
48
+        int number = 22;
49
+        String expectedOutput = "22";
50
+
51
+        //When
52
+        String actualOutput = FizzBuzz.of(number);
53
+
54
+        //Then
55
+        Assert.assertEquals(expectedOutput, actualOutput);
56
+    }
57
+
58
+
2 59
 }