#include "data_structures/basic_types.h"
#include "data_structures/Histogram.h"
#include <iostream>
using namespace std;
int main(void) {
double bounds[5] = { 1.0, 3.0, 5.0, 10.0, 20.0 };
cout << "Testing infinite histogram" << endl;
Histogram<double> infHist( bounds, 5 );
Histogram<double> infHistCopy( infHist );
for( int i = -1; i < 30; i++ ) {
infHist.addValue( static_cast<double>(i) );
}
for( int i = 0; i < infHist.size(); i++ ) {
cout << "Bin " << infHist.getBin(i).toString() << endl;
}
cout << "Testing copy of infinite histogram" << endl;
for( int i = 0; i < infHistCopy.size(); i++ ) {
cout << "Bin " << infHistCopy.getBin(i).toString() << endl;
}
cout << "Testing finite histogram" << endl;
Histogram<double> finHist( bounds, 5, true );
int exceptCount = 0;
for( int i = -1; i < 30; i++ ) {
try {
finHist.addValue( static_cast<double>(i) );
} catch ( ValueOutOfRangeException range ) {
if( ( i > 1 ) && ( i <= 20 ) ) {
cerr << "Unexpected exception populating histogram : " << endl;
cerr << range.what() << endl;
} else {
++exceptCount;
}
}
}
if( exceptCount != 12 ) {
cerr << "Incorrect number of exceptions caught: " << exceptCount << endl;
}
for( int i = 0; i < finHist.size(); i++ ) {
cout << "Bin " << finHist.getBin(i).toString() << endl;
}
cout << "Testing Timeval histogram" << endl;
Timeval timebounds[5] = {
Timeval( 0.001 ),
Timeval( 0.01 ),
Timeval( 0.1 ),
Timeval( 0.2 ),
Timeval( 0.5 )
};
Histogram<Timeval> timeHist( timebounds, 5 );
timeHist.addValue( Timeval( 0.0000 ) );
timeHist.addValue( Timeval( 0.0001 ) );
timeHist.addValue( Timeval( 0.0002 ) );
timeHist.addValue( Timeval( 0.007 ) );
timeHist.addValue( Timeval( 0.01 ) );
timeHist.addValue( Timeval( 0.02 ) );
timeHist.addValue( Timeval( 0.015 ) );
timeHist.addValue( Timeval( 4.3 ) );
for( int i = 0; i < timeHist.size(); i++ ) {
cout << "Bin " << timeHist.getBin(i).toString() << endl;
}
cout << "Testing interval histogram" << endl;
Histogram<double> intervalHist( 0.0, 4.0, 0.75 );
for( int i = -1; i <= 5; i++ ) {
intervalHist.addValue( static_cast<double>(i) );
}
for( int i = 0; i < intervalHist.size(); i++ ) {
cout << "Bin " << intervalHist.getBin(i).toString() << endl;
}
return 0;
}