[mlpack] 238/324: More comprehensive tests.

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:22:14 UTC 2014


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit a6216c283eaa1db9fb4e80fdf71512817078b8dc
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Mon Jul 28 19:52:39 2014 +0000

    More comprehensive tests.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16907 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/tests/arma_extend_test.cpp | 81 +++++++++++++++++++++++++++++------
 1 file changed, 68 insertions(+), 13 deletions(-)

diff --git a/src/mlpack/tests/arma_extend_test.cpp b/src/mlpack/tests/arma_extend_test.cpp
index dd0b0b3..f523d4e 100644
--- a/src/mlpack/tests/arma_extend_test.cpp
+++ b/src/mlpack/tests/arma_extend_test.cpp
@@ -54,17 +54,44 @@ BOOST_AUTO_TEST_CASE(InplaceReshapeMatrixTest)
 BOOST_AUTO_TEST_CASE(ConstRowColIteratorTest)
 {
   mat X;
-  X.ones(2, 2);
-  // make sure default costructor works okay
+  X.zeros(5, 5);
+  for (size_t i = 0; i < 5; ++i)
+    X.col(i) += i;
+
+  for (size_t i = 0; i < 5; ++i)
+    X.row(i) += 3 * i;
+
+  // Make sure default constructor works okay.
   mat::const_row_col_iterator it;
-  // make sure ++ operator, operator* and comparison operators work fine
+  // Make sure ++ operator, operator* and comparison operators work fine.
   size_t count = 0;
-  for(it = X.begin_row_col();it != X.end_row_col();it++)
+  for (it = X.begin_row_col(); it != X.end_row_col(); it++)
   {
+    // Check iterator value.
+    BOOST_REQUIRE_EQUAL(*it, (count % 5) * 3 + (count / 5));
+
+    // Check iterator position.
+    BOOST_REQUIRE_EQUAL(it.row(), count % 5);
+    BOOST_REQUIRE_EQUAL(it.col(), count / 5);
+
     count++;
-    BOOST_REQUIRE_EQUAL(*it, 1);
   }
-  BOOST_REQUIRE_EQUAL(count, 4);
+  BOOST_REQUIRE_EQUAL(count, 25);
+  it = X.end_row_col();
+  do
+  {
+    it--;
+    count--;
+
+    // Check iterator value.
+    BOOST_REQUIRE_EQUAL(*it, (count % 5) * 3 + (count / 5));
+
+    // Check iterator position.
+    BOOST_REQUIRE_EQUAL(it.row(), count % 5);
+    BOOST_REQUIRE_EQUAL(it.col(), count / 5);
+  } while (it != X.begin_row_col());
+
+  BOOST_REQUIRE_EQUAL(count, 0);
   // make sure it can be constructed from row_iterator
   it = X.begin_row(0);
 }
@@ -75,18 +102,46 @@ BOOST_AUTO_TEST_CASE(ConstRowColIteratorTest)
 BOOST_AUTO_TEST_CASE(RowColIteratorTest)
 {
   mat X;
-  X.ones(2, 2);
-  // make sure default costructor works okay
+  X.zeros(5, 5);
+  for (size_t i = 0; i < 5; ++i)
+    X.col(i) += i;
+
+  for (size_t i = 0; i < 5; ++i)
+    X.row(i) += 3 * i;
+
+  // Make sure default constructor works okay.
   mat::row_col_iterator it;
-  // make sure ++ operator, operator* and comparison operators work fine
+  // Make sure ++ operator, operator* and comparison operators work fine.
   size_t count = 0;
-  for(it = X.begin_row_col();it != X.end_row_col();it++)
+  for (it = X.begin_row_col(); it != X.end_row_col(); it++)
   {
+    // Check iterator value.
+    BOOST_REQUIRE_EQUAL(*it, (count % 5) * 3 + (count / 5));
+
+    // Check iterator position.
+    BOOST_REQUIRE_EQUAL(it.row(), count % 5);
+    BOOST_REQUIRE_EQUAL(it.col(), count / 5);
+
     count++;
-    BOOST_REQUIRE_EQUAL(*it, 1);
   }
-  BOOST_REQUIRE_EQUAL(count, 4);
-  // make sure it can be constructed from row_iterator
+  BOOST_REQUIRE_EQUAL(count, 25);
+  it = X.end_row_col();
+  do
+  {
+    it--;
+    count--;
+
+    // Check iterator value.
+    BOOST_REQUIRE_EQUAL(*it, (count % 5) * 3 + (count / 5));
+
+    // Check iterator position.
+    BOOST_REQUIRE_EQUAL(it.row(), count % 5);
+    BOOST_REQUIRE_EQUAL(it.col(), count / 5);
+  } while (it != X.begin_row_col());
+
+  BOOST_REQUIRE_EQUAL(count, 0);
+
+  // Make sure it can be constructed from row_iterator.
   it = X.begin_row(0);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list