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

#include "pMinMax.h"

Pierre Aubert's avatar
Pierre Aubert committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
///Test the min max function
/**	@param tabValue : table of values
 * 	@param nbValue : number of values
 * 	@param minVal : expected min value
 * 	@param minPos : expected min position of the table of value
 * 	@param maxVal : expected max value
 * 	@param maxPos : expected max position of the table of value
 * 	@return true on success, false otherwise
*/
bool checkMinMaxTab(const int * tabValue, size_t nbValue, int minVal, size_t minPos, int maxVal, size_t maxPos){
	bool b(true);
	
	b &= pminTab<int>(tabValue, nbValue) == minVal;
	b &= pminTabPos<int>(tabValue, nbValue) == minPos;
	
	b &= pmaxTab<int>(tabValue, nbValue) == maxVal;
	b &= pmaxTabPos<int>(tabValue, nbValue) == maxPos;
	
	return b;
}

///Test the min max function
Pierre Aubert's avatar
Pierre Aubert committed
31 32 33 34 35
/**	@return true on success, false otherwise
*/
bool testPMinMax(){
	bool b(true);
	
Pierre Aubert's avatar
Pierre Aubert committed
36 37
	b &= checkMinMaxTab(NULL, 0lu, 0, 0lu, 0, 0lu);
	b &= checkMinMaxTab(NULL, 1lu, 0, 0lu, 0, 0lu);
Pierre Aubert's avatar
Pierre Aubert committed
38
	
Pierre Aubert's avatar
Pierre Aubert committed
39
	int tabSingle[] = {1};
Pierre Aubert's avatar
Pierre Aubert committed
40
	b &= checkMinMaxTab(tabSingle, 0lu, 0, 0lu, 0, 0lu);
Pierre Aubert's avatar
Pierre Aubert committed
41
	
Pierre Aubert's avatar
Pierre Aubert committed
42
	b &= checkMinMaxTab(tabSingle, 1lu, 1, 0lu, 1, 0lu);
Pierre Aubert's avatar
Pierre Aubert committed
43 44 45 46
	
	size_t nbValue(15lu);
	int tabValue[] = {1,4,6,3,6,6,7,0,4,3,7,5,3,5,6};
	
Pierre Aubert's avatar
Pierre Aubert committed
47
	b &= checkMinMaxTab(tabValue, nbValue, 0, 7lu, 7, 6lu);
Pierre Aubert's avatar
Pierre Aubert committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
	
	
	return b;
}


int main(int argc, char** argv){
	bool b(testPMinMax());
	
	
	return b - 1;
}