294 |
|
for (TimeUnit x : TimeUnit.values()) |
295 |
|
for (TimeUnit y : TimeUnit.values()) { |
296 |
|
long ratio = x.toNanos(1) / y.toNanos(1); |
297 |
< |
if (ratio > 1) { |
297 |
> |
if (ratio >= 1) { |
298 |
|
assertEquals(ratio, y.convert(1, x)); |
299 |
|
assertEquals(1, x.convert(ratio, y)); |
300 |
|
long max = Long.MAX_VALUE/ratio; |
302 |
|
assertEquals(-max * ratio, y.convert(-max, x)); |
303 |
|
assertEquals(max, x.convert(max * ratio, y)); |
304 |
|
assertEquals(-max, x.convert(-max * ratio, y)); |
305 |
< |
assertEquals(Long.MAX_VALUE, y.convert(max + 1, x)); |
306 |
< |
assertEquals(Long.MIN_VALUE, y.convert(-max - 1, x)); |
305 |
> |
if (max < Long.MAX_VALUE) { |
306 |
> |
assertEquals(Long.MAX_VALUE, y.convert(max + 1, x)); |
307 |
> |
assertEquals(Long.MIN_VALUE, y.convert(-max - 1, x)); |
308 |
> |
assertEquals(Long.MIN_VALUE, y.convert(Long.MIN_VALUE + 1, x)); |
309 |
> |
} |
310 |
|
assertEquals(Long.MAX_VALUE, y.convert(Long.MAX_VALUE, x)); |
311 |
|
assertEquals(Long.MIN_VALUE, y.convert(Long.MIN_VALUE, x)); |
309 |
– |
assertEquals(Long.MIN_VALUE, y.convert(Long.MIN_VALUE + 1, x)); |
312 |
|
} |
313 |
|
} |
314 |
|
} |
325 |
|
|
326 |
|
for (TimeUnit x : TimeUnit.values()) { |
327 |
|
long ratio = x.toNanos(1) / NANOSECONDS.toNanos(1); |
328 |
< |
if (ratio > 1) { |
328 |
> |
if (ratio >= 1) { |
329 |
|
long max = Long.MAX_VALUE/ratio; |
330 |
|
for (long z : new long[] {0, 1, -1, max, -max}) |
331 |
|
assertEquals(z * ratio, x.toNanos(z)); |
332 |
< |
assertEquals(Long.MAX_VALUE, x.toNanos(max + 1)); |
333 |
< |
assertEquals(Long.MIN_VALUE, x.toNanos(-max - 1)); |
332 |
> |
if (max < Long.MAX_VALUE) { |
333 |
> |
assertEquals(Long.MAX_VALUE, x.toNanos(max + 1)); |
334 |
> |
assertEquals(Long.MIN_VALUE, x.toNanos(-max - 1)); |
335 |
> |
assertEquals(Long.MIN_VALUE, x.toNanos(Long.MIN_VALUE + 1)); |
336 |
> |
} |
337 |
|
assertEquals(Long.MAX_VALUE, x.toNanos(Long.MAX_VALUE)); |
338 |
|
assertEquals(Long.MIN_VALUE, x.toNanos(Long.MIN_VALUE)); |
334 |
– |
assertEquals(Long.MIN_VALUE, x.toNanos(Long.MIN_VALUE + 1)); |
339 |
|
if (max < Integer.MAX_VALUE) { |
340 |
|
assertEquals(Long.MAX_VALUE, x.toNanos(Integer.MAX_VALUE)); |
341 |
|
assertEquals(Long.MIN_VALUE, x.toNanos(Integer.MIN_VALUE)); |
351 |
|
public void testToMicrosSaturate() { |
352 |
|
for (TimeUnit x : TimeUnit.values()) { |
353 |
|
long ratio = x.toNanos(1) / MICROSECONDS.toNanos(1); |
354 |
< |
if (ratio > 1) { |
354 |
> |
if (ratio >= 1) { |
355 |
|
long max = Long.MAX_VALUE/ratio; |
356 |
|
for (long z : new long[] {0, 1, -1, max, -max}) |
357 |
|
assertEquals(z * ratio, x.toMicros(z)); |
358 |
< |
assertEquals(Long.MAX_VALUE, x.toMicros(max + 1)); |
359 |
< |
assertEquals(Long.MIN_VALUE, x.toMicros(-max - 1)); |
358 |
> |
if (max < Long.MAX_VALUE) { |
359 |
> |
assertEquals(Long.MAX_VALUE, x.toMicros(max + 1)); |
360 |
> |
assertEquals(Long.MIN_VALUE, x.toMicros(-max - 1)); |
361 |
> |
assertEquals(Long.MIN_VALUE, x.toMicros(Long.MIN_VALUE + 1)); |
362 |
> |
} |
363 |
|
assertEquals(Long.MAX_VALUE, x.toMicros(Long.MAX_VALUE)); |
364 |
|
assertEquals(Long.MIN_VALUE, x.toMicros(Long.MIN_VALUE)); |
358 |
– |
assertEquals(Long.MIN_VALUE, x.toMicros(Long.MIN_VALUE + 1)); |
365 |
|
if (max < Integer.MAX_VALUE) { |
366 |
|
assertEquals(Long.MAX_VALUE, x.toMicros(Integer.MAX_VALUE)); |
367 |
|
assertEquals(Long.MIN_VALUE, x.toMicros(Integer.MIN_VALUE)); |
377 |
|
public void testToMillisSaturate() { |
378 |
|
for (TimeUnit x : TimeUnit.values()) { |
379 |
|
long ratio = x.toNanos(1) / MILLISECONDS.toNanos(1); |
380 |
< |
if (ratio > 1) { |
380 |
> |
if (ratio >= 1) { |
381 |
|
long max = Long.MAX_VALUE/ratio; |
382 |
|
for (long z : new long[] {0, 1, -1, max, -max}) |
383 |
|
assertEquals(z * ratio, x.toMillis(z)); |
384 |
< |
assertEquals(Long.MAX_VALUE, x.toMillis(max + 1)); |
385 |
< |
assertEquals(Long.MIN_VALUE, x.toMillis(-max - 1)); |
384 |
> |
if (max < Long.MAX_VALUE) { |
385 |
> |
assertEquals(Long.MAX_VALUE, x.toMillis(max + 1)); |
386 |
> |
assertEquals(Long.MIN_VALUE, x.toMillis(-max - 1)); |
387 |
> |
assertEquals(Long.MIN_VALUE, x.toMillis(Long.MIN_VALUE + 1)); |
388 |
> |
} |
389 |
|
assertEquals(Long.MAX_VALUE, x.toMillis(Long.MAX_VALUE)); |
390 |
|
assertEquals(Long.MIN_VALUE, x.toMillis(Long.MIN_VALUE)); |
382 |
– |
assertEquals(Long.MIN_VALUE, x.toMillis(Long.MIN_VALUE + 1)); |
391 |
|
if (max < Integer.MAX_VALUE) { |
392 |
|
assertEquals(Long.MAX_VALUE, x.toMillis(Integer.MAX_VALUE)); |
393 |
|
assertEquals(Long.MIN_VALUE, x.toMillis(Integer.MIN_VALUE)); |
403 |
|
public void testToSecondsSaturate() { |
404 |
|
for (TimeUnit x : TimeUnit.values()) { |
405 |
|
long ratio = x.toNanos(1) / SECONDS.toNanos(1); |
406 |
< |
if (ratio > 1) { |
406 |
> |
if (ratio >= 1) { |
407 |
|
long max = Long.MAX_VALUE/ratio; |
408 |
|
for (long z : new long[] {0, 1, -1, max, -max}) |
409 |
|
assertEquals(z * ratio, x.toSeconds(z)); |
410 |
< |
assertEquals(Long.MAX_VALUE, x.toSeconds(max + 1)); |
411 |
< |
assertEquals(Long.MIN_VALUE, x.toSeconds(-max - 1)); |
410 |
> |
if (max < Long.MAX_VALUE) { |
411 |
> |
assertEquals(Long.MAX_VALUE, x.toSeconds(max + 1)); |
412 |
> |
assertEquals(Long.MIN_VALUE, x.toSeconds(-max - 1)); |
413 |
> |
assertEquals(Long.MIN_VALUE, x.toSeconds(Long.MIN_VALUE + 1)); |
414 |
> |
} |
415 |
|
assertEquals(Long.MAX_VALUE, x.toSeconds(Long.MAX_VALUE)); |
416 |
|
assertEquals(Long.MIN_VALUE, x.toSeconds(Long.MIN_VALUE)); |
406 |
– |
assertEquals(Long.MIN_VALUE, x.toSeconds(Long.MIN_VALUE + 1)); |
417 |
|
if (max < Integer.MAX_VALUE) { |
418 |
|
assertEquals(Long.MAX_VALUE, x.toSeconds(Integer.MAX_VALUE)); |
419 |
|
assertEquals(Long.MIN_VALUE, x.toSeconds(Integer.MIN_VALUE)); |
449 |
|
public void testToHoursSaturate() { |
450 |
|
for (TimeUnit x : TimeUnit.values()) { |
451 |
|
long ratio = x.toNanos(1) / HOURS.toNanos(1); |
452 |
< |
if (ratio > 1) { |
452 |
> |
if (ratio >= 1) { |
453 |
|
long max = Long.MAX_VALUE/ratio; |
454 |
|
for (long z : new long[] {0, 1, -1, max, -max}) |
455 |
|
assertEquals(z * ratio, x.toHours(z)); |
456 |
< |
assertEquals(Long.MAX_VALUE, x.toHours(max + 1)); |
457 |
< |
assertEquals(Long.MIN_VALUE, x.toHours(-max - 1)); |
456 |
> |
if (max < Long.MAX_VALUE) { |
457 |
> |
assertEquals(Long.MAX_VALUE, x.toHours(max + 1)); |
458 |
> |
assertEquals(Long.MIN_VALUE, x.toHours(-max - 1)); |
459 |
> |
assertEquals(Long.MIN_VALUE, x.toHours(Long.MIN_VALUE + 1)); |
460 |
> |
} |
461 |
|
assertEquals(Long.MAX_VALUE, x.toHours(Long.MAX_VALUE)); |
462 |
|
assertEquals(Long.MIN_VALUE, x.toHours(Long.MIN_VALUE)); |
450 |
– |
assertEquals(Long.MIN_VALUE, x.toHours(Long.MIN_VALUE + 1)); |
463 |
|
} |
464 |
|
} |
465 |
|
} |