@Test public void testBinarySearchLimit() { assertEquals(9, Search.binarySearch(sorted, 9)); }
@Test public void testBinarySearch() { assertEquals(3, Search.binarySearch(sorted, 3)); }
@Test public void testBinarySearchLeftOverflow() { assertEquals(-1, Search.binarySearch(sorted, -1)); }
@Test public void testBinarySearchRightOverflow() { assertEquals(-11, Search.binarySearch(sorted, 10)); }
@Test public void testBinary() { Search s = new Search(); assertEquals(-1, (s.binarySearch(new int[] {}, 1))); assertEquals(0, (s.binarySearch(new int[] {1}, 1))); assertEquals(-1, (s.binarySearch(new int[] {2}, 1))); assertEquals(-1, (s.binarySearch(new int[] {2, 4, 6, 8}, 1))); assertEquals(0, (s.binarySearch(new int[] {2, 4, 6, 8}, 2))); assertEquals(2, (s.binarySearch(new int[] {2, 4, 6, 8}, 6))); assertEquals(3, (s.binarySearch(new int[] {2, 4, 6, 8}, 8))); assertEquals(-1, (s.binarySearch(new int[] {2, 4, 6, 8}, 9))); assertEquals(-1, (s.binarySearch(new int[] {2, 4, 5, 6, 8}, 1))); assertEquals(0, (s.binarySearch(new int[] {2, 4, 5, 6, 8}, 2))); assertEquals(3, (s.binarySearch(new int[] {2, 4, 5, 6, 8}, 6))); assertEquals(4, (s.binarySearch(new int[] {2, 4, 5, 6, 8}, 8))); assertEquals(-1, (s.binarySearch(new int[] {2, 4, 5, 6, 8}, 9))); }