Esempio n. 1
0
 @Test
 public void testBinarySearchLimit() {
   assertEquals(9, Search.binarySearch(sorted, 9));
 }
Esempio n. 2
0
 @Test
 public void testBinarySearch() {
   assertEquals(3, Search.binarySearch(sorted, 3));
 }
Esempio n. 3
0
 @Test
 public void testBinarySearchLeftOverflow() {
   assertEquals(-1, Search.binarySearch(sorted, -1));
 }
Esempio n. 4
0
 @Test
 public void testBinarySearchRightOverflow() {
   assertEquals(-11, Search.binarySearch(sorted, 10));
 }
Esempio n. 5
0
 @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)));
 }