[mlpack-git] master: add new test cases (4ea13b0)
gitdub at mlpack.org
gitdub at mlpack.org
Tue May 31 14:25:10 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/1f562a1aba7ae55475afcc95659511c2b7f694e5...5b8fdce471328f722fcd8c0f22a6d995ce22c98b
>---------------------------------------------------------------
commit 4ea13b02acb58c408135d08eae942b774064fdc7
Author: stereomatchingkiss <stereomatchingkiss at gmail.com>
Date: Wed Jun 1 02:25:10 2016 +0800
add new test cases
>---------------------------------------------------------------
4ea13b02acb58c408135d08eae942b774064fdc7
src/mlpack/tests/load_save_test.cpp | 272 +++++++++++++++++++++++++++++++++++-
1 file changed, 270 insertions(+), 2 deletions(-)
diff --git a/src/mlpack/tests/load_save_test.cpp b/src/mlpack/tests/load_save_test.cpp
index 7e2f6a1..1935083 100644
--- a/src/mlpack/tests/load_save_test.cpp
+++ b/src/mlpack/tests/load_save_test.cpp
@@ -941,7 +941,7 @@ BOOST_AUTO_TEST_CASE(NontransposedCSVDatasetInfoLoad)
/**
* Create a file with a categorical string feature, then load it.
*/
-BOOST_AUTO_TEST_CASE(CategoricalCSVLoadTest)
+BOOST_AUTO_TEST_CASE(CategoricalCSVLoadTest00)
{
fstream f;
f.open("test.csv", fstream::out);
@@ -1001,7 +1001,140 @@ BOOST_AUTO_TEST_CASE(CategoricalCSVLoadTest)
remove("test.csv");
}
-BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest)
+BOOST_AUTO_TEST_CASE(CategoricalCSVLoadTest01)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << "1, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f << " , 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), 0);
+ BOOST_REQUIRE_EQUAL(matrix(0, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 3), 0);
+ 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(info.Type(3) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 0), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("", 0), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 0), "1");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 0), "");
+
+ remove("test.csv");
+}
+
+BOOST_AUTO_TEST_CASE(CategoricalCSVLoadTest02)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << "1, 1, 1" << endl;
+ f << ", 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), 0);
+ BOOST_REQUIRE_EQUAL(matrix(0, 3), 0);
+ 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("", 0), 1);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 0), 0);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 0), "1");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 0), "");
+
+ remove("test.csv");
+}
+
+BOOST_AUTO_TEST_CASE(CategoricalCSVLoadTest03)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << ", 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("", 0), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 0), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 0), "");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 0), "1");
+
+ remove("test.csv");
+}
+
+BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest00)
{
fstream f;
f.open("test.csv", fstream::out);
@@ -1093,6 +1226,141 @@ BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest)
remove("test.csv");
}
+BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest01)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << "1, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f << " , 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), 1);
+ 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), 0);
+ 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::numeric);
+ BOOST_REQUIRE(info.Type(1) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(2) == Datatype::categorical);
+ BOOST_REQUIRE(info.Type(3) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(info.MapString("", 2), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 2), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 2), "");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 2), "1");
+
+ remove("test.csv");
+}
+
+BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest02)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << "1, 1, 1" << endl;
+ f << ", 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), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 0), 0);
+ 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::numeric);
+ BOOST_REQUIRE(info.Type(1) == Datatype::categorical);
+ BOOST_REQUIRE(info.Type(2) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(3) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(info.MapString("", 1), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 1), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 1), "");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 1), "1");
+
+ remove("test.csv");
+}
+
+BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest03)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << ", 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("", 1), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 1), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 1), "");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 1), "1");
+
+ remove("test.csv");
+}
+
/**
* A simple ARFF load test. Two attributes, both numeric.
*/
More information about the mlpack-git
mailing list