Browse Source

{FizzBuzz with Thulasi}

Jacqueline Joson 6 years ago
parent
commit
ff6f79b88b
2 changed files with 68 additions and 1 deletions
  1. 16
    0
      src/main/java/FizzBuzz.java
  2. 52
    1
      src/test/java/FizzBuzzTest.java

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

@@ -1,2 +1,18 @@
1
+import java.util.Scanner;
2
+
1 3
 public class FizzBuzz {
4
+
5
+    Scanner user = new Scanner(System.in);
6
+    int n = user.nextInt();
7
+    public static String of(int n) {
8
+        if (n%15 == 0) {
9
+            return "FizzBuzz";
10
+        } else if (n%3 == 0) {
11
+            return "Fizz";
12
+        } else if (n%5 == 0) {
13
+            return "Buzz";
14
+        } else {
15
+           return Integer.toString(n);
16
+        }
17
+    }
2 18
 }

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

@@ -1,2 +1,53 @@
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
+        //FizzBuzz fb = new FizzBuzz();
9
+        int number = 3;
10
+
11
+
12
+        String expected = "Fizz";
13
+
14
+        String actual = FizzBuzz.of(number);
15
+        Assert.assertEquals(expected,actual);
16
+    }
17
+
18
+    @Test
19
+    public void buzzTest() {
20
+        //FizzBuzz fb = new FizzBuzz();
21
+        int number = 5;
22
+
23
+
24
+        String expected = "Buzz";
25
+
26
+        String actual = FizzBuzz.of(number);
27
+        Assert.assertEquals(expected,actual);
28
+    }
29
+
30
+    @Test
31
+    public void fizzBuzzTest() {
32
+        //FizzBuzz fb = new FizzBuzz();
33
+        int number = 15;
34
+
35
+
36
+        String expected = "FizzBuzz";
37
+
38
+        String actual = FizzBuzz.of(number);
39
+        Assert.assertEquals(expected,actual);
40
+    }
41
+
42
+    @Test
43
+    public void numberTest() {
44
+        //FizzBuzz fb = new FizzBuzz();
45
+        int number = 2;
46
+
47
+
48
+        String expected = Integer.toString(number);
49
+
50
+        String actual = FizzBuzz.of(number);
51
+        Assert.assertEquals(expected,actual);
52
+    }
53
+}