[mlpack] 109/207: Split prefixedoustream tests and fix includes in prefixedoustream.hpp

Barak A. Pearlmutter barak+git at pearlmutter.net
Thu Mar 23 17:53:45 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 f70b47f565bb1a8f148ab6c1a4c60e0aa9a77302
Author: shikhar <shikharbhardwaj68 at gmail.com>
Date:   Fri Mar 3 22:09:53 2017 +0530

    Split prefixedoustream tests and fix includes in prefixedoustream.hpp
---
 src/mlpack/core/util/prefixedoutstream.cpp      |   6 +-
 src/mlpack/core/util/prefixedoutstream.hpp      |   8 +-
 src/mlpack/core/util/prefixedoutstream_impl.hpp |   4 +-
 src/mlpack/tests/prefixedoutstream_test.cpp     | 124 +++++++++++++-----------
 4 files changed, 73 insertions(+), 69 deletions(-)

diff --git a/src/mlpack/core/util/prefixedoutstream.cpp b/src/mlpack/core/util/prefixedoutstream.cpp
index 210b8b3..5e73efb 100644
--- a/src/mlpack/core/util/prefixedoutstream.cpp
+++ b/src/mlpack/core/util/prefixedoutstream.cpp
@@ -10,11 +10,7 @@
  * 3-clause BSD license along with mlpack.  If not, see
  * http://www.opensource.org/licenses/BSD-3-Clause for more information.
  */
-#include <string>
-#include <iostream>
-#include <streambuf>
-#include <string.h>
-#include <stdlib.h>
+#include <mlpack/prereqs.hpp>
 
 #include "prefixedoutstream.hpp"
 
diff --git a/src/mlpack/core/util/prefixedoutstream.hpp b/src/mlpack/core/util/prefixedoutstream.hpp
index af41d7b..3b7c824 100644
--- a/src/mlpack/core/util/prefixedoutstream.hpp
+++ b/src/mlpack/core/util/prefixedoutstream.hpp
@@ -13,13 +13,7 @@
 #ifndef MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_HPP
 #define MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_HPP
 
-#include <iostream>
-#include <iomanip>
-#include <string>
-#include <streambuf>
-#include <stdexcept>
-
-#include <mlpack/core/arma_extend/arma_extend.hpp> // Includes Armadillo
+#include <mlpack/prereqs.hpp>
 
 namespace mlpack {
 namespace util {
diff --git a/src/mlpack/core/util/prefixedoutstream_impl.hpp b/src/mlpack/core/util/prefixedoutstream_impl.hpp
index adf3477..16b14b9 100644
--- a/src/mlpack/core/util/prefixedoutstream_impl.hpp
+++ b/src/mlpack/core/util/prefixedoutstream_impl.hpp
@@ -33,7 +33,7 @@ PrefixedOutStream& PrefixedOutStream::operator<<(const T& s)
 }
 
 template<typename T>
-typename std::enable_if<!arma::is_arma_type<T>::value, void>::type
+typename std::enable_if<!arma::is_arma_type<T>::value>::type
 PrefixedOutStream::BaseLogic(const T& val)
 {
   // We will use this to track whether or not we need to terminate at the end of
@@ -137,7 +137,7 @@ PrefixedOutStream::BaseLogic(const T& val)
 }
 
 template<typename T>
-typename std::enable_if<arma::is_arma_type<T>::value, void>::type
+typename std::enable_if<arma::is_arma_type<T>::value>::type
 PrefixedOutStream::BaseLogic(const T& val)
 {
 
diff --git a/src/mlpack/tests/prefixedoutstream_test.cpp b/src/mlpack/tests/prefixedoutstream_test.cpp
index 0527859..e69fe48 100644
--- a/src/mlpack/tests/prefixedoutstream_test.cpp
+++ b/src/mlpack/tests/prefixedoutstream_test.cpp
@@ -106,6 +106,75 @@ BOOST_AUTO_TEST_CASE(TestArmadilloPrefixedOutStream)
       BASH_GREEN "[INFO ] " BASH_CLEAR "   2.5000   3.0000   3.5000\n"
       BASH_GREEN "[INFO ] " BASH_CLEAR "   4.0000   4.5000   5.0000\n");
 
+}
+
+/**
+ * Test that we can correctly output things in general.
+ */
+BOOST_AUTO_TEST_CASE(TestPrefixedOutStream)
+{
+  std::stringstream ss;
+  PrefixedOutStream pss(ss, BASH_GREEN "[INFO ] " BASH_CLEAR);
+
+  pss << "hello world I am ";
+  pss << 7;
+
+  BOOST_REQUIRE_EQUAL(ss.str(),
+      BASH_GREEN "[INFO ] " BASH_CLEAR "hello world I am 7");
+
+  pss << std::endl;
+  BOOST_REQUIRE_EQUAL(ss.str(),
+      BASH_GREEN "[INFO ] " BASH_CLEAR "hello world I am 7\n");
+
+  ss.str("");
+  pss << std::endl;
+  BOOST_REQUIRE_EQUAL(ss.str(),
+      BASH_GREEN "[INFO ] " BASH_CLEAR "\n");
+}
+
+/**
+ * Test format modifiers.
+ */
+BOOST_AUTO_TEST_CASE(TestPrefixedOutStreamModifiers)
+{
+  std::stringstream ss;
+  PrefixedOutStream pss(ss, BASH_GREEN "[INFO ] " BASH_CLEAR);
+
+  pss << "I have a precise number which is ";
+  pss << std::setw(6) << std::setfill('0') << (int)156;
+
+  BOOST_REQUIRE_EQUAL(ss.str(),
+      BASH_GREEN "[INFO ] " BASH_CLEAR
+      "I have a precise number which is 000156");
+}
+
+/**
+ * Test formatted floating-point output.
+ */
+BOOST_AUTO_TEST_CASE(TestFormattedOutput)
+{
+  std::stringstream ss;
+  PrefixedOutStream pss(ss, BASH_GREEN "[INFO ]" BASH_CLEAR);
+
+  const double pi = std::acos(-1.0);
+  pss << std::setprecision(10) << pi;
+
+  BOOST_REQUIRE_EQUAL(ss.str(),
+      BASH_GREEN "[INFO ]" BASH_CLEAR "3.141592654");
+}
+
+/**
+ * Test custom precision output of arma objects.
+ */
+BOOST_AUTO_TEST_CASE(TestArmaCustomPrecision)
+{
+  std::stringstream ss;
+  PrefixedOutStream pss(ss, BASH_GREEN "[INFO ] " BASH_CLEAR);
+  // The vector to be tested
+  arma::vec test("1.0 1.5 2.0 2.5 3.0 3.5 4.0");
+  // The matrix to be tested
+  arma::mat test2("1.0 1.5 2.0; 2.5 3.0 3.5; 4.0 4.5 4.99999");
+
   // Try to print armadillo objects with custom precision
   ss << std::fixed;
   ss << std::setprecision(6);
@@ -171,59 +240,4 @@ BOOST_AUTO_TEST_CASE(TestArmadilloPrefixedOutStream)
       BASH_GREEN "[INFO ] " BASH_CLEAR "   4.0000   4.5000   5.0000\n");
 }
 
-/**
- * Test that we can correctly output things in general.
- */
-BOOST_AUTO_TEST_CASE(TestPrefixedOutStream)
-{
-  std::stringstream ss;
-  PrefixedOutStream pss(ss, BASH_GREEN "[INFO ] " BASH_CLEAR);
-
-  pss << "hello world I am ";
-  pss << 7;
-
-  BOOST_REQUIRE_EQUAL(ss.str(),
-      BASH_GREEN "[INFO ] " BASH_CLEAR "hello world I am 7");
-
-  pss << std::endl;
-  BOOST_REQUIRE_EQUAL(ss.str(),
-      BASH_GREEN "[INFO ] " BASH_CLEAR "hello world I am 7\n");
-
-  ss.str("");
-  pss << std::endl;
-  BOOST_REQUIRE_EQUAL(ss.str(),
-      BASH_GREEN "[INFO ] " BASH_CLEAR "\n");
-}
-
-/**
- * Test format modifiers.
- */
-BOOST_AUTO_TEST_CASE(TestPrefixedOutStreamModifiers)
-{
-  std::stringstream ss;
-  PrefixedOutStream pss(ss, BASH_GREEN "[INFO ] " BASH_CLEAR);
-
-  pss << "I have a precise number which is ";
-  pss << std::setw(6) << std::setfill('0') << (int)156;
-
-  BOOST_REQUIRE_EQUAL(ss.str(),
-      BASH_GREEN "[INFO ] " BASH_CLEAR
-      "I have a precise number which is 000156");
-}
-
-/**
- * Test formatted floating-point output.
- */
-BOOST_AUTO_TEST_CASE(TestFormattedOutput)
-{
-  std::stringstream ss;
-  PrefixedOutStream pss(ss, BASH_GREEN "[INFO ]" BASH_CLEAR);
-
-  const double pi = std::acos(-1.0);
-  pss << std::setprecision(10) << pi;
-
-  BOOST_REQUIRE_EQUAL(ss.str(),
-      BASH_GREEN "[INFO ]" BASH_CLEAR "3.141592654");
-}
-
 BOOST_AUTO_TEST_SUITE_END();

-- 
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