Bläddra i källkod

added more test for math util

Nhu Nguyen 6 år sedan
förälder
incheckning
f6bb78f11d
3 ändrade filer med 57 tillägg och 41 borttagningar
  1. 43
    41
      BonusTest.java
  2. 4
    0
      MathUtilities.java
  3. 10
    0
      MathUtilitiesTest.java

+ 43
- 41
BonusTest.java Visa fil

@@ -15,6 +15,48 @@ public class BonusTest
15 15
     }
16 16
     
17 17
     @Test
18
+    public void testFactorialBase(){
19
+        //Given
20
+        int number = 1;
21
+        int expected = 1;
22
+        
23
+        //When
24
+        int actual = bonus.factorial(number);
25
+        
26
+        //Then
27
+        assertEquals(expected, actual);
28
+        
29
+    }
30
+        
31
+    @Test
32
+    public void testFactorialOfSmallNumber(){
33
+        //Given
34
+        int number = 3;
35
+        int expected = 6;
36
+        
37
+        //When
38
+        int actual = bonus.factorial(number);
39
+        
40
+        //Then
41
+        assertEquals(expected, actual);
42
+        
43
+    }
44
+    
45
+    @Test
46
+    public void testFactorialOfBigNumber(){
47
+        //Given
48
+        int number = 6;
49
+        int expected = 720;
50
+        
51
+        //When
52
+        int actual = bonus.factorial(number);
53
+        
54
+        //Then
55
+        assertEquals(expected, actual);
56
+        
57
+    }
58
+    
59
+    @Test
18 60
     public void testAcronymBasic() {
19 61
         //Given
20 62
         String phrase = "Portable Network Graphics";
@@ -96,45 +138,5 @@ public class BonusTest
96 138
     }
97 139
     
98 140
     
99
-    @Test
100
-    public void testFactorialOf1(){
101
-        //Given
102
-        int number = 1;
103
-        int expected = 1;
104
-        
105
-        //When
106
-        int actual = bonus.factorial(number);
107
-        
108
-        //Then
109
-        assertEquals(expected, actual);
110
-        
111
-    }
112
-        
113
-    @Test
114
-    public void testFactorialOfSmallNumber(){
115
-        //Given
116
-        int number = 3;
117
-        int expected = 6;
118
-        
119
-        //When
120
-        int actual = bonus.factorial(number);
121
-        
122
-        //Then
123
-        assertEquals(expected, actual);
124
-        
125
-    }
126
-    
127
-    @Test
128
-    public void testFactorialOfBigNumber(){
129
-        //Given
130
-        int number = 6;
131
-        int expected = 720;
132
-        
133
-        //When
134
-        int actual = bonus.factorial(number);
135
-        
136
-        //Then
137
-        assertEquals(expected, actual);
138
-        
139
-    }
141
+
140 142
 }

+ 4
- 0
MathUtilities.java Visa fil

@@ -11,5 +11,9 @@ public class MathUtilities{
11 11
     public double half(int number) {
12 12
         return -1;
13 13
     }
14
+    
15
+    public boolean isOdd(int number){
16
+        return false;
17
+    }
14 18
 
15 19
 }

+ 10
- 0
MathUtilitiesTest.java Visa fil

@@ -62,4 +62,14 @@ public class MathUtilitiesTest
62 62
         //Then
63 63
         assertEquals(expected, actual, DELTA);
64 64
     }
65
+    
66
+    @Test
67
+    public void testIsOdd_forOddNumber(){
68
+        assertTrue(utilities.isOdd(7));
69
+    }
70
+    
71
+    @Test
72
+    public void testIsOdd_forEvenNumber(){
73
+        assertFalse(utilities.isOdd(12));
74
+    }
65 75
 }