|
@@ -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
|
}
|