Added unit tests for matrix iterators.

This commit is contained in:
Davis King 2012-12-23 23:06:34 -05:00
parent ee4e7aea49
commit a0e3d2a606
1 changed files with 82 additions and 0 deletions

View File

@ -934,6 +934,87 @@ namespace
}
}
template <typename T>
std::vector<int> tovect1(const T& m)
{
std::vector<int> temp;
for (typename T::const_iterator i = m.begin(); i != m.end(); ++i)
{
temp.push_back(*i);
}
return temp;
}
template <typename T>
std::vector<int> tovect2(const T& m)
{
std::vector<int> temp;
for (typename T::const_iterator i = m.begin(); i != m.end(); i++)
{
temp.push_back(*i);
}
return temp;
}
template <typename T>
std::vector<int> tovect3(const T& m_)
{
matrix<int> m(m_);
std::vector<int> temp;
for (matrix<int>::iterator i = m.begin(); i != m.end(); ++i)
{
temp.push_back(*i);
}
return temp;
}
template <typename T>
std::vector<int> tovect4(const T& m_)
{
matrix<int> m(m_);
std::vector<int> temp;
for (matrix<int>::iterator i = m.begin(); i != m.end(); i++)
{
temp.push_back(*i);
}
return temp;
}
void test_iterators()
{
matrix<int> m(3,2);
m = 1,2,3,
4,5,6;
std::vector<int> v1 = tovect1(m);
std::vector<int> v2 = tovect2(m);
std::vector<int> v3 = tovect3(m);
std::vector<int> v4 = tovect4(m);
std::vector<int> v5 = tovect1(m+m);
std::vector<int> v6 = tovect2(m+m);
std::vector<int> v7 = tovect3(m+m);
std::vector<int> v8 = tovect4(m+m);
std::vector<int> a1, a2;
for (int i = 1; i <= 6; ++i)
{
a1.push_back(i);
a2.push_back(i*2);
}
DLIB_TEST(max(abs(mat(v1) - mat(a1))) == 0);
DLIB_TEST(max(abs(mat(v2) - mat(a1))) == 0);
DLIB_TEST(max(abs(mat(v3) - mat(a1))) == 0);
DLIB_TEST(max(abs(mat(v4) - mat(a1))) == 0);
DLIB_TEST(max(abs(mat(v5) - mat(a2))) == 0);
DLIB_TEST(max(abs(mat(v6) - mat(a2))) == 0);
DLIB_TEST(max(abs(mat(v7) - mat(a2))) == 0);
DLIB_TEST(max(abs(mat(v8) - mat(a2))) == 0);
}
class matrix_tester : public tester
{
public:
@ -946,6 +1027,7 @@ namespace
void perform_test (
)
{
test_iterators();
test_setsubs();
test_conv<0,0,0,0>();