#include <stdio.h>
#include<ctype.h>
#include <string.h>

extern int binarySearch(int *array, int ssize, int key, int *count);

extern char *yourName;
extern char *yourStudentID;
static void testcode();

int main(void)
{
  testcode();
  return 0;
}

static void testcode (void)
{
	int key,size,count,isFound;
	int array1[10] = {1,2,3,4,5,6,7,8,9,10};
	int array2[13] = {17,26,34,45,59,62,70,83,101,135,346,753,800};
	int array3[13] = {17,26,34,45,59,62,70,83,101,135,346,753,800};
	int array4[1] = {4};
	int array5[2] = {1,100};
	int	total=1;

	printf ("ICS 51 lab3 (Winter 2005)\nName:      %s\nStudentID: %s\n",   yourName, yourStudentID);

	//first test
	key = 2;
	size=10;
	isFound=binarySearch(array1,size,key,&count);		// 3rd iteration
	if(isFound)
	{
		total = total+2;
		printf("CORRECT: Key is found in %d'th iteration, total=%d \n",count, total);
		if (count >= 5)
			total = total-1;
	}
	else
		printf("INCORRECT: Key couldn't found after %d iteration, total=%d \n",count, total);
	


	//second test	
	key = 800;
	size=13;
	isFound=binarySearch(array2,size,key,&count);		// 4th iteration
	if(isFound)
	{
		total = total+2;
        printf("CORRECT: Key is found in %d'th iteration, total=%d \n",count, total);
		if (count >= 6)
			total = total-1;
	}
	else
		printf("INCORRECT:Key couldn't found after %d iteration, total=%d \n",count, total);
	

	//third test

	key = 110;
	size=13;
	isFound=binarySearch(array3,size,key,&count);		// NO
	if(isFound)
        printf("INCORRECT: Key is found in %d'th iteration, total=%d \n",count, total);
	else
	{
		total=total+2;
		printf("CORRECT: Key couldn't found after %d iteration, total=%d \n",count, total);
		if (count >= 7)
			total = total-1;
	}
	
	

	//4th test	
	key = 4;
	size=1;
	isFound=binarySearch(array4,size,key,&count);		// 1st iteration
	if(isFound)
	{
		total = total+2;
        printf("CORRECT: Key is found in %d'th iteration, total=%d \n",count, total);
		if (count >=3)
			total = total-1;
	}
	else
		printf("INCORRECT: Key couldn't found after %d iteration, total=%d \n",count, total);
	

	//5th test
	key = 1;
	size=2;
	isFound=binarySearch(array5,size,key,&count);		// 2nd iteration
	if(isFound)
	{
		total = total+2;
    	printf("CORRECT: Key is found in %d'th iteration, total=%d \n",count, total);
		if (count >= 4)
			total = total-1;
	}
	else
		printf("INCORRECT: Key couldn't found after %d iteration, total=%d \n",count, total);
	
	printf("TOTAL for LAB3 = %d \n", total);

}