Sfoglia il codice sorgente

Nick Satinover FizzBuzz-TDD

Nicholas Satinover 6 anni fa
parent
commit
92a343dffc
3 ha cambiato i file con 86 aggiunte e 0 eliminazioni
  1. BIN
      .DS_Store
  2. 13
    0
      src/main/java/FizzBuzz.java
  3. 73
    0
      src/test/java/FizzBuzzTest.java

BIN
.DS_Store Vedi File


+ 13
- 0
src/main/java/FizzBuzz.java Vedi File

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

+ 73
- 0
src/test/java/FizzBuzzTest.java Vedi File

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