Extend support for float/double tolerances in testing
[alexxy/gromacs.git] / src / gromacs / fft / tests / fft.cpp
index ff83aa6dec8160f9c78cb0668782ba1f03745f31..dfe4dbd3311a2ad01ac646e8c88457340e7b6141 100644 (file)
@@ -1,48 +1,60 @@
 /*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *                This source code is part of
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
  *
- *                 G   R   O   M   A   C   S
+ * GROMACS is free software; you can 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.
  *
- *          GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /*! \internal \file
  * \brief
  * Tests utilities for fft calculations.
  *
+ * Current reference data is generated in double precision using the Reference
+ * build type, except for the compiler (Apple Clang).
+ *
  * \author Roland Schulz <roland@utk.edu>
  * \ingroup module_fft
  */
+#include "gmxpre.h"
+
+#include "gromacs/fft/fft.h"
+
 #include <vector>
 
 #include <gtest/gtest.h>
 
-#include "gromacs/fft/fft.h"
 #include "gromacs/fft/parallel_3dfft.h"
 #include "gromacs/utility/stringutil.h"
+
 #include "testutils/refdata.h"
+#include "testutils/testasserts.h"
 
 namespace
 {
@@ -75,16 +87,24 @@ const real inputdata[] = { //print ",\n".join([",".join(["%4s"%(random.randint(-
 class BaseFFTTest : public ::testing::Test
 {
     public:
-        BaseFFTTest() : checker_(data_.rootChecker())
+        BaseFFTTest()
+            : checker_(data_.rootChecker()), flags_(GMX_FFT_FLAG_CONSERVATIVE)
         {
+            // TODO: These tolerances are just something that has been observed
+            // to be sufficient to pass the tests.  It would be nicer to
+            // actually argue about why they are sufficient (or what is).
+            checker_.setDefaultTolerance(
+                    gmx::test::relativeToleranceAsPrecisionDependentUlp(10.0, 64, 512));
         }
         ~BaseFFTTest()
         {
             gmx_fft_cleanup();
         }
+
         gmx::test::TestReferenceData    data_;
         gmx::test::TestReferenceChecker checker_;
         std::vector<real>               in_, out_;
+        int                             flags_;
 };
 
 class FFTTest : public BaseFFTTest
@@ -154,7 +174,7 @@ TEST_P(FFTTest1D, Complex)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_1d(&fft_, nx, 0);
+    gmx_fft_init_1d(&fft_, nx, flags_);
 
     gmx_fft_1d(fft_, GMX_FFT_FORWARD, in, out);
     checker_.checkSequenceArray(nx*2, out, "forward");
@@ -173,7 +193,7 @@ TEST_P(FFTTest1D, Real)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_1d_real(&fft_, rx, 0);
+    gmx_fft_init_1d_real(&fft_, rx, flags_);
 
     gmx_fft_1d_real(fft_, GMX_FFT_REAL_TO_COMPLEX, in, out);
     checker_.checkSequenceArray(cx*2, out, "forward");
@@ -195,7 +215,7 @@ TEST_F(ManyFFTTest, Complex1DLength48Multi5Test)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_many_1d(&fft_, nx, N, 0);
+    gmx_fft_init_many_1d(&fft_, nx, N, flags_);
 
     gmx_fft_many_1d(fft_, GMX_FFT_FORWARD, in, out);
     checker_.checkSequenceArray(nx*2*N, out, "forward");
@@ -214,7 +234,7 @@ TEST_F(ManyFFTTest, Real1DLength48Multi5Test)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_many_1d_real(&fft_, rx, N, 0);
+    gmx_fft_init_many_1d_real(&fft_, rx, N, flags_);
 
     gmx_fft_many_1d_real(fft_, GMX_FFT_REAL_TO_COMPLEX, in, out);
     checker_.checkSequenceArray(cx*2*N, out, "forward");
@@ -233,7 +253,7 @@ TEST_F(FFTTest, Real2DLength18_15Test)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_2d_real(&fft_, rx, ny, 0);
+    gmx_fft_init_2d_real(&fft_, rx, ny, flags_);
 
     gmx_fft_2d_real(fft_, GMX_FFT_REAL_TO_COMPLEX, in, out);
     checker_.checkSequenceArray(cx*2*ny, out, "forward");