Please send questions to
st10@humboldt.edu .
//---------------------------------------------------------------
// File: test_count_bin.cpp
// Name: Sharon Tuttle
// last modified: 2-8-05
//
// Purpose: tester for function count_bin
//--------------------------------------------------------------
#include <iostream>
#include "count_bin.h"
using namespace std;
int main()
{
// set-up declarations
int arr1[] = {1, 3, 8, 27, 56, 77, 78, 79, 100};
int count = 0;
// tests and associated cout's
cout << endl;
cout << "Testing function count_bin..." << endl;
cout << endl;
cout << "1's mean test passed, 0's mean test failed:" << endl;
cout << "-------------------------------------------" << endl;
cout << (count_bin(arr1, 0, 8, 50, count) == -1) << endl;
cout << (count == 5) << endl;
count = 0;
cout << (count_bin(arr1, 0, 8, 150, count) == -1) << endl;
cout << (count == 5) << endl;
count = 0;
cout << (count_bin(arr1, 0, 8, 0, count) == -1) << endl;
cout << (count == 7) << endl;
count = 0;
cout << (count_bin(arr1, 0, 8, 1, count) == 0) << endl;
cout << (count == 7) << endl;
count = 0;
cout << (count_bin(arr1, 0, 8, 100, count) == 8) << endl;
cout << (count == 5) << endl;
count = 0;
cout << (count_bin(arr1, 0, 8, 56, count) == 4) << endl;
cout << (count == 1) << endl;
cout << endl;
// let's try a BIG array... [for ADDITIONAL, "bonus" testing!]
int big[10000];
for (int i=0; i < 10000; i++)
{
big[i] = i*2;
}
int target;
cout << "in array of even numbers from 0 to 19998, " << endl;
cout << " enter a value to search for: " ;
cin >> target;
cout << "found it at: ";
int where;
count = 0;
where = count_bin(big, 0, 9999, target, count);
cout << where;
cout << " ...and it took: " << count << " comparisons." << endl;
cout << endl;
return EXIT_SUCCESS;
}