Bladeren bron

Completed FizzBuzz w/partner

Chaitali Patel 6 jaren geleden
bovenliggende
commit
508271216d
2 gewijzigde bestanden met toevoegingen van 91 en 1 verwijderingen
  1. 32
    1
      src/main/java/FizzBuzz.java
  2. 59
    0
      src/test/java/FizzBuzzTest.java

+ 32
- 1
src/main/java/FizzBuzz.java Bestand weergeven

@@ -1,2 +1,33 @@
1 1
 public class FizzBuzz {
2
-}
2
+      //String str = "";
3
+
4
+    public static String divThree(int num) {
5
+        String str = "";
6
+        if (num % 3 == 0) {
7
+            str += "Fizz";
8
+        } else {
9
+            str = str.format("%d", num);
10
+        }
11
+        return str;
12
+    }
13
+
14
+        public static String divFive(int num) {
15
+            String str = "";
16
+            if (num % 5 == 0) {
17
+                str += "Buzz";
18
+            } else {
19
+                str = str.format("%d", num);
20
+            }
21
+            return str;
22
+    }
23
+            public static String divThreeFive(int num){
24
+                String str = "";
25
+                if (num % 3 == 0 && num % 5 == 0) {
26
+                    str += "FizzBuzz";
27
+                } else {
28
+                    str = str.format("%d", num);
29
+            }
30
+                return str;
31
+        }
32
+
33
+    }

+ 59
- 0
src/test/java/FizzBuzzTest.java Bestand weergeven

@@ -1,2 +1,61 @@
1
+import org.junit.Assert;
2
+import org.junit.Test;
3
+
1 4
 public class FizzBuzzTest {
5
+
6
+    @Test
7
+    public void divThree() {
8
+        FizzBuzz fizz = new FizzBuzz();
9
+        int num = 9;
10
+        String Expected = "Fizz";
11
+
12
+        String actual = FizzBuzz.divThree(num);
13
+        Assert.assertEquals(Expected,actual);
14
+    }
15
+    @Test
16
+    public void divThree2() {
17
+        FizzBuzz fizz = new FizzBuzz();
18
+        int num = 2;
19
+        String Expected = "2";
20
+
21
+        String actual = FizzBuzz.divThree(num);
22
+        Assert.assertEquals(Expected,actual);
23
+    }
24
+    @Test
25
+    public void divFive() {
26
+        FizzBuzz buzz = new FizzBuzz();
27
+        int num = 10;
28
+        String Expected = "Buzz";
29
+
30
+        String actual = FizzBuzz.divFive(num);
31
+        Assert.assertEquals(Expected,actual);
32
+    }
33
+    @Test
34
+    public void divFive2() {
35
+        FizzBuzz buzz = new FizzBuzz();
36
+        int num = 3;
37
+        String Expected = "3";
38
+
39
+        String actual = FizzBuzz.divFive(num);
40
+        Assert.assertEquals(Expected,actual);
41
+    }
42
+    @Test
43
+    public void divThreeFive() {
44
+        FizzBuzz fizzBuzz = new FizzBuzz();
45
+        int num = 30;
46
+        String Expected = "FizzBuzz";
47
+
48
+        String actual = FizzBuzz.divThreeFive(num);
49
+        Assert.assertEquals(Expected,actual);
50
+    }
51
+    @Test
52
+    public void divThreeFive2() {
53
+        FizzBuzz fizzBuzz = new FizzBuzz();
54
+        int num = 2;
55
+        String Expected = "2";
56
+
57
+        String actual = FizzBuzz.divThreeFive(num);
58
+        Assert.assertEquals(Expected,actual);
59
+    }
60
+
2 61
 }