コード例 #1
0
 @Test
 public void testBinarySearchLimit() {
   assertEquals(9, Search.binarySearch(sorted, 9));
 }
コード例 #2
0
 @Test
 public void testBinarySearch() {
   assertEquals(3, Search.binarySearch(sorted, 3));
 }
コード例 #3
0
 @Test
 public void testBinarySearchLeftOverflow() {
   assertEquals(-1, Search.binarySearch(sorted, -1));
 }
コード例 #4
0
 @Test
 public void testBinarySearchRightOverflow() {
   assertEquals(-11, Search.binarySearch(sorted, 10));
 }
コード例 #5
0
ファイル: TestSearch.java プロジェクト: pvinay/algorithms
 @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)));
 }