Commit a0e3d2a6 authored by Davis King's avatar Davis King

Added unit tests for matrix iterators.

parent ee4e7aea
...@@ -934,6 +934,87 @@ namespace ...@@ -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 class matrix_tester : public tester
{ {
public: public:
...@@ -946,6 +1027,7 @@ namespace ...@@ -946,6 +1027,7 @@ namespace
void perform_test ( void perform_test (
) )
{ {
test_iterators();
test_setsubs(); test_setsubs();
test_conv<0,0,0,0>(); test_conv<0,0,0,0>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment