From 8ec9f0051b8a39428a10de13b9147374f1ea7861 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Thu, 18 Apr 2019 15:49:59 +0200 Subject: [PATCH] Add a test to check std::copy and std::swap with vector of Expressions --- tests/symengine/symengine_number_type_03.cc | 56 +++++++++++++++++++ .../symengine/symengine_number_type_03.output | 12 ++++ 2 files changed, 68 insertions(+) create mode 100644 tests/symengine/symengine_number_type_03.cc create mode 100644 tests/symengine/symengine_number_type_03.output diff --git a/tests/symengine/symengine_number_type_03.cc b/tests/symengine/symengine_number_type_03.cc new file mode 100644 index 0000000000..743745db23 --- /dev/null +++ b/tests/symengine/symengine_number_type_03.cc @@ -0,0 +1,56 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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. +// +// --------------------------------------------------------------------- + + +// Check that the wrapper for symengine expressions can be use with some +// of the algorithms defined in the standard namespace + +#include + +#include + +#include "../tests.h" + +using namespace dealii; +namespace SD = Differentiation::SD; + +int +main() +{ + initlog(); + + const SD::types::symbol_vector copy_from{SD::Expression(1), + SD::Expression(true), + SD::Expression(2.5), + SD::Expression("a")}; + SD::types::symbol_vector copy_to(copy_from.size()); + + // Mimics Tensor operator= + std::copy(copy_from.begin(), copy_from.end(), copy_to.begin()); + + deallog << "Copy" << std::endl; + for (unsigned int i = 0; i < copy_from.size(); ++i) + deallog << i << ": " << copy_from[i] << " -> " << copy_to[i] << std::endl; + + + SD::types::symbol_vector swap_to; + std::swap(copy_to, swap_to); + + deallog << "Swap" << std::endl; + for (unsigned int i = 0; i < swap_to.size(); ++i) + deallog << i << ": " << swap_to[i] << std::endl; + + deallog << "OK" << std::endl; +} diff --git a/tests/symengine/symengine_number_type_03.output b/tests/symengine/symengine_number_type_03.output new file mode 100644 index 0000000000..acf7106b08 --- /dev/null +++ b/tests/symengine/symengine_number_type_03.output @@ -0,0 +1,12 @@ + +DEAL::Copy +DEAL::0: 1 -> 1 +DEAL::1: True -> True +DEAL::2: 2.5 -> 2.5 +DEAL::3: a -> a +DEAL::Swap +DEAL::0: 1 +DEAL::1: True +DEAL::2: 2.5 +DEAL::3: a +DEAL::OK -- 2.39.5