]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
unit test for Utilities::break_text_into_lines
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 17 Jan 2012 22:36:03 +0000 (22:36 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 17 Jan 2012 22:36:03 +0000 (22:36 +0000)
git-svn-id: https://svn.dealii.org/trunk@24908 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/utilities_04.cc [new file with mode: 0644]
tests/base/utilities_04/cmp/generic [new file with mode: 0644]
tests/base/utilities_04/cmp/powerpc-apple-darwin8.10.0+gcc4.0 [new file with mode: 0644]
tests/base/utilities_04/cmp/powerpc-apple-darwin8.8.0+gcc4.0 [new file with mode: 0644]

diff --git a/tests/base/utilities_04.cc b/tests/base/utilities_04.cc
new file mode 100644 (file)
index 0000000..dbc57e0
--- /dev/null
@@ -0,0 +1,92 @@
+//-----------------------------------------------------------------------------
+//    $Id: utilities_03.cc 24204 2011-08-25 19:13:52Z bangerth $
+//    Version: $Name$
+//
+//    Copyright (C) 2005, 2006, 2011 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//-----------------------------------------------------------------------------
+
+// test functions in namespace Utilities
+
+#include "../tests.h"
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+#include <sstream>
+
+#include <deal.II/base/utilities.h>
+
+using namespace dealii;
+
+std::vector<std::string> split_string(const std::string &text, const char delim='|')
+{
+  std::vector<std::string> result;
+  std::string word;
+  std::stringstream stream(text);
+  while( getline(stream, word, delim) )
+    result.push_back(word);
+  
+  return result;
+}
+
+
+void test_function(const std::string &original_text,
+                  const unsigned int width,
+                  const char delimiter,
+                  const std::string &result)
+{
+  std::vector<std::string> res_vec
+    = Utilities::break_text_into_lines (original_text, width, delimiter);
+
+  std::vector<std::string> should_be_vec
+    = split_string(result);
+  
+
+  Assert(res_vec.size()==should_be_vec.size(), ExcInternalError());
+  for (unsigned int i=0;i<res_vec.size();++i)
+    {
+      if (res_vec[i]!=should_be_vec[i])
+       std::cout << "'" << res_vec[i] << "!=" << should_be_vec[i] << "'" << std::endl;
+      Assert(res_vec[i]==should_be_vec[i], ExcInternalError());
+    }
+  
+
+  
+}
+
+
+void test ()
+{
+  test_function("test", 80, ' ', "test");
+  test_function("test it", 80, ' ', "test it");
+  test_function("test it", 5, ' ', "test|it");
+  test_function("test it longer", 5, ' ', "test|it|longer");
+  test_function(" white  space  too long ", 14, ' ', "white  space|too long");
+  test_function(" white  space ", 80, ' ', "white  space");
+
+  test_function("new\nline", 80, ' ', "new|line");
+  test_function("new\n\nline\n", 80, ' ', "new||line|");
+  test_function("combining whitespace\nand new line", 10, ' ', "combining|whitespace|and new|line");
+
+  
+  deallog << "OK" << std::endl;  
+}
+
+
+
+
+int main()
+{
+  std::ofstream logfile("utilities_04/output");
+//deallog.attach(logfile);
+//deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test ();
+}
diff --git a/tests/base/utilities_04/cmp/generic b/tests/base/utilities_04/cmp/generic
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/base/utilities_04/cmp/powerpc-apple-darwin8.10.0+gcc4.0 b/tests/base/utilities_04/cmp/powerpc-apple-darwin8.10.0+gcc4.0
new file mode 100644 (file)
index 0000000..902f619
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::0042
+DEAL::42
+DEAL::3
+DEAL::413
+DEAL::1
+DEAL::-12
+DEAL::125
+DEAL::-177.002 -36.2427 43.4584 
diff --git a/tests/base/utilities_04/cmp/powerpc-apple-darwin8.8.0+gcc4.0 b/tests/base/utilities_04/cmp/powerpc-apple-darwin8.8.0+gcc4.0
new file mode 100644 (file)
index 0000000..902f619
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::0042
+DEAL::42
+DEAL::3
+DEAL::413
+DEAL::1
+DEAL::-12
+DEAL::125
+DEAL::-177.002 -36.2427 43.4584 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.