]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added tests for several Convert<T> types.
authorLuca Heltai <luca.heltai@sissa.it>
Wed, 19 Jul 2017 19:35:03 +0000 (21:35 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Sun, 23 Jul 2017 14:57:27 +0000 (16:57 +0200)
include/deal.II/base/patterns_tools.h
tests/base/patterns_tools_01.cc [new file with mode: 0644]
tests/base/patterns_tools_01.output [new file with mode: 0644]
tests/base/patterns_tools_02.cc [new file with mode: 0644]
tests/base/patterns_tools_02.output [new file with mode: 0644]
tests/base/patterns_tools_03.cc [new file with mode: 0644]
tests/base/patterns_tools_03.output [new file with mode: 0644]
tests/base/patterns_tools_04.cc [new file with mode: 0644]
tests/base/patterns_tools_04.output [new file with mode: 0644]
tests/base/patterns_tools_05.cc [new file with mode: 0644]
tests/base/patterns_tools_05.output [new file with mode: 0644]

index dc06e46aea856b954d433a95a61b22eb02cbc9ad..9c06114ec9b24d8c0f27fd3d204e3d5b2993587c 100644 (file)
@@ -196,7 +196,8 @@ namespace PatternsTools
 
 
 // ---------------------- inline and template functions --------------------
-namespace PatternsTools {
+namespace PatternsTools
+{
   namespace internal
   {
     /**
diff --git a/tests/base/patterns_tools_01.cc b/tests/base/patterns_tools_01.cc
new file mode 100644 (file)
index 0000000..28533a4
--- /dev/null
@@ -0,0 +1,60 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/patterns_tools.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/numbers.h>
+#include <boost/core/demangle.hpp>
+
+#include <memory>
+
+using namespace dealii;
+using namespace PatternsTools;
+
+// Try conversion on elementary types
+
+template<class T>
+void test(T t)
+{
+  deallog << "Type     : " << boost::core::demangle(typeid(T).name()) << std::endl;
+  auto p = Convert<T>::to_pattern();
+  deallog << "Pattern  : " << p->description() << std::endl;
+  auto s = Convert<T>::to_string(t);
+  deallog << "To String: " << s << std::endl;
+  deallog << "To value : " << Convert<T>::to_string(Convert<T>::to_value(s)) << std::endl;
+
+}
+
+int main()
+{
+  initlog();
+
+  int                 t0 = 1;
+  unsigned int        t1 = 2;
+  types::boundary_id  t2 = 3;
+  std::string         t3 = "Ciao";
+  double              t4 = 4.0;
+
+  test(t0);
+  test(t1);
+  test(t2);
+  test(t3);
+  test(t4);
+
+  return 0;
+}
diff --git a/tests/base/patterns_tools_01.output b/tests/base/patterns_tools_01.output
new file mode 100644 (file)
index 0000000..188c128
--- /dev/null
@@ -0,0 +1,20 @@
+
+DEAL::Type     : int
+DEAL::Pattern  : [Integer range -2147483648...2147483647 (inclusive)]
+DEAL::To String: 1
+DEAL::To value : 1
+DEAL::Type     : unsigned int
+DEAL::Pattern  : [Integer]
+DEAL::To String: 2
+DEAL::To value : 2
+DEAL::Type     : unsigned char
+DEAL::Pattern  : [Integer range 0...255 (inclusive)]
+DEAL::To String: 3
+DEAL::To value : 3
+DEAL::Pattern  : [Anything]
+DEAL::To String: Ciao
+DEAL::To value : Ciao
+DEAL::Type     : double
+DEAL::Pattern  : [Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]
+DEAL::To String: 4.000000
+DEAL::To value : 4.000000
diff --git a/tests/base/patterns_tools_02.cc b/tests/base/patterns_tools_02.cc
new file mode 100644 (file)
index 0000000..8852719
--- /dev/null
@@ -0,0 +1,79 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/patterns_tools.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/numbers.h>
+#include <boost/core/demangle.hpp>
+
+#include <memory>
+
+using namespace dealii;
+using namespace PatternsTools;
+
+// Try conversion on non elementary types
+
+template<class T>
+void test(T t)
+{
+  auto p = Convert<T>::to_pattern();
+  deallog << "Pattern  : " << p->description() << std::endl;
+  auto s = Convert<T>::to_string(t);
+  deallog << "To String: " << s << std::endl;
+  deallog << "To value : " << Convert<T>::to_string(Convert<T>::to_value(s)) << std::endl;
+
+}
+
+int main()
+{
+  initlog();
+
+  Point<1> t0(1);
+  Point<2> t1(2,3);
+  Point<3> t2(3,4,5);
+
+  Tensor<1,1> t3;
+  Tensor<1,2> t4;
+  Tensor<1,3> t5;
+
+  Tensor<2,1> t32;
+  Tensor<2,2> t42;
+  Tensor<2,3> t52;
+
+  Tensor<3,1> t33;
+  Tensor<3,2> t43;
+  Tensor<3,3> t53;
+
+  std::complex<double> t6(1,2);
+
+  test(t0);
+  test(t1);
+  test(t2);
+  test(t3);
+  test(t4);
+  test(t5);
+  test(t6);
+  test(t32);
+  test(t42);
+  test(t52);
+  test(t33);
+  test(t43);
+  test(t53);
+
+  return 0;
+}
diff --git a/tests/base/patterns_tools_02.output b/tests/base/patterns_tools_02.output
new file mode 100644 (file)
index 0000000..be28c44
--- /dev/null
@@ -0,0 +1,40 @@
+
+DEAL::Pattern  : [List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 1...1 (inclusive)]
+DEAL::To String: 1.000000
+DEAL::To value : 1.000000
+DEAL::Pattern  : [List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 2...2 (inclusive)]
+DEAL::To String: 2.000000, 3.000000
+DEAL::To value : 2.000000, 3.000000
+DEAL::Pattern  : [List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 3...3 (inclusive)]
+DEAL::To String: 3.000000, 4.000000, 5.000000
+DEAL::To value : 3.000000, 4.000000, 5.000000
+DEAL::Pattern  : [List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 1...1 (inclusive)]
+DEAL::To String: 0.000000
+DEAL::To value : 0.000000
+DEAL::Pattern  : [List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 2...2 (inclusive)]
+DEAL::To String: 0.000000, 0.000000
+DEAL::To value : 0.000000, 0.000000
+DEAL::Pattern  : [List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 3...3 (inclusive)]
+DEAL::To String: 0.000000, 0.000000, 0.000000
+DEAL::To value : 0.000000, 0.000000, 0.000000
+DEAL::Pattern  : [List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 2...2 (inclusive)]
+DEAL::To String: 1.000000, 2.000000
+DEAL::To value : 1.000000, 2.000000
+DEAL::Pattern  : [List of <[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 1...1 (inclusive)]> of length 1...1 (inclusive) separated by <;>]
+DEAL::To String: 0.000000
+DEAL::To value : 0.000000
+DEAL::Pattern  : [List of <[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 2...2 (inclusive)]> of length 2...2 (inclusive) separated by <;>]
+DEAL::To String: 0.000000, 0.000000; 0.000000, 0.000000
+DEAL::To value : 0.000000, 0.000000; 0.000000, 0.000000
+DEAL::Pattern  : [List of <[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 3...3 (inclusive)]> of length 3...3 (inclusive) separated by <;>]
+DEAL::To String: 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000
+DEAL::To value : 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000
+DEAL::Pattern  : [List of <[List of <[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 1...1 (inclusive)]> of length 1...1 (inclusive) separated by <;>]> of length 1...1 (inclusive) separated by <|>]
+DEAL::To String: 0.000000
+DEAL::To value : 0.000000
+DEAL::Pattern  : [List of <[List of <[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 2...2 (inclusive)]> of length 2...2 (inclusive) separated by <;>]> of length 2...2 (inclusive) separated by <|>]
+DEAL::To String: 0.000000, 0.000000; 0.000000, 0.000000| 0.000000, 0.000000; 0.000000, 0.000000
+DEAL::To value : 0.000000, 0.000000; 0.000000, 0.000000| 0.000000, 0.000000; 0.000000, 0.000000
+DEAL::Pattern  : [List of <[List of <[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 3...3 (inclusive)]> of length 3...3 (inclusive) separated by <;>]> of length 3...3 (inclusive) separated by <|>]
+DEAL::To String: 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000| 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000| 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000
+DEAL::To value : 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000| 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000| 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000; 0.000000, 0.000000, 0.000000
diff --git a/tests/base/patterns_tools_03.cc b/tests/base/patterns_tools_03.cc
new file mode 100644 (file)
index 0000000..736a252
--- /dev/null
@@ -0,0 +1,65 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/patterns_tools.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/numbers.h>
+#include <boost/core/demangle.hpp>
+
+#include <memory>
+
+using namespace dealii;
+using namespace PatternsTools;
+
+// Try conversion on container types
+
+template<class T>
+void test(T t)
+{
+  auto p = Convert<T>::to_pattern();
+  deallog << "Pattern  : " << p->description() << std::endl;
+  auto s = Convert<T>::to_string(t);
+  deallog << "To String: " << s << std::endl;
+  deallog << "To value : " << Convert<T>::to_string(Convert<T>::to_value(s)) << std::endl;
+
+}
+
+int main()
+{
+  initlog();
+
+  int                 t0 = 1;
+  unsigned int        t1 = 2;
+  types::boundary_id  t2 = 3;
+  std::string         t3 = "Ciao";
+  double              t4 = 4.0;
+
+  std::vector<int                > t10(2, t0);
+  std::vector<unsigned int       > t11(2, t1);
+  std::vector<types::boundary_id > t12(2, t2);
+  std::vector<std::string        > t13(2, t3);
+  std::vector<double             > t14(2, t4);
+
+  test(t10);
+  test(t11);
+  test(t12);
+  test(t13);
+  test(t14);
+
+  return 0;
+}
diff --git a/tests/base/patterns_tools_03.output b/tests/base/patterns_tools_03.output
new file mode 100644 (file)
index 0000000..8f3628c
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL::Pattern  : [List of <[Integer range -2147483648...2147483647 (inclusive)]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 1, 1
+DEAL::To value : 1, 1
+DEAL::Pattern  : [List of <[Integer]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 2, 2
+DEAL::To value : 2, 2
+DEAL::Pattern  : [List of <[Integer range 0...255 (inclusive)]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 3, 3
+DEAL::To value : 3, 3
+DEAL::Pattern  : [List of <[Anything]> of length 0...4294967295 (inclusive)]
+DEAL::To String: Ciao, Ciao
+DEAL::To value : Ciao, Ciao
+DEAL::Pattern  : [List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 4.000000, 4.000000
+DEAL::To value : 4.000000, 4.000000
diff --git a/tests/base/patterns_tools_04.cc b/tests/base/patterns_tools_04.cc
new file mode 100644 (file)
index 0000000..d2a9348
--- /dev/null
@@ -0,0 +1,77 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/patterns_tools.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/numbers.h>
+#include <boost/core/demangle.hpp>
+
+#include <memory>
+
+using namespace dealii;
+using namespace PatternsTools;
+
+// Try conversion on map types
+
+template<class T>
+void test(T t)
+{
+  auto p = Convert<T>::to_pattern();
+  deallog << "Pattern  : " << p->description() << std::endl;
+  auto s = Convert<T>::to_string(t);
+  deallog << "To String: " << s << std::endl;
+  deallog << "To value : " << Convert<T>::to_string(Convert<T>::to_value(s)) << std::endl;
+
+}
+
+int main()
+{
+  initlog();
+
+  int                 t0 = 1;
+  unsigned int        t1 = 2;
+  types::boundary_id  t2 = 3;
+  std::string         t3 = "Ciao";
+  double              t4 = 4.0;
+
+  std::map<unsigned int, int                > t10;
+  std::map<unsigned int, unsigned int       > t11;
+  std::map<unsigned int, types::boundary_id > t12;
+  std::map<unsigned int, std::string        > t13;
+  std::map<unsigned int, double             > t14;
+
+  t10[0] = t0;
+  t11[0] = t1;
+  t12[0] = t2;
+  t13[0] = t3;
+  t14[0] = t4;
+
+  t10[2] = t0;
+  t11[2] = t1;
+  t12[2] = t2;
+  t13[2] = t3;
+  t14[2] = t4;
+
+  test(t10);
+  test(t11);
+  test(t12);
+  test(t13);
+  test(t14);
+
+  return 0;
+}
diff --git a/tests/base/patterns_tools_04.output b/tests/base/patterns_tools_04.output
new file mode 100644 (file)
index 0000000..7a38790
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL::Pattern  : [Map of <[Integer]>:<[Integer range -2147483648...2147483647 (inclusive)]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 0:1, 2:1
+DEAL::To value : 0:1, 2:1
+DEAL::Pattern  : [Map of <[Integer]>:<[Integer]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 0:2, 2:2
+DEAL::To value : 0:2, 2:2
+DEAL::Pattern  : [Map of <[Integer]>:<[Integer range 0...255 (inclusive)]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 0:3, 2:3
+DEAL::To value : 0:3, 2:3
+DEAL::Pattern  : [Map of <[Integer]>:<[Anything]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 0:Ciao, 2:Ciao
+DEAL::To value : 0:Ciao, 2:Ciao
+DEAL::Pattern  : [Map of <[Integer]>:<[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 0...4294967295 (inclusive)]
+DEAL::To String: 0:4.000000, 2:4.000000
+DEAL::To value : 0:4.000000, 2:4.000000
diff --git a/tests/base/patterns_tools_05.cc b/tests/base/patterns_tools_05.cc
new file mode 100644 (file)
index 0000000..c4c4017
--- /dev/null
@@ -0,0 +1,72 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/patterns_tools.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/numbers.h>
+#include <boost/core/demangle.hpp>
+
+#include <memory>
+
+using namespace dealii;
+using namespace PatternsTools;
+
+// Try conversion on complex map types
+
+template<class T>
+void test(T t)
+{
+  auto p = Convert<T>::to_pattern();
+  deallog << "Pattern  : " << p->description() << std::endl;
+  auto s = Convert<T>::to_string(t);
+  deallog << "To String: " << s << std::endl;
+  deallog << "To value : " << Convert<T>::to_string(Convert<T>::to_value(s)) << std::endl;
+
+}
+
+int main()
+{
+  initlog();
+
+  Point<3>                          t0(1,2,3);
+  std::complex<double>              t1(4,5);
+  std::vector<Point<3>>             t2(2,t0);
+  std::vector<std::complex<double>> t3(2,t1);
+
+  std::map<unsigned int, Point<3>                          > t10;
+  std::map<unsigned int, std::complex<double>              > t11;
+  std::map<unsigned int, std::vector<Point<3>>             > t12;
+  std::map<unsigned int, std::vector<std::complex<double>> > t13;
+
+  t10[0] = t0;
+  t11[0] = t1;
+  t12[0] = t2;
+  t13[0] = t3;
+
+  t10[2] = t0;
+  t11[2] = t1;
+  t12[2] = t2;
+  t13[2] = t3;
+
+  test(t10);
+  test(t11);
+  test(t12);
+  test(t13);
+
+  return 0;
+}
diff --git a/tests/base/patterns_tools_05.output b/tests/base/patterns_tools_05.output
new file mode 100644 (file)
index 0000000..de4f4b3
--- /dev/null
@@ -0,0 +1,13 @@
+
+DEAL::Pattern  : [Map of <[Integer]>:<[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 3...3 (inclusive)]> of length 0...4294967295 (inclusive) separated by <;>]
+DEAL::To String: 0:1.000000, 2.000000, 3.000000; 2:1.000000, 2.000000, 3.000000
+DEAL::To value : 0:1.000000, 2.000000, 3.000000; 2:1.000000, 2.000000, 3.000000
+DEAL::Pattern  : [Map of <[Integer]>:<[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 2...2 (inclusive)]> of length 0...4294967295 (inclusive) separated by <;>]
+DEAL::To String: 0:4.000000, 5.000000; 2:4.000000, 5.000000
+DEAL::To value : 0:4.000000, 5.000000; 2:4.000000, 5.000000
+DEAL::Pattern  : [Map of <[Integer]>:<[List of <[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 3...3 (inclusive)]> of length 0...4294967295 (inclusive) separated by <;>]> of length 0...4294967295 (inclusive) separated by <|>]
+DEAL::To String: 0:1.000000, 2.000000, 3.000000; 1.000000, 2.000000, 3.000000| 2:1.000000, 2.000000, 3.000000; 1.000000, 2.000000, 3.000000
+DEAL::To value : 0:1.000000, 2.000000, 3.000000; 1.000000, 2.000000, 3.000000| 2:1.000000, 2.000000, 3.000000; 1.000000, 2.000000, 3.000000
+DEAL::Pattern  : [Map of <[Integer]>:<[List of <[List of <[Double -MAX_DOUBLE...MAX_DOUBLE (inclusive)]> of length 2...2 (inclusive)]> of length 0...4294967295 (inclusive) separated by <;>]> of length 0...4294967295 (inclusive) separated by <|>]
+DEAL::To String: 0:4.000000, 5.000000; 4.000000, 5.000000| 2:4.000000, 5.000000; 4.000000, 5.000000
+DEAL::To value : 0:4.000000, 5.000000; 4.000000, 5.000000| 2:4.000000, 5.000000; 4.000000, 5.000000

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.