瀏覽代碼

Clean up test

Nhu Nguyen 6 年之前
父節點
當前提交
00fb88dc91
共有 6 個文件被更改,包括 167 次插入152 次删除
  1. 9
    13
      NumberUtilities.java
  2. 66
    101
      NumberUtilitiesTest.java
  3. 19
    0
      TableUtilitiesTest.java
  4. 4
    3
      TriangleUtilities.java
  5. 49
    15
      TriangleUtilitiesTest.java
  6. 20
    20
      package.bluej

+ 9
- 13
NumberUtilities.java 查看文件

@@ -2,35 +2,31 @@
2 2
 
3 3
 
4 4
 public class NumberUtilities {
5
-    public static String getEvenNumbers(int start, int stop) {
5
+    
6
+    public static String getRange(int start) {
6 7
         return null;
7 8
     }
8
-
9
-
10
-    public static String getOddNumbers(int start, int stop) {
9
+    
10
+    public static String getRange(int start, int stop) {
11 11
         return null;
12 12
     }
13 13
 
14 14
 
15
-    public static String getSquareNumbers(int start, int stop, int step) {
16
-        return null;
17
-    }
18
-
19
-    public static String getRange(int start) {
15
+    public static String getRange(int start, int stop, int step) {
20 16
         return null;
21 17
     }
22
-
23
-    public static String getRange(int start, int stop) {
18
+    
19
+    public static String getEvenNumbers(int start, int stop) {
24 20
         return null;
25 21
     }
26 22
 
27 23
 
28
-    public static String getRange(int start, int stop, int step) {
24
+    public static String getOddNumbers(int start, int stop) {
29 25
         return null;
30 26
     }
31 27
 
32 28
 
33
-    public static String getExponentiations(int start, int stop, int step, int exponent) {
29
+    public static String getExponentiations(int start, int stop, int exponent) {
34 30
         return null;
35 31
     }
36 32
 }

+ 66
- 101
NumberUtilitiesTest.java 查看文件

@@ -4,11 +4,12 @@ import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6 6
 public class NumberUtilitiesTest {
7
+    
7 8
     @Test
8
-    public void testGetRange1A() {
9
+    public void testGetRangeForSmallRange() {
9 10
         // : Given
10
-        String expected = "0123456789";
11
-        int stop = 11;
11
+        String expected = "012";
12
+        int stop = 3;
12 13
 
13 14
         // : When
14 15
         String actual = NumberUtilities.getRange(stop);
@@ -16,12 +17,13 @@ public class NumberUtilitiesTest {
16 17
         // : Then
17 18
         Assert.assertEquals(expected, actual);
18 19
     }
19
-
20
+    
21
+    
20 22
     @Test
21
-    public void testGetRange2A() {
23
+    public void testGetRangeToTwoDigits() {
22 24
         // : Given
23
-        String expected = "01234";
24
-        int stop = 5;
25
+        String expected = "01234567891011";
26
+        int stop = 12;
25 27
 
26 28
         // : When
27 29
         String actual = NumberUtilities.getRange(stop);
@@ -31,35 +33,25 @@ public class NumberUtilitiesTest {
31 33
     }
32 34
 
33 35
     @Test
34
-    public void testGetRange3A() {
36
+    public void testGetRangeWithAStartNumber() {
35 37
         // : Given
36
-        String expected = "012345678910111213141516171819";
38
+        String expected = "5678910111213141516171819";
39
+        int start = 5;
37 40
         int stop = 20;
38 41
 
39 42
         // : When
40
-        String actual = NumberUtilities.getRange(stop);
43
+        String actual = NumberUtilities.getRange(start, stop);
41 44
 
42 45
         // : Then
43 46
         Assert.assertEquals(expected, actual);
44 47
     }
45 48
 
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57 49
     @Test
58
-    public void testGetRange1B() {
50
+    public void testGetRangeStartAt100() {
59 51
         // : Given
60
-        String expected = "5678910111213141516171819";
61
-        int start = 5;
62
-        int stop = 20;
52
+        String expected = "100101102103104105106107108109";
53
+        int start = 100;
54
+        int stop = 110;
63 55
 
64 56
         // : When
65 57
         String actual = NumberUtilities.getRange(start, stop);
@@ -68,16 +60,17 @@ public class NumberUtilitiesTest {
68 60
         Assert.assertEquals(expected, actual);
69 61
     }
70 62
 
71
-
63
+    
72 64
     @Test
73
-    public void testGetRange2B() {
65
+    public void testGetRangeWithOneStep() {
74 66
         // : Given
75
-        String expected = "101112131415161718192021222324";
76
-        int start = 10;
77
-        int stop = 25;
67
+        String expected = "012345678910111213141516171819";
68
+        int start = 0;
69
+        int stop = 20;
70
+        int step = 1;
78 71
 
79 72
         // : When
80
-        String actual = NumberUtilities.getRange(start, stop);
73
+        String actual = NumberUtilities.getRange(start, stop, step);
81 74
 
82 75
         // : Then
83 76
         Assert.assertEquals(expected, actual);
@@ -85,33 +78,22 @@ public class NumberUtilitiesTest {
85 78
 
86 79
 
87 80
     @Test
88
-    public void testGetRange3B() {
81
+    public void testGetRangeWithTwoStep() {
89 82
         // : Given
90
-        String expected = "100101103104105106107108109";
91
-        int start = 100;
92
-        int stop = 110;
83
+        String expected = "0246810";
84
+        int start = 0;
85
+        int stop = 11;
86
+        int step = 2;
93 87
 
94 88
         // : When
95
-        String actual = NumberUtilities.getRange(start, stop);
89
+        String actual = NumberUtilities.getRange(start, stop, step);
96 90
 
97 91
         // : Then
98 92
         Assert.assertEquals(expected, actual);
99 93
     }
100 94
 
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-    @Test
114
-    public void testGetRange1C() {
95
+        @Test
96
+    public void testGetRangeWithFiveStep() {
115 97
         // : Given
116 98
         String expected = "51015";
117 99
         int start = 5;
@@ -125,72 +107,56 @@ public class NumberUtilitiesTest {
125 107
         Assert.assertEquals(expected, actual);
126 108
     }
127 109
 
128
-
110
+    
129 111
     @Test
130
-    public void testGetRange2C() {
112
+    public void testGetEvenNumbersStartAndEndAtEven() {
131 113
         // : Given
132
-        String expected = "012345678910111213141516171819";
133
-        int start = 0;
114
+        String expected = "4681012141618";
115
+        int start = 4;
134 116
         int stop = 20;
135
-        int step = 1;
136 117
 
137 118
         // : When
138
-        String actual = NumberUtilities.getRange(start, stop, step);
119
+        String actual = NumberUtilities.getEvenNumbers(start, stop);
139 120
 
140 121
         // : Then
141 122
         Assert.assertEquals(expected, actual);
142 123
     }
143 124
 
144
-
125
+    
145 126
     @Test
146
-    public void testGetRange3C() {
127
+    public void testGetEvenNumbersStartAndEndAtOdd() {
147 128
         // : Given
148
-        String expected = "0246810";
149
-        int start = 0;
150
-        int stop = 11;
151
-        int step = 2;
129
+        String expected = "68101214161820";
130
+        int start = 5;
131
+        int stop = 21;
152 132
 
153 133
         // : When
154
-        String actual = NumberUtilities.getRange(start, stop, step);
134
+        String actual = NumberUtilities.getEvenNumbers(start, stop);
155 135
 
156 136
         // : Then
157 137
         Assert.assertEquals(expected, actual);
158 138
     }
159 139
 
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
140
+    
173 141
     @Test
174
-    public void testGetEvenNumbers() {
142
+    public void testGetOddNumbersStartAndEndAtOdd() {
175 143
         // : Given
176 144
         String expected = "5791113151719";
177 145
         int start = 5;
178
-        int stop = 20;
146
+        int stop = 21;
179 147
 
180 148
         // : When
181
-        String actual = NumberUtilities.getEvenNumbers(start, stop);
149
+        String actual = NumberUtilities.getOddNumbers(start, stop);
182 150
 
183 151
         // : Then
184 152
         Assert.assertEquals(expected, actual);
185 153
     }
186 154
 
187
-    @Test
188
-    public void testGetOddNumbers() {
155
+    public void testGetOddNumbersStartAndEndAtEven() {
189 156
         // : Given
190
-        String expected = "681012141618";
191
-        int start = 5;
192
-        int stop = 20;
193
-        int step = 5;
157
+        String expected = "579111315";
158
+        int start = 4;
159
+        int stop = 16;
194 160
 
195 161
         // : When
196 162
         String actual = NumberUtilities.getOddNumbers(start, stop);
@@ -200,35 +166,34 @@ public class NumberUtilitiesTest {
200 166
     }
201 167
 
202 168
 
203
-
204 169
     @Test
205
-    public void testGetSquareNumbers() {
170
+    public void testGetExponentiationNumbersForSquare() {
206 171
         // : Given
207
-        String expected = "25100225";
208
-        int start = 5;
209
-        int stop = 20;
210
-        int step = 5;
172
+        String expected = "4916253649";
173
+        int start = 2;
174
+        int stop = 7;
175
+        int exponent = 2;
211 176
 
212 177
         // : When
213
-        String actual = NumberUtilities.getSquareNumbers(start, stop, step);
178
+        String actual = NumberUtilities.getExponentiations(start, stop, exponent);
214 179
 
215 180
         // : Then
216 181
         Assert.assertEquals(expected, actual);
217 182
     }
218
-
219
-
183
+    
184
+    
220 185
     @Test
221
-    public void testGetExponentiationNumbers() {
186
+    public void testGetExponentiationNumbersForCube() {
222 187
         // : Given
223
-        String expected = "25100225";
224
-        int start = 5;
225
-        int stop = 20;
226
-        int step = 5;
227
-        int exponent = 2;
188
+        String expected = "182764";
189
+        int start = 1;
190
+        int stop = 4;
191
+        int exponent = 3;
228 192
 
229 193
         // : When
230
-        String actual = NumberUtilities.getExponentiations(start, stop, step, exponent);
194
+        String actual = NumberUtilities.getExponentiations(start, stop, exponent);
231 195
 
196
+        // : Then
232 197
         Assert.assertEquals(expected, actual);
233 198
     }
234 199
 }

+ 19
- 0
TableUtilitiesTest.java 查看文件

@@ -7,6 +7,25 @@ import org.junit.Test;
7 7
  * Created by leon on 1/31/18.
8 8
  */
9 9
 public class TableUtilitiesTest {
10
+   
11
+    @Test
12
+    public void testGetMulplicationTable_forOne(){
13
+        String expected = "  1 |\n";
14
+
15
+        String actual = TableUtilities.getMultiplicationTable(1);
16
+        Assert.assertEquals(expected, actual);
17
+    }
18
+    
19
+        @Test
20
+    public void testGetMulplicationTable_forTwo(){
21
+        String expected = "  1 |  2 |\n" +
22
+                          "  2 |  4 |\n";
23
+
24
+        String actual = TableUtilities.getMultiplicationTable(2);
25
+        Assert.assertEquals(expected, actual);
26
+    }
27
+    
28
+    
10 29
     @Test
11 30
     public void testGetLargeMultiplicationTable() {
12 31
         String expected =

+ 4
- 3
TriangleUtilities.java 查看文件

@@ -2,14 +2,15 @@
2 2
 
3 3
 public class TriangleUtilities {
4 4
 
5
-    public static String getTriangle(int numberOfRows) {
5
+    public static String getRow(int numberOfStars) {
6 6
         return null;
7 7
     }
8
-
9
-    public static String getRow(int numberOfStars) {
8
+    
9
+    public static String getTriangle(int numberOfRows) {
10 10
         return null;
11 11
     }
12 12
 
13
+
13 14
     public static String getSmallTriangle() {
14 15
         return null;
15 16
     }

+ 49
- 15
TriangleUtilitiesTest.java 查看文件

@@ -7,18 +7,62 @@ import org.junit.Test;
7 7
 public class TriangleUtilitiesTest {
8 8
 
9 9
     @Test
10
-    public void getRow() {
10
+    public void testGetRow_ForSmallWidth(){
11
+        //Given
12
+        String expected = "*";
13
+        int width = 1;
14
+        
15
+        //When
16
+        String actual = TriangleUtilities.getRow(width);
17
+        
18
+        //Then
19
+        Assert.assertEquals(expected, actual);
20
+    }
21
+    
22
+    @Test
23
+    public void testGetRow_ForBigWidth() {
24
+        //Given
11 25
         String expected = "********************";
12 26
         int width = 20;
27
+        
28
+        //When
13 29
         String actual = TriangleUtilities.getRow(width);
30
+        
31
+        //Then
14 32
         Assert.assertEquals(expected, actual);
15 33
     }
16 34
 
35
+    @Test
36
+    public void testGetTriangle_ForOneRow() {
37
+        // Given
38
+        String expected = "*\n";
17 39
 
40
+        // When
41
+        String actual = TriangleUtilities.getTriangle(1);
42
+        
43
+        // Then
44
+        Assert.assertEquals(expected, actual);
45
+    }
46
+    
18 47
     @Test
19
-    public void getTriangleTest1() {
48
+    public void testGetTriangle_ForSmallTriangle() {
49
+        // Given
20 50
         String expected =
21
-                "*\n" +
51
+                        "*\n" +
52
+                        "**\n" +
53
+                        "***\n";
54
+
55
+        // When                
56
+        String actual = TriangleUtilities.getTriangle(3);
57
+        
58
+        // Then
59
+        Assert.assertEquals(expected, actual);
60
+    }
61
+    
62
+    @Test
63
+    public void testGetTriangle_ForBigTriangle() {
64
+        String expected =
65
+                        "*\n" +
22 66
                         "**\n" +
23 67
                         "***\n" +
24 68
                         "****\n" +
@@ -26,23 +70,13 @@ public class TriangleUtilitiesTest {
26 70
                         "******\n" +
27 71
                         "*******\n" +
28 72
                         "********\n" +
29
-                        "*********\n";
73
+                        "*********\n" +
74
+                        "**********\n";
30 75
         String actual = TriangleUtilities.getTriangle(10);
31 76
         Assert.assertEquals(expected, actual);
32 77
     }
33 78
 
34 79
     @Test
35
-    public void getTriangleTest2() {
36
-        String expected =
37
-                "*\n" +
38
-                        "**\n" +
39
-                        "***\n" +
40
-                        "****\n";
41
-        String actual = TriangleUtilities.getTriangle(5);
42
-        Assert.assertEquals(expected, actual);
43
-    }
44
-
45
-    @Test
46 80
     public void testGetLargeTriangle() {
47 81
         String expected =
48 82
                 "*\n" +

+ 20
- 20
package.bluej 查看文件

@@ -1,27 +1,27 @@
1 1
 #BlueJ package file
2
-dependency1.from=TableUtilitiesTest
3
-dependency1.to=TableUtilities
2
+dependency1.from=NumberUtilitiesTest
3
+dependency1.to=NumberUtilities
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=NumberUtilitiesTest
6
-dependency2.to=NumberUtilities
5
+dependency2.from=TriangleUtilitiesTest
6
+dependency2.to=TriangleUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=TriangleUtilitiesTest
9
-dependency3.to=TriangleUtilities
8
+dependency3.from=TableUtilitiesTest
9
+dependency3.to=TableUtilities
10 10
 dependency3.type=UsesDependency
11 11
 editor.fx.0.height=722
12 12
 editor.fx.0.width=800
13
-editor.fx.0.x=640
14
-editor.fx.0.y=23
13
+editor.fx.0.x=537
14
+editor.fx.0.y=28
15 15
 objectbench.height=164
16
-objectbench.width=595
16
+objectbench.width=484
17 17
 package.divider.horizontal=0.6
18 18
 package.divider.vertical=0.7560627674750356
19 19
 package.editor.height=523
20
-package.editor.width=493
20
+package.editor.width=382
21 21
 package.editor.x=20
22 22
 package.editor.y=57
23 23
 package.frame.height=759
24
-package.frame.width=619
24
+package.frame.width=508
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true
@@ -62,18 +62,18 @@ target4.type=ClassTarget
62 62
 target4.width=120
63 63
 target4.x=80
64 64
 target4.y=70
65
-target5.association=TriangleUtilitiesTest
66 65
 target5.height=50
67
-target5.name=TriangleUtilities
66
+target5.name=NumberUtilitiesTest
68 67
 target5.showInterface=false
69
-target5.type=ClassTarget
68
+target5.type=UnitTestTargetJunit4
70 69
 target5.width=120
71
-target5.x=70
72
-target5.y=190
70
+target5.x=110
71
+target5.y=40
72
+target6.association=TriangleUtilitiesTest
73 73
 target6.height=50
74
-target6.name=NumberUtilitiesTest
74
+target6.name=TriangleUtilities
75 75
 target6.showInterface=false
76
-target6.type=UnitTestTargetJunit4
76
+target6.type=ClassTarget
77 77
 target6.width=120
78
-target6.x=110
79
-target6.y=40
78
+target6.x=70
79
+target6.y=190