Skip to content

Commit d2bb7e9

Browse files
committed
test crossing zero
1 parent b07bdf9 commit d2bb7e9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

mug-guava/src/test/java/com/google/guava/labs/collect/BinarySearchTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,30 @@ public void guessTheDoubleNumberWithMostlyPositive(
15851585
assertThat(mean).isIn(Range.open(d1, d2));
15861586
}
15871587

1588+
@Test public void find_betweenNegativeAndPositiveZero(
1589+
@TestParameter({"-1", "-0.5", "-0.1", "0"}) double secret) {
1590+
assertThat(
1591+
BinarySearch.forDoubles(Range.closed(-1D, 0D))
1592+
.find((lo, mid, hi) -> Double.compare(secret, mid)))
1593+
.hasValue(secret);
1594+
}
1595+
1596+
@Test public void find_betweenNegativeZeroAndPositiveZero(
1597+
@TestParameter({"0"}) double secret) {
1598+
assertThat(
1599+
BinarySearch.forDoubles(Range.closed(-0D, 0D))
1600+
.find((lo, mid, hi) -> Double.compare(secret, mid)))
1601+
.hasValue(secret);
1602+
}
1603+
1604+
@Test public void find_betweenNegativeAndPositive(
1605+
@TestParameter({"-1", "-0.5", "-0.1", "0", "0.5", "1"}) double secret) {
1606+
assertThat(
1607+
BinarySearch.forDoubles(Range.closed(-1D, 1D))
1608+
.find((lo, mid, hi) -> Double.compare(secret, mid)))
1609+
.hasValue(secret);
1610+
}
1611+
15881612
private static double parabola(int x) {
15891613
return Math.pow(x, 2) + 4 * x - 3;
15901614
}

0 commit comments

Comments
 (0)