Skip to content

Commit

Permalink
added some tests for push_back
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Jul 15, 2016
1 parent 2d964f8 commit 957bf14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/core/src/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,9 @@ void Mat::push_back(const Mat& elems)
bool eq = size == elems.size;
size.p[0] = r;
if( !eq )
CV_Error(CV_StsUnmatchedSizes, "");
CV_Error(CV_StsUnmatchedSizes, "Pushed vector length is not equal to matrix row length");
if( type() != elems.type() )
CV_Error(CV_StsUnmatchedFormats, "");
CV_Error(CV_StsUnmatchedFormats, "Pushed vector type is not the same as matrix type");

if( isSubmatrix() || dataend + step.p[0]*delta > datalimit )
reserve( std::max(r + delta, (r*3+1)/2) );
Expand Down
18 changes: 18 additions & 0 deletions modules/core/test/test_mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,3 +1520,21 @@ TEST(Reduce, regression_should_fail_bug_4594)
EXPECT_NO_THROW(cv::reduce(src, dst, 0, CV_REDUCE_SUM, CV_32S));
EXPECT_NO_THROW(cv::reduce(src, dst, 0, CV_REDUCE_AVG, CV_32S));
}

TEST(Mat, push_back_vector)
{
cv::Mat result(1, 5, CV_32FC1);

std::vector<float> vec1(result.cols + 1);
std::vector<int> vec2(result.cols);

EXPECT_THROW(result.push_back(vec1), cv::Exception);
EXPECT_THROW(result.push_back(vec2), cv::Exception);

vec1.resize(result.cols);

for (int i = 0; i < 5; ++i)
result.push_back(cv::Mat(vec1).reshape(1, 1));

ASSERT_EQ(6, result.rows);
}

0 comments on commit 957bf14

Please sign in to comment.