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
 
2
 
3
 
3
 
4
 public class NumberUtilities {
4
 public class NumberUtilities {
5
-    public static String getEvenNumbers(int start, int stop) {
5
+    
6
+    public static String getRange(int start) {
6
         return null;
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
         return null;
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
         return null;
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
         return null;
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
         return null;
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
         return null;
30
         return null;
35
     }
31
     }
36
 }
32
 }

+ 66
- 101
NumberUtilitiesTest.java Целия файл

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

+ 19
- 0
TableUtilitiesTest.java Целия файл

7
  * Created by leon on 1/31/18.
7
  * Created by leon on 1/31/18.
8
  */
8
  */
9
 public class TableUtilitiesTest {
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
     @Test
29
     @Test
11
     public void testGetLargeMultiplicationTable() {
30
     public void testGetLargeMultiplicationTable() {
12
         String expected =
31
         String expected =

+ 4
- 3
TriangleUtilities.java Целия файл

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

+ 49
- 15
TriangleUtilitiesTest.java Целия файл

7
 public class TriangleUtilitiesTest {
7
 public class TriangleUtilitiesTest {
8
 
8
 
9
     @Test
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
         String expected = "********************";
25
         String expected = "********************";
12
         int width = 20;
26
         int width = 20;
27
+        
28
+        //When
13
         String actual = TriangleUtilities.getRow(width);
29
         String actual = TriangleUtilities.getRow(width);
30
+        
31
+        //Then
14
         Assert.assertEquals(expected, actual);
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
     @Test
47
     @Test
19
-    public void getTriangleTest1() {
48
+    public void testGetTriangle_ForSmallTriangle() {
49
+        // Given
20
         String expected =
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
                         "**\n" +
66
                         "**\n" +
23
                         "***\n" +
67
                         "***\n" +
24
                         "****\n" +
68
                         "****\n" +
26
                         "******\n" +
70
                         "******\n" +
27
                         "*******\n" +
71
                         "*******\n" +
28
                         "********\n" +
72
                         "********\n" +
29
-                        "*********\n";
73
+                        "*********\n" +
74
+                        "**********\n";
30
         String actual = TriangleUtilities.getTriangle(10);
75
         String actual = TriangleUtilities.getTriangle(10);
31
         Assert.assertEquals(expected, actual);
76
         Assert.assertEquals(expected, actual);
32
     }
77
     }
33
 
78
 
34
     @Test
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
     public void testGetLargeTriangle() {
80
     public void testGetLargeTriangle() {
47
         String expected =
81
         String expected =
48
                 "*\n" +
82
                 "*\n" +

+ 20
- 20
package.bluej Целия файл

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