Add replacements for pbc enumerations
[gromacs.git] / src / gromacs / math / tests / coordinatetransformation.cpp
blob805030c0d91aa16d3bdb0ec601e900a8291cda26
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \internal \file
36 * \brief
37 * Tests structure similarity measures rmsd and size-independent rho factor.
39 * \author Christian Blau <cblau@gwdg.de>
40 * \ingroup module_math
42 #include "gmxpre.h"
44 #include "gromacs/math/coordinatetransformation.h"
46 #include <array>
48 #include <gmock/gmock.h>
49 #include <gtest/gtest.h>
51 #include "testutils/testasserts.h"
52 #include "testutils/testmatchers.h"
54 namespace gmx
57 namespace test
60 using ::testing::Pointwise;
61 class TranslateAndScaleTest : public ::testing::Test
63 protected:
64 RVec identityScale_ = {1, 1, 1};
65 RVec identityTranslation_ = {0, 0, 0};
66 std::vector<RVec> testVectors_ = {{0, 0, 0}, {1, 0, 0}, {0, -1, -1}, {1e10, 1e1, 1e-2}, {3, -6, 2.5}};
70 TEST_F(TranslateAndScaleTest, identityTransformation)
72 TranslateAndScale translateAndScale(identityScale_, identityTranslation_);
73 auto toBeTransformed = testVectors_;
74 translateAndScale(toBeTransformed);
75 EXPECT_THAT(testVectors_, Pointwise(RVecEq(defaultFloatTolerance()), toBeTransformed));
78 TEST_F(TranslateAndScaleTest, translationWithIdentityScaling)
80 TranslateAndScale translateAndScale(identityScale_, {1, -1, 2});
81 translateAndScale(testVectors_);
82 std::vector<RVec> expected = { {1, -1, 2}, {2, -1, 2}, {1, -2, 1}, {1e10+1, 1e1-1, 1e-2+2}, { 4, -7, 4.5 } };
83 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
86 TEST_F(TranslateAndScaleTest, scalingWithZeroTranslation)
88 TranslateAndScale translateAndScale({-1e10, 2, 0}, identityTranslation_);
89 translateAndScale(testVectors_);
90 std::vector<RVec> expected = {{0, 0, 0}, {-1e10, 0, 0}, {0, -2, 0}, {-1e20, 2e1, 0}, {-3e10, -12, 0}};
91 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
94 TEST_F(TranslateAndScaleTest, translationAndScalingNonTrivial)
96 TranslateAndScale translateAndScale({-1e10, 2, 0}, {1, -1, 2});
97 translateAndScale(testVectors_);
98 std::vector<RVec> expected = {{-1e+10, -2, 0}, {-2e+10, -2, 0}, {-1e+10, -4, 0}, {-1e+20, 18, 0}, {-4e+10, -14, 0}};
99 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
102 TEST_F(TranslateAndScaleTest, scalingIdentity)
104 ScaleCoordinates scale(identityScale_);
105 auto expected = testVectors_;
106 scale(testVectors_);
107 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
110 TEST_F(TranslateAndScaleTest, scalingNonTrivial)
112 ScaleCoordinates scale({-100, 0.1, 0});
113 std::vector<RVec> expected = {{0, 0, 0}, {-100, 0, 0}, {0, -0.1, 0}, {-1e12, 1e0, 0}, {-300, -0.6, 0}};
114 scale(testVectors_);
115 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
118 TEST_F(TranslateAndScaleTest, scalingInverseNoZero)
120 ScaleCoordinates scale({-100, 0.1, 3});
121 auto expected = testVectors_;
122 scale(testVectors_);
123 scale.inverseIgnoringZeroScale(testVectors_);
124 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
127 TEST_F(TranslateAndScaleTest, scalingInverseWithOneScaleDimensionZero)
129 ScaleCoordinates scale({-100, 0.1, 0});
130 std::vector<RVec> expected = {{0, 0, 0}, {1, 0, 0}, {0, -1, 0}, {1e10, 1e1, 0}, {3, -6, 0}};
131 scale(testVectors_);
132 scale.inverseIgnoringZeroScale(testVectors_);
133 EXPECT_THAT(expected, Pointwise(RVecEq(defaultFloatTolerance()), testVectors_));
136 } // namespace test
137 } // namespace gmx