main.cpp 2.43 KB
Newer Older
Pierre Aubert's avatar
Pierre Aubert committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/***************************************
	Auteur : Pierre Aubert
	Mail : aubertp7@gmail.com
	Licence : CeCILL-C
****************************************/

#include "PHistogram/PHistogram.h"

///Test the graph conversion to dot
/**	@return true on success, false otherwise
*/
bool testPHistogram(){
	bool b(true);
	
Pierre Aubert's avatar
Pierre Aubert committed
15
	PHistogram<float> hist(-1.0f, 1.0f, 10lu);
Pierre Aubert's avatar
Pierre Aubert committed
16 17
	
	hist.reset();
Pierre Aubert's avatar
Pierre Aubert committed
18 19
	for(size_t i(0lu); i < 1000lu; ++i){
		hist.addValue((((float)(i*27lu%19)) - 9.0)/2.0f);
Pierre Aubert's avatar
Pierre Aubert committed
20 21 22 23 24 25
	}
	std::cout << "testPHistogram : min = " << hist.getMin() << ", max = " << hist.getMax() << ", range = " << hist.getRange() << ", nbValueUnderMin = " << hist.getUnderXMin() << ", nbValueUpperMax = " << hist.getOverXMax() << std::endl;
	std::cout << hist << std::endl;
	
	PHistogram<float> hist2(hist);
	std::cout << hist2 << std::endl;
Pierre Aubert's avatar
Pierre Aubert committed
26
	hist2.checkLogValue(0.001f);
Pierre Aubert's avatar
Pierre Aubert committed
27 28 29 30 31 32
	
	PHistogram<float> hist3;
	hist3 = hist;
	hist3.normalize();
	std::cout << hist3 << std::endl;
	
Pierre Aubert's avatar
Pierre Aubert committed
33 34 35 36 37 38 39 40
	PHistogram<float> hist4;
	hist4.setRange(-1.0f, 1.0f);
	hist4.resize(20lu);
	for(size_t i(0lu); i < 200lu; ++i){
		hist4.addValue((((float)(i*27lu%19)) - 9.0)/5.0f);
	}
	std::cout << hist4 << std::endl;
	
Pierre Aubert's avatar
Pierre Aubert committed
41 42
	PHistogram<float> emptyHist;
	std::cout << emptyHist << std::endl;
Pierre Aubert's avatar
Pierre Aubert committed
43
	emptyHist.normalize();
Pierre Aubert's avatar
Pierre Aubert committed
44
	
Pierre Aubert's avatar
Pierre Aubert committed
45 46
	PHistogram<float> singleValueHist(1lu);
	std::cout << singleValueHist << std::endl;
Pierre Aubert's avatar
Pierre Aubert committed
47
	emptyHist.normalize();
Pierre Aubert's avatar
Pierre Aubert committed
48
	
Pierre Aubert's avatar
Pierre Aubert committed
49 50 51
	return b;
}

Pierre Aubert's avatar
Pierre Aubert committed
52 53 54 55 56 57 58 59 60 61
///Test the graph conversion to dot
/**	@return true on success, false otherwise
*/
bool testPHistogram2(){
	bool b(true);
	
	PHistogram<float> hist(-1.0f, 1.0f, 10lu);
	float tabValue[] = {1.0f,4.0f,6.0f,3.0f,6.0f,6.0f,7.0f,4.0f,3.0f,7.0f,5.0f,3.0f,5.0f,6.0f};
	
	hist.addValue(NULL, 0lu);
Pierre Aubert's avatar
Pierre Aubert committed
62
	hist.addValue(NULL, 42lu);
Pierre Aubert's avatar
Pierre Aubert committed
63 64 65
	hist.setValueRange(tabValue, 14lu);
	hist.addValue(tabValue, 14lu);
	
Pierre Aubert's avatar
Pierre Aubert committed
66 67 68
	hist.setValueRange(tabValue, 0lu);
	hist.addValue(tabValue, 0lu);
	
Pierre Aubert's avatar
Pierre Aubert committed
69 70
	std::cout << hist << std::endl;
	
Pierre Aubert's avatar
Pierre Aubert committed
71
	PHistogram<float> hist4(10lu);
Pierre Aubert's avatar
Pierre Aubert committed
72 73 74
	hist4.setRange(-1.0f, 1.0f);
	hist4.resize(20lu);
	for(size_t i(0lu); i < 200lu; ++i){
Pierre Aubert's avatar
Pierre Aubert committed
75
		hist4.addAmplitude((((float)(i*27lu%19)) - 9.0)/5.0f, -1.0f);
Pierre Aubert's avatar
Pierre Aubert committed
76 77
	}
	std::cout << hist4 << std::endl;
Pierre Aubert's avatar
Pierre Aubert committed
78 79
	hist4.checkLogValue(0.001f);
	hist4.resize(0lu);
Pierre Aubert's avatar
Pierre Aubert committed
80
	
Pierre Aubert's avatar
Pierre Aubert committed
81 82 83 84 85 86 87
	PHistogram<float> emptyHist;
	std::cout << emptyHist << std::endl;
	
	emptyHist.addValue(42.0f);
	emptyHist.addAmplitude(3.0f, 4.0f);
	emptyHist.setValueRange(tabValue, 14lu);
	emptyHist.addValue(tabValue, 14lu);
Pierre Aubert's avatar
Pierre Aubert committed
88
	emptyHist.checkLogValue(0.001f);
Pierre Aubert's avatar
Pierre Aubert committed
89
	
Pierre Aubert's avatar
Pierre Aubert committed
90 91
	return b;
}
Pierre Aubert's avatar
Pierre Aubert committed
92 93 94

int main(int argc, char** argv){
	bool b(testPHistogram());
Pierre Aubert's avatar
Pierre Aubert committed
95
	b &= testPHistogram2();
Pierre Aubert's avatar
Pierre Aubert committed
96 97 98 99
	return b - 1;
}