// Path: src/main/java/rogeriogentil/data/structures/chapter05/RecursionBinarySearch.java
// public class RecursionBinarySearch {
// 
//    public static int search(int n, int[] array, int indexLowest, int indexHighest) {
//       if (indexLowest > indexHighest) {
//          return -1;
//       }
// 
//       int middle = (indexHighest + indexLowest) / 2;
//       int number = array[middle];
// 
//       if (n == number) {
//          return middle;
//       }
// 
//       if (n < number) {
//          return search(n, array, indexLowest, middle - 1);
//       } else {
//          return search(n, array, middle + 1, indexHighest);
//       }
//    }
// }


import rogeriogentil.data.structures.chapter05.RecursionBinarySearch;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
package rogeriogentil.data.structures.chapter05;


/**
 *
 * @author rogerio
 */
public class RecursionBinarySearchTest {

   @Test
   public void deveEncontrarNumeroNoMeio() {
      int[] array = {0, 10, 20, 30, 40};
      int numero = 20;
      
      int index = RecursionBinarySearch.search(numero, array, 0, array.length - 1);
      
      Assert.assertEquals(2, index);
   }
   
   @Ignore
// Path: src/main/java/rogeriogentil/data/structures/chapter05/RecursionBinarySearch.java
// public class RecursionBinarySearch {
// 
//    public static int search(int n, int[] array, int indexLowest, int indexHighest) {
//       if (indexLowest > indexHighest) {
//          return -1;
//       }
// 
//       int middle = (indexHighest + indexLowest) / 2;
//       int number = array[middle];
// 
//       if (n == number) {
//          return middle;
//       }
// 
//       if (n < number) {
//          return search(n, array, indexLowest, middle - 1);
//       } else {
//          return search(n, array, middle + 1, indexHighest);
//       }
//    }
// }


// Path: src/test/java/rogeriogentil/data/structures/chapter05/RecursionBinarySearchTest.java
import rogeriogentil.data.structures.chapter05.RecursionBinarySearch;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

package rogeriogentil.data.structures.chapter05;


/**
 *
 * @author rogerio
 */
public class RecursionBinarySearchTest {

   @Test
   public void deveEncontrarNumeroNoMeio() {
      int[] array = {0, 10, 20, 30, 40};
      int numero = 20;
      
      int index = RecursionBinarySearch.search(numero, array, 0, array.length - 1);
      
      Assert.assertEquals(2, index);
   }
   
   @Ignore
   @Test