fixed compile problems when Makefiles are used
[profile/ivi/opencv.git] / modules / core / test / test_arithm.cpp
1 #include "test_precomp.hpp"
2 #include <iostream>
3
4 using namespace cv;
5 using namespace std;
6
7 const int ARITHM_NTESTS = 1000;
8 const int ARITHM_RNG_SEED = -1;
9 const int ARITHM_MAX_NDIMS = 4;
10 const int ARITHM_MAX_SIZE_LOG = 10;
11 const int ARITHM_MAX_CHANNELS = 4;
12
13 static void getArithmValueRange(int depth, double& minval, double& maxval)
14 {
15     minval = depth < CV_32S ? cvtest::getMinVal(depth) : depth == CV_32S ? -1000000 : -1000.;
16     maxval = depth < CV_32S ? cvtest::getMinVal(depth) : depth == CV_32S ? 1000000 : 1000.;
17 }
18
19 static double getArithmMaxErr(int depth)
20 {
21     return depth < CV_32F ? 0 : 4;
22 }
23
24 TEST(ArithmTest, add)
25 {
26     int testIdx = 0;
27     RNG rng(ARITHM_RNG_SEED);
28     for( testIdx = 0; testIdx < ARITHM_NTESTS; testIdx++ )
29     {
30         double minval, maxval;
31         vector<int> size;
32         cvtest::randomSize(rng, 2, ARITHM_MAX_NDIMS, ARITHM_MAX_SIZE_LOG, size);
33         int type = cvtest::randomType(rng, cvtest::TYPE_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
34         int depth = CV_MAT_DEPTH(type);
35         bool haveMask = rng.uniform(0, 4) == 0;
36         
37         getArithmValueRange(depth, minval, maxval);
38         Mat src1 = cvtest::randomMat(rng, size, type, minval, maxval, true);
39         Mat src2 = cvtest::randomMat(rng, size, type, minval, maxval, true);
40         Mat dst0 = cvtest::randomMat(rng, size, type, minval, maxval, false);
41         Mat dst = cvtest::randomMat(rng, size, type, minval, maxval, true);
42         Mat mask;
43         if( haveMask )
44         {
45             mask = cvtest::randomMat(rng, size, CV_8U, 0, 2, true);
46             cvtest::copy(dst0, dst);
47             cvtest::add(src1, 1, src2, 1, Scalar::all(0), dst0, dst.type());
48             cvtest::copy(dst, dst0, mask, true);
49             add(src1, src2, dst, mask);
50         }
51         else
52         {
53             cvtest::add(src1, 1, src2, 1, Scalar::all(0), dst0, dst.type());
54             add(src1, src2, dst);
55         }
56         
57         double maxErr = getArithmMaxErr(depth);
58         vector<int> pos;
59         ASSERT_TRUE(cvtest::cmpEps(dst0, dst, maxErr, &pos)) << "position: " << Mat(pos);
60     }
61 }