[mlpack] 157/207: add new test cases for strings like "200-DM"
Barak A. Pearlmutter
barak+git at pearlmutter.net
Thu Mar 23 17:53:50 UTC 2017
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch master
in repository mlpack.
commit b292fad82c156dd458075d588a981a8e62219383
Author: stereomatchingkiss <stereomatchingkiss at gmail.com>
Date: Mon Jun 6 20:19:58 2016 +0800
add new test cases for strings like "200-DM"
---
src/mlpack/tests/load_save_test.cpp | 89 +++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/src/mlpack/tests/load_save_test.cpp b/src/mlpack/tests/load_save_test.cpp
index 86f2f07..621f002 100644
--- a/src/mlpack/tests/load_save_test.cpp
+++ b/src/mlpack/tests/load_save_test.cpp
@@ -1223,6 +1223,50 @@ BOOST_AUTO_TEST_CASE(CategoricalCSVLoadTest03)
remove("test.csv");
}
+BOOST_AUTO_TEST_CASE(CategoricalCSVLoadTest04)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << "200-DM, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f.close();
+
+ // Load the test CSV.
+ arma::umat matrix;
+ DatasetInfo info;
+ data::Load("test.csv", matrix, info, true);
+
+ BOOST_REQUIRE_EQUAL(matrix.n_cols, 4);
+ BOOST_REQUIRE_EQUAL(matrix.n_rows, 3);
+
+ BOOST_REQUIRE_EQUAL(matrix(0, 0), 0);
+ BOOST_REQUIRE_EQUAL(matrix(0, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 3), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 3), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 3), 1);
+
+ BOOST_REQUIRE(info.Type(0) == Datatype::categorical);
+ BOOST_REQUIRE(info.Type(1) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(2) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(info.MapString("200-DM", 0), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 0), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 0), "200-DM");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 0), "1");
+
+ remove("test.csv");
+}
+
BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest00)
{
fstream f;
@@ -1450,6 +1494,51 @@ BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest03)
remove("test.csv");
}
+BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest04)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << " 200-DM , 1 , 1 " << endl;
+ f << " 1 , 1 , 1 " << endl;
+ f << " 1 , 1 , 1 " << endl;
+ f << " 1 , 1 , 1 " << endl;
+ f.close();
+
+ // Load the test CSV.
+ arma::umat matrix;
+ DatasetInfo info;
+ data::Load("test.csv", matrix, info, true, false); // No transpose.
+
+ BOOST_REQUIRE_EQUAL(matrix.n_cols, 3);
+ BOOST_REQUIRE_EQUAL(matrix.n_rows, 4);
+
+ BOOST_REQUIRE_EQUAL(matrix(0, 0), 0);
+ BOOST_REQUIRE_EQUAL(matrix(0, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 2), 1);
+
+ BOOST_REQUIRE(info.Type(0) == Datatype::categorical);
+ BOOST_REQUIRE(info.Type(1) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(2) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(3) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(info.MapString("200-DM", 1), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 1), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 1), "200-DM");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 1), "1");
+
+ remove("test.csv");
+}
+
/**
* A harder test CSV based on the concerns in #658.
*/
--
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