Пример #1
0
 @Test
 public void testSquareRoot() throws Exception {
   assertEquals(4, Search.squareRoot(16));
   assertEquals(13, Search.squareRoot(169));
   assertEquals(25, Search.squareRoot(625));
   assertEquals(-1, Search.squareRoot(626));
 }
Пример #2
0
 @Test
 public void testNaiveSearch3() {
   Search s = new Search();
   assertEquals(3, s.naiveSearch3("pattern", "ter"));
   assertEquals(0, s.naiveSearch3("pattern", "p"));
   assertEquals(6, s.naiveSearch3("pattern", "n"));
   assertEquals(-1, s.naiveSearch3("pattern", "u"));
   assertEquals(2, s.naiveSearch3("pattern", "t"));
 }
Пример #3
0
 @Test
 public void testKmpSearch() {
   Search s = new Search();
   assertEquals(3, s.kmpSearch("pattern", "ter"));
   assertEquals(0, s.kmpSearch("pattern", "p"));
   assertEquals(6, s.kmpSearch("pattern", "n"));
   assertEquals(-1, s.kmpSearch("pattern", "u"));
   assertEquals(2, s.kmpSearch("pattern", "t"));
 }
Пример #4
0
 @Test
 public void testBinarySearchWithEmpty() throws Exception {
   assertEquals(
       4,
       Search.binarySearchWithEmpty(
           new String[] {"at", "", "", "", "ball", "", "", "car", "", "", "dad", "", ""}, "ball"));
 }
Пример #5
0
 @Test
 public void testMinTriplet() {
   assertTrue(
       Arrays.equals(
           new int[] {2, 2, 2},
           Search.minTriplet(
               new int[] {1, 3, 78}, new int[] {15, 19, 79}, new int[] {27, 29, 80})));
 }
Пример #6
0
 @Test
 public void testOccurencesNoDuplicates() throws Exception {
   assertEquals(0, Search.occurences(sorted, 10));
   assertEquals(1, Search.occurences(sorted, 4));
 }
Пример #7
0
 @Test
 public void testRotatedSearchDuplNotThere() throws Exception {
   assertEquals(-1, Search.rotatedSearch(rotatedDupl, 6));
 }
Пример #8
0
 @Test
 public void testRotatedMin() throws Exception {
   assertEquals(4, Search.rotatedMin(new Integer[] {38, 40, 55, 89, 6, 13, 20, 23, 36}));
 }
Пример #9
0
 @Test
 public void testBinarySearchLimit() {
   assertEquals(9, Search.binarySearch(sorted, 9));
 }
Пример #10
0
 @Test
 public void testRotatedSearchDupl() throws Exception {
   assertEquals(8, Search.rotatedSearch(rotatedDupl, 3));
 }
Пример #11
0
 @Test
 public void testBinarySearchRightOverflow() {
   assertEquals(-11, Search.binarySearch(sorted, 10));
 }
Пример #12
0
 @Test
 public void testBinarySearch() {
   assertEquals(3, Search.binarySearch(sorted, 3));
 }
Пример #13
0
 @Test
 public void testMaxmin() throws Exception {
   assertTrue(
       Arrays.equals(
           new Integer[] {3, 9}, Search.maxmin(new Integer[] {4, 5, 6, 6, 7, 8, 9, 9, 3, 4})));
 }
Пример #14
0
 @Test
 public void testSearchSortedMatrixTrue() throws Exception {
   assertTrue(Arrays.equals(new int[] {1, 1}, Search.searchSortedMatrix(m, 11)));
 }
Пример #15
0
 @Test
 public void testBinarySearchMatrixTrue() throws Exception {
   assertTrue(Arrays.equals(new int[] {1, 1}, Search.binarySearchMatrix(m, 11)));
 }
Пример #16
0
 @Test
 public void testNthElementMatrix() throws Exception {
   assertEquals(16, (int) Search.nthElement(m, 6));
   assertEquals(1, (int) Search.nthElement(m, 0));
   assertEquals(50, (int) Search.nthElement(m, 11));
 }
Пример #17
0
 @Test
 public void testNthElementDuplicates() {
   assertEquals(
       5, (int) Search.nthElement(new Integer[] {4, 5, 6, 7, 4, 4, 8, 1, 2, 9, 9, 1, 2}, 7));
 }
Пример #18
0
 @Test
 public void testNthElement() {
   assertEquals(5, (int) Search.nthElement(new Integer[] {4, 5, 6, 7, 8, 9, 1, 2}, 3));
 }
Пример #19
0
 @Test
 public void testInsertionPoint() throws Exception {
   assertEquals(0, Search.insertionPoint(without, 0));
   assertEquals(1, Search.insertionPoint(without, 2));
   assertEquals(4, Search.insertionPoint(without, 7));
 }
Пример #20
0
 @Test
 public void testMaxLessThan() throws Exception {
   assertEquals(8, Search.maxLessThan(sorted2, 15));
   assertEquals(8, Search.maxLessThan(sorted2, 16));
   assertEquals(-1, Search.maxLessThan(sorted2, 0));
 }
Пример #21
0
 @Test
 public void testOccurences() throws Exception {
   Integer[] duplicated = new Integer[] {1, 2, 3, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13};
   assertEquals(3, Search.occurences(duplicated, 4));
   assertEquals(3, Search.occurences(duplicated, 13));
 }
Пример #22
0
 @Test
 public void testBinarySearchLeftOverflow() {
   assertEquals(-1, Search.binarySearch(sorted, -1));
 }
Пример #23
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)));
 }