25 #include <Base/Common/CompareFloatingPoint.hh>
26 #include <Base/Debug/Error.hh>
27 #include <Base/Math/Random.hh>
28 #include <MathAlgo/Median1D.hh>
43 int main(
int argc,
char *argv[])
49 vector<double> vecDouble;
50 vector<float> vecFloat;
53 const unsigned int numRuns = 1000;
54 const double minVal = -100.0;
55 const double maxVal = 100.0;
56 const unsigned int minSize = 3;
57 const unsigned int maxSize = 150;
60 unsigned int size, medIdx, countLT, countGT, numLT, numGT;
65 for (
unsigned int run = 1; run <= numRuns; run++)
71 vecDouble.resize(size);
72 vecFloat.resize(size);
74 vecDouble[medIdx] = median;
75 countLT = countGT = 0;
77 numLT = size - 1 - numGT;
78 for (
unsigned int i = 0; i < size; i++) {
82 else if (countGT == numGT)
94 vecFloat[i] = (float)vecDouble[i];
95 vecInt[i] = (int)vecDouble[i];
97 BIASASSERT(countLT + countGT + 1 == size);
98 BIASASSERT(vecDouble.size() == size && vecFloat.size() == size && vecInt.size() == size);
99 if (countLT != numLT || countGT != numGT) {
100 cout <<
"Error in run " << run <<
"/" << numRuns <<
" : " << endl
101 <<
" found " << countLT <<
" values below median, expected "
102 << numLT << endl <<
" found " << countGT <<
" values above median, expected "
103 << numGT << endl <<
", vector size is " << size << endl << flush;
114 cout <<
"Error in run " << run <<
"/" << numRuns <<
" : " << endl
115 <<
" [double] computed " << medDouble.
GetMedian()
116 <<
",\t expected " << median << endl
117 <<
" [float] computed " << medFloat.
GetMedian()
118 <<
",\t expected " << (float)median << endl
119 <<
" [int] computed " << medInt.
GetMedian()
120 <<
",\t expected " << (int)median << endl
121 <<
" vector size is " << size << endl << flush;
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
int GetUniformDistributedInt(const int min, const int max)
get uniform distributed random variable including min/max
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
class for producing random numbers from different distributions