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