对于整数,这项任务很简单.
private int x; private int y private int checksOut; public TestCase(int input, int checksOut) { if (input == Integer.MAX_VALUE) { throw new IllegalArgumentException("can't increment MAX_VALUE"); } this.x = input; this.y = input +1; this.checksOut = checksOut; } @Test public void test() { boolean biggerThanY = y <= checksOut; boolean smallerThanX = x >= checksOut; assertTrue(biggerThanY || smallerThanX); }
如何使用原始浮点数而不是整数重写此测试,以便找不到任何未通过测试的输入和checksOut值?
方法java.lang.Math.nextUp(float f)返回"在正无穷大方向上与f相邻的浮点值".