From e26a9f0639059f29f7bb8261f7d68a1434eecc23 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Wed, 19 Jul 2017 21:35:03 +0200 Subject: [PATCH] Added tests for several Convert types. --- include/deal.II/base/patterns_tools.h | 3 +- tests/base/patterns_tools_01.cc | 60 ++++++++++++++++++++ tests/base/patterns_tools_01.output | 20 +++++++ tests/base/patterns_tools_02.cc | 79 +++++++++++++++++++++++++++ tests/base/patterns_tools_02.output | 40 ++++++++++++++ tests/base/patterns_tools_03.cc | 65 ++++++++++++++++++++++ tests/base/patterns_tools_03.output | 16 ++++++ tests/base/patterns_tools_04.cc | 77 ++++++++++++++++++++++++++ tests/base/patterns_tools_04.output | 16 ++++++ tests/base/patterns_tools_05.cc | 72 ++++++++++++++++++++++++ tests/base/patterns_tools_05.output | 13 +++++ 11 files changed, 460 insertions(+), 1 deletion(-) create mode 100644 tests/base/patterns_tools_01.cc create mode 100644 tests/base/patterns_tools_01.output create mode 100644 tests/base/patterns_tools_02.cc create mode 100644 tests/base/patterns_tools_02.output create mode 100644 tests/base/patterns_tools_03.cc create mode 100644 tests/base/patterns_tools_03.output create mode 100644 tests/base/patterns_tools_04.cc create mode 100644 tests/base/patterns_tools_04.output create mode 100644 tests/base/patterns_tools_05.cc create mode 100644 tests/base/patterns_tools_05.output diff --git a/include/deal.II/base/patterns_tools.h b/include/deal.II/base/patterns_tools.h index dc06e46aea..9c06114ec9 100644 --- a/include/deal.II/base/patterns_tools.h +++ b/include/deal.II/base/patterns_tools.h @@ -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 index 0000000000..28533a4502 --- /dev/null +++ b/tests/base/patterns_tools_01.cc @@ -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 +#include +#include +#include +#include + +#include + +using namespace dealii; +using namespace PatternsTools; + +// Try conversion on elementary types + +template +void test(T t) +{ + deallog << "Type : " << boost::core::demangle(typeid(T).name()) << std::endl; + auto p = Convert::to_pattern(); + deallog << "Pattern : " << p->description() << std::endl; + auto s = Convert::to_string(t); + deallog << "To String: " << s << std::endl; + deallog << "To value : " << Convert::to_string(Convert::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 index 0000000000..188c128ea8 --- /dev/null +++ b/tests/base/patterns_tools_01.output @@ -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 index 0000000000..8852719e72 --- /dev/null +++ b/tests/base/patterns_tools_02.cc @@ -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 +#include +#include +#include +#include + +#include + +using namespace dealii; +using namespace PatternsTools; + +// Try conversion on non elementary types + +template +void test(T t) +{ + auto p = Convert::to_pattern(); + deallog << "Pattern : " << p->description() << std::endl; + auto s = Convert::to_string(t); + deallog << "To String: " << s << std::endl; + deallog << "To value : " << Convert::to_string(Convert::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 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 index 0000000000..be28c44a36 --- /dev/null +++ b/tests/base/patterns_tools_02.output @@ -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 index 0000000000..736a25234f --- /dev/null +++ b/tests/base/patterns_tools_03.cc @@ -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 +#include +#include +#include +#include + +#include + +using namespace dealii; +using namespace PatternsTools; + +// Try conversion on container types + +template +void test(T t) +{ + auto p = Convert::to_pattern(); + deallog << "Pattern : " << p->description() << std::endl; + auto s = Convert::to_string(t); + deallog << "To String: " << s << std::endl; + deallog << "To value : " << Convert::to_string(Convert::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 t10(2, t0); + std::vector t11(2, t1); + std::vector t12(2, t2); + std::vector t13(2, t3); + std::vector 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 index 0000000000..8f3628c8d2 --- /dev/null +++ b/tests/base/patterns_tools_03.output @@ -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 index 0000000000..d2a9348984 --- /dev/null +++ b/tests/base/patterns_tools_04.cc @@ -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 +#include +#include +#include +#include + +#include + +using namespace dealii; +using namespace PatternsTools; + +// Try conversion on map types + +template +void test(T t) +{ + auto p = Convert::to_pattern(); + deallog << "Pattern : " << p->description() << std::endl; + auto s = Convert::to_string(t); + deallog << "To String: " << s << std::endl; + deallog << "To value : " << Convert::to_string(Convert::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 t10; + std::map t11; + std::map t12; + std::map t13; + std::map 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 index 0000000000..7a387902f9 --- /dev/null +++ b/tests/base/patterns_tools_04.output @@ -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 index 0000000000..c4c401794e --- /dev/null +++ b/tests/base/patterns_tools_05.cc @@ -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 +#include +#include +#include +#include + +#include + +using namespace dealii; +using namespace PatternsTools; + +// Try conversion on complex map types + +template +void test(T t) +{ + auto p = Convert::to_pattern(); + deallog << "Pattern : " << p->description() << std::endl; + auto s = Convert::to_string(t); + deallog << "To String: " << s << std::endl; + deallog << "To value : " << Convert::to_string(Convert::to_value(s)) << std::endl; + +} + +int main() +{ + initlog(); + + Point<3> t0(1,2,3); + std::complex t1(4,5); + std::vector> t2(2,t0); + std::vector> t3(2,t1); + + std::map > t10; + std::map > t11; + std::map> > t12; + std::map> > 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 index 0000000000..de4f4b36f8 --- /dev/null +++ b/tests/base/patterns_tools_05.output @@ -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 -- 2.39.5