[mlpack-svn] r13016 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Jun 11 13:36:05 EDT 2012
Author: rcurtin
Date: 2012-06-11 13:36:04 -0400 (Mon, 11 Jun 2012)
New Revision: 13016
Modified:
mlpack/trunk/src/mlpack/tests/load_save_test.cpp
Log:
Tests for new options to data::Load() and data::Save().
Modified: mlpack/trunk/src/mlpack/tests/load_save_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/load_save_test.cpp 2012-06-11 17:35:52 UTC (rev 13015)
+++ mlpack/trunk/src/mlpack/tests/load_save_test.cpp 2012-06-11 17:36:04 UTC (rev 13016)
@@ -82,12 +82,39 @@
BOOST_REQUIRE(data::Save("test_file.csv", test) == true);
// Load it in and make sure it is the same.
- BOOST_REQUIRE(data::Load("test_file.csv", test) == true);
+ arma::mat test2;
+ BOOST_REQUIRE(data::Load("test_file.csv", test2) == true);
- BOOST_REQUIRE_EQUAL(test.n_rows, 4);
- BOOST_REQUIRE_EQUAL(test.n_cols, 2);
+ BOOST_REQUIRE_EQUAL(test2.n_rows, 4);
+ BOOST_REQUIRE_EQUAL(test2.n_cols, 2);
for (int i = 0; i < 8; i++)
+ BOOST_REQUIRE_CLOSE(test2[i], (double) (i + 1), 1e-5);
+
+ // Remove the file.
+ remove("test_file.csv");
+}
+
+/**
+ * Make sure CSVs can be loaded in non-transposed form.
+ */
+BOOST_AUTO_TEST_CASE(LoadNonTransposedCSVTest)
+{
+ std::fstream f;
+ f.open("test_file.csv", std::fstream::out);
+
+ f << "1, 3, 5, 7" << std::endl;
+ f << "2, 4, 6, 8" << std::endl;
+
+ f.close();
+
+ arma::mat test;
+ BOOST_REQUIRE(data::Load("test_file.csv", test, false, false) == true);
+
+ BOOST_REQUIRE_EQUAL(test.n_cols, 4);
+ BOOST_REQUIRE_EQUAL(test.n_rows, 2);
+
+ for (size_t i = 0; i < 8; ++i)
BOOST_REQUIRE_CLOSE(test[i], (double) (i + 1), 1e-5);
// Remove the file.
@@ -95,6 +122,32 @@
}
/**
+ * Make sure CSVs can be saved in non-transposed form.
+ */
+BOOST_AUTO_TEST_CASE(SaveNonTransposedCSVTest)
+{
+ arma::mat test = "1 2;"
+ "3 4;"
+ "5 6;"
+ "7 8;";
+
+ BOOST_REQUIRE(data::Save("test_file.csv", test, false, false) == true);
+
+ // Load it in and make sure it is in the same.
+ arma::mat test2;
+ BOOST_REQUIRE(data::Load("test_file.csv", test2, false, false) == true);
+
+ BOOST_REQUIRE_EQUAL(test2.n_rows, 4);
+ BOOST_REQUIRE_EQUAL(test2.n_cols, 2);
+
+ for (size_t i = 0; i < 8; ++i)
+ BOOST_REQUIRE_CLOSE(test[i], test2[i], 1e-5);
+
+ // Remove the file.
+ remove("test_file.csv");
+}
+
+/**
* Make sure arma_ascii is loaded correctly.
*/
BOOST_AUTO_TEST_CASE(LoadArmaASCIITest)
More information about the mlpack-svn
mailing list