|
20 | 20 |
|
21 | 21 | import static org.assertj.core.api.BDDAssertions.then; |
22 | 22 |
|
23 | | -import java.util.stream.IntStream; |
24 | | - |
25 | 23 | import org.junit.jupiter.api.Test; |
26 | 24 |
|
27 | 25 | class ByteCombinableArbitraryTest { |
@@ -50,56 +48,46 @@ void withRange() { |
50 | 48 | @Test |
51 | 49 | void positive() { |
52 | 50 | // when |
53 | | - boolean allPositive = IntStream.range(0, 100) |
54 | | - .mapToObj(i -> CombinableArbitrary.bytes().positive().combined()) |
55 | | - .allMatch(b -> b > 0); |
| 51 | + Byte actual = CombinableArbitrary.bytes().positive().combined(); |
56 | 52 |
|
57 | 53 | // then |
58 | | - then(allPositive).isTrue(); |
| 54 | + then(actual).isPositive(); |
59 | 55 | } |
60 | 56 |
|
61 | 57 | @Test |
62 | 58 | void negative() { |
63 | 59 | // when |
64 | | - boolean allNegative = IntStream.range(0, 100) |
65 | | - .mapToObj(i -> CombinableArbitrary.bytes().negative().combined()) |
66 | | - .allMatch(b -> b < 0); |
| 60 | + Byte actual = CombinableArbitrary.bytes().negative().combined(); |
67 | 61 |
|
68 | 62 | // then |
69 | | - then(allNegative).isTrue(); |
| 63 | + then(actual).isNegative(); |
70 | 64 | } |
71 | 65 |
|
72 | 66 | @Test |
73 | 67 | void even() { |
74 | 68 | // when |
75 | | - boolean allEven = IntStream.range(0, 100) |
76 | | - .mapToObj(i -> CombinableArbitrary.bytes().even().combined()) |
77 | | - .allMatch(b -> b % 2 == 0); |
| 69 | + Byte actual = CombinableArbitrary.bytes().even().combined(); |
78 | 70 |
|
79 | 71 | // then |
80 | | - then(allEven).isTrue(); |
| 72 | + then(actual % 2).isEqualTo(0); |
81 | 73 | } |
82 | 74 |
|
83 | 75 | @Test |
84 | 76 | void odd() { |
85 | 77 | // when |
86 | | - boolean allOdd = IntStream.range(0, 100) |
87 | | - .mapToObj(i -> CombinableArbitrary.bytes().odd().combined()) |
88 | | - .allMatch(b -> b % 2 != 0); |
| 78 | + Byte actual = CombinableArbitrary.bytes().odd().combined(); |
89 | 79 |
|
90 | 80 | // then |
91 | | - then(allOdd).isTrue(); |
| 81 | + then(actual % 2).isNotEqualTo(0); |
92 | 82 | } |
93 | 83 |
|
94 | 84 | @Test |
95 | 85 | void ascii() { |
96 | 86 | // when |
97 | | - boolean allAscii = IntStream.range(0, 100) |
98 | | - .mapToObj(i -> CombinableArbitrary.bytes().ascii().combined()) |
99 | | - .allMatch(b -> b >= 0 && b <= 127); |
| 87 | + Byte actual = CombinableArbitrary.bytes().ascii().combined(); |
100 | 88 |
|
101 | 89 | // then |
102 | | - then(allAscii).isTrue(); |
| 90 | + then(actual).isBetween((byte)0, (byte)127); |
103 | 91 | } |
104 | 92 |
|
105 | 93 | @Test |
@@ -220,136 +208,112 @@ void fixed() { |
220 | 208 | @Test |
221 | 209 | void lastMethodWinsRangeOverPositive() { |
222 | 210 | // when - positive().withRange() => withRange() |
223 | | - boolean allInRange = IntStream.range(0, 30) |
224 | | - .mapToObj(i -> CombinableArbitrary.bytes().positive().withRange((byte)-10, (byte)-1).combined()) |
225 | | - .allMatch(b -> b >= -10 && b <= -1); |
| 211 | + Byte actual = CombinableArbitrary.bytes().positive().withRange((byte)-10, (byte)-1).combined(); |
226 | 212 |
|
227 | 213 | // then |
228 | | - then(allInRange).isTrue(); |
| 214 | + then(actual).isBetween((byte)-10, (byte)-1); |
229 | 215 | } |
230 | 216 |
|
231 | 217 | @Test |
232 | 218 | void lastMethodWinsOddOverEven() { |
233 | 219 | // when - even().odd() => odd() |
234 | | - boolean allOdd = IntStream.range(0, 30) |
235 | | - .mapToObj(i -> CombinableArbitrary.bytes().even().odd().combined()) |
236 | | - .allMatch(b -> b % 2 != 0); |
| 220 | + Byte actual = CombinableArbitrary.bytes().even().odd().combined(); |
237 | 221 |
|
238 | 222 | // then |
239 | | - then(allOdd).isTrue(); |
| 223 | + then(actual % 2).isNotEqualTo(0); |
240 | 224 | } |
241 | 225 |
|
242 | 226 | @Test |
243 | 227 | void byteFilterWithMultipleOfFive() { |
244 | 228 | // when - filter multiples of 5 |
245 | | - boolean allMultipleOfFive = IntStream.range(0, 30) |
246 | | - .mapToObj(i -> CombinableArbitrary.bytes() |
| 229 | + Byte actual = CombinableArbitrary.bytes() |
247 | 230 | .withRange((byte)0, (byte)100) |
248 | | - .filter(b -> b % 5 == 0).combined()) |
249 | | - .allMatch(b -> b % 5 == 0); |
| 231 | + .filter(b -> b % 5 == 0).combined(); |
250 | 232 |
|
251 | 233 | // then |
252 | | - then(allMultipleOfFive).isTrue(); |
| 234 | + then(actual % 5).isEqualTo(0); |
253 | 235 | } |
254 | 236 |
|
255 | 237 | @Test |
256 | 238 | void asciiWithOdd() { |
257 | 239 | // when - ascii().odd() => odd() |
258 | | - boolean allOdd = IntStream.range(0, 100) |
259 | | - .mapToObj(i -> CombinableArbitrary.bytes().ascii().odd().combined()) |
260 | | - .allMatch(b -> b % 2 != 0); |
| 240 | + Byte actual = CombinableArbitrary.bytes().ascii().odd().combined(); |
261 | 241 |
|
262 | 242 | // then |
263 | | - then(allOdd).isTrue(); |
| 243 | + then(actual % 2).isNotEqualTo(0); |
264 | 244 | } |
265 | 245 |
|
266 | 246 | @Test |
267 | 247 | void asciiWithEven() { |
268 | 248 | // when - ascii().even() => even() |
269 | | - boolean allEven = IntStream.range(0, 100) |
270 | | - .mapToObj(i -> CombinableArbitrary.bytes().ascii().even().combined()) |
271 | | - .allMatch(b -> b % 2 == 0); |
| 249 | + Byte actual = CombinableArbitrary.bytes().ascii().even().combined(); |
272 | 250 |
|
273 | 251 | // then |
274 | | - then(allEven).isTrue(); |
| 252 | + then(actual % 2).isEqualTo(0); |
275 | 253 | } |
276 | 254 |
|
277 | 255 | @Test |
278 | 256 | void asciiWithPositive() { |
279 | 257 | // when |
280 | | - boolean allAsciiAndPositive = IntStream.range(0, 100) |
281 | | - .mapToObj(i -> CombinableArbitrary.bytes().ascii().positive().combined()) |
282 | | - .allMatch(b -> b >= 1 && b <= 127); |
| 258 | + Byte actual = CombinableArbitrary.bytes().ascii().positive().combined(); |
283 | 259 |
|
284 | 260 | // then |
285 | | - then(allAsciiAndPositive).isTrue(); |
| 261 | + then(actual).isBetween((byte)1, (byte)127); |
286 | 262 | } |
287 | 263 |
|
288 | 264 | @Test |
289 | 265 | void asciiWithNegative() { |
290 | 266 | // when - ascii().negative() => negative() |
291 | | - boolean allNegative = IntStream.range(0, 100) |
292 | | - .mapToObj(i -> CombinableArbitrary.bytes().ascii().negative().combined()) |
293 | | - .allMatch(b -> b < 0); |
| 267 | + Byte actual = CombinableArbitrary.bytes().ascii().negative().combined(); |
294 | 268 |
|
295 | 269 | // then |
296 | | - then(allNegative).isTrue(); |
| 270 | + then(actual).isNegative(); |
297 | 271 | } |
298 | 272 |
|
299 | 273 | @Test |
300 | 274 | void negativeWithAscii() { |
301 | 275 | // when - negative().ascii() => ascii() |
302 | | - boolean allAscii = IntStream.range(0, 100) |
303 | | - .mapToObj(i -> CombinableArbitrary.bytes().negative().ascii().combined()) |
304 | | - .allMatch(b -> b >= 0 && b <= 127); |
| 276 | + Byte actual = CombinableArbitrary.bytes().negative().ascii().combined(); |
305 | 277 |
|
306 | 278 | // then |
307 | | - then(allAscii).isTrue(); |
| 279 | + then(actual).isBetween((byte)0, (byte)127); |
308 | 280 | } |
309 | 281 |
|
310 | 282 | @Test |
311 | 283 | void oddWithEvenCombination() { |
312 | 284 | // when - odd().even() => even() |
313 | | - boolean allEven = IntStream.range(0, 100) |
314 | | - .mapToObj(i -> CombinableArbitrary.bytes().odd().even().combined()) |
315 | | - .allMatch(b -> b % 2 == 0); |
| 285 | + Byte actual = CombinableArbitrary.bytes().odd().even().combined(); |
316 | 286 |
|
317 | 287 | // then |
318 | | - then(allEven).isTrue(); |
| 288 | + then(actual % 2).isEqualTo(0); |
319 | 289 | } |
320 | 290 |
|
321 | 291 | @Test |
322 | 292 | void positiveWithNegativeCombination() { |
323 | 293 | // when - positive().negative() => negative() |
324 | | - boolean allNegative = IntStream.range(0, 100) |
325 | | - .mapToObj(i -> CombinableArbitrary.bytes().positive().negative().combined()) |
326 | | - .allMatch(b -> b < 0); |
| 294 | + Byte actual = CombinableArbitrary.bytes().positive().negative().combined(); |
327 | 295 |
|
328 | 296 | // then |
329 | | - then(allNegative).isTrue(); |
| 297 | + then(actual).isNegative(); |
330 | 298 | } |
331 | 299 |
|
332 | 300 | @Test |
333 | 301 | void complexApiCombination() { |
334 | 302 | // when - ascii().positive().odd() => odd() |
335 | | - boolean allOdd = IntStream.range(0, 100) |
336 | | - .mapToObj(i -> CombinableArbitrary.bytes().ascii().positive().odd().combined()) |
337 | | - .allMatch(b -> b % 2 != 0); |
| 303 | + Byte actual = CombinableArbitrary.bytes().ascii().positive().odd().combined(); |
338 | 304 |
|
339 | 305 | // then |
340 | | - then(allOdd).isTrue(); |
| 306 | + then(actual % 2).isNotEqualTo(0); |
341 | 307 | } |
342 | 308 |
|
343 | 309 | @Test |
344 | 310 | void rangeOverridesOtherConstraints() { |
345 | 311 | // when |
346 | 312 | byte min = -50; |
347 | 313 | byte max = -10; |
348 | | - boolean allInRange = IntStream.range(0, 100) |
349 | | - .mapToObj(i -> CombinableArbitrary.bytes().ascii().positive().odd().withRange(min, max).combined()) |
350 | | - .allMatch(b -> b >= min && b <= max); |
| 314 | + Byte actual = CombinableArbitrary.bytes().ascii().positive().odd().withRange(min, max).combined(); |
351 | 315 |
|
352 | 316 | // then |
353 | | - then(allInRange).isTrue(); |
| 317 | + then(actual).isBetween(min, max); |
354 | 318 | } |
355 | 319 | } |
0 commit comments