Selaa lähdekoodia

tests written code coded

Jacob Andersen 6 vuotta sitten
vanhempi
commit
d259c68827
2 muutettua tiedostoa jossa 158 lisäystä ja 1 poistoa
  1. 13
    0
      src/main/java/FizzBuzz.java
  2. 145
    1
      src/test/java/FizzBuzzTest.java

+ 13
- 0
src/main/java/FizzBuzz.java Näytä tiedosto

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

+ 145
- 1
src/test/java/FizzBuzzTest.java Näytä tiedosto

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