1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
void testBinSearch(Tester & t)
{
vector<double> test1;
int comps=0;
cout << "Testing binSearch function" << endl;
//testing size 0 array
t.test(binSearch(test1,17,comps)==-1, "Testing binSearch on size 0 vector");
//testing size 1 array
test1.push_back(0);
t.test(binSearch(test1,17,comps)==-1,"Testing binSearch on vector of size 1. Element not found");
t.test(binSearch(test1,0,comps)==0, "Testing binSearch on vector of size 1. Element Found");
//testing a sorted larger vector
for(int i=1; i<20; ++i)
{
test1.push_back(i);
}
t.test(binSearch(test1,44,comps)==-1,"Testing binSearch on vector of size 20. Element not found");
t.test(binSearch(test1,12,comps)==12, "Testing binSearch on vector of size 20. Element Found");
test1=seedVectorDouble(25);
t.test(binSearch(test1,12,comps)==-2, "Testing binSearch on unsorted vector");
}
| |