fixed bug #1318. extended RNG::fill with the optional saturateRange parameter

This commit is contained in:
Vadim Pisarevsky
2012-03-29 12:00:34 +00:00
parent ee8c4aeb4b
commit 586ff429ec
4 changed files with 57 additions and 5 deletions

View File

@@ -301,3 +301,37 @@ void Core_RandTest::run( int )
TEST(Core_Rand, quality) { Core_RandTest test; test.safe_run(); }
class Core_RandRangeTest : public cvtest::BaseTest
{
public:
Core_RandRangeTest() {}
~Core_RandRangeTest() {}
protected:
void run(int)
{
Mat a(Size(1280, 720), CV_8U, Scalar(20));
Mat af(Size(1280, 720), CV_32F, Scalar(20));
theRNG().fill(a, RNG::UNIFORM, -DBL_MAX, DBL_MAX);
theRNG().fill(af, RNG::UNIFORM, -DBL_MAX, DBL_MAX);
int n0 = 0, n255 = 0, nx = 0;
int nfmin = 0, nfmax = 0, nfx = 0;
for( int i = 0; i < a.rows; i++ )
for( int j = 0; j < a.cols; j++ )
{
int v = a.at<uchar>(i,j);
double vf = af.at<float>(i,j);
if( v == 0 ) n0++;
else if( v == 255 ) n255++;
else nx++;
if( vf < FLT_MAX*-0.999f ) nfmin++;
else if( vf > FLT_MAX*0.999f ) nfmax++;
else nfx++;
}
CV_Assert( n0 > nx*2 && n255 > nx*2 );
CV_Assert( nfmin > nfx*2 && nfmax > nfx*2 );
}
};
TEST(Core_Rand, range) { Core_RandRangeTest test; test.safe_run(); }