From 9c74fc507bcf41b8c39501bbafbd7f36014da5c3 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Mon, 10 Nov 2014 10:42:42 +0100 Subject: [PATCH] [T] Test for properties in class Mesh. --- Tests/MeshLib/MeshProperties.cpp | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Tests/MeshLib/MeshProperties.cpp diff --git a/Tests/MeshLib/MeshProperties.cpp b/Tests/MeshLib/MeshProperties.cpp new file mode 100644 index 00000000000..834597d3654 --- /dev/null +++ b/Tests/MeshLib/MeshProperties.cpp @@ -0,0 +1,53 @@ +/** + * \copyright + * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/LICENSE.txt + */ + +#include <ctime> +#include "gtest/gtest.h" + +#include "MeshLib/MeshGenerators/MeshGenerator.h" +#include "MeshLib/Mesh.h" +#include "MeshLib/Elements/Line.h" + +class MeshLibMeshProperties : public ::testing::Test +{ + public: + MeshLibMeshProperties() + : mesh(nullptr) + { + mesh = MeshLib::MeshGenerator::generateRegularHexMesh(1.0, mesh_size); + } + + ~MeshLibMeshProperties() + { + delete mesh; + } + + static std::size_t const mesh_size = 9; + MeshLib::Mesh * mesh; +}; +std::size_t const MeshLibMeshProperties::mesh_size; + +TEST_F(MeshLibMeshProperties, AddDoubleProperties) +{ + ASSERT_TRUE(mesh != nullptr); + const std::size_t size(mesh_size*mesh_size*mesh_size); + std::vector<double> double_properties(size); + std::iota(double_properties.begin(), double_properties.end(), 1); + + std::string const& prop_name("FirstTestProperty"); + // add a vector with property values to the mesh + mesh->addProperty(prop_name, double_properties); + + boost::optional<std::vector<double> const&> + double_properties_cpy(mesh->getProperty<double>(prop_name)); + + for (std::size_t k(0); k<size; k++) { + ASSERT_EQ(double_properties[k], (*double_properties_cpy)[k]); + } +} + -- GitLab