Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / correlationfunctions / tests / expfit.cpp
index 162123bc066d1c735d8a6b2cacad6aa2af42eff3..c7427688f33daa7bb9d40fa76a7971bfe4e0cfbf 100644 (file)
@@ -66,149 +66,148 @@ namespace
 #if HAVE_LMFIT
 class ExpfitData
 {
-    public:
-        int               nrLines_;
-        std::vector<real> x_, y_;
-        real              startTime_, endTime_, dt_;
+public:
+    int               nrLines_;
+    std::vector<real> x_, y_;
+    real              startTime_, endTime_, dt_;
 };
 
 class ExpfitTest : public ::testing::Test
 {
 
-    protected:
-        static std::vector<ExpfitData> data_;
-        test::TestReferenceData        refData_;
-        test::TestReferenceChecker     checker_;
-        ExpfitTest( )
-            : checker_(refData_.rootChecker())
+protected:
+    static std::vector<ExpfitData> data_;
+    test::TestReferenceData        refData_;
+    test::TestReferenceChecker     checker_;
+    ExpfitTest() : checker_(refData_.rootChecker()) {}
+
+    // Static initiation, only run once every test.
+    static void SetUpTestCase()
+    {
+        double**                 tempValues = nullptr;
+        std::vector<std::string> fileName;
+        fileName.push_back(test::TestFileManager::getInputFilePath("testINVEXP.xvg"));
+        fileName.push_back(test::TestFileManager::getInputFilePath("testPRES.xvg"));
+        fileName.push_back(test::TestFileManager::getInputFilePath("testINVEXP79.xvg"));
+        fileName.push_back(test::TestFileManager::getInputFilePath("testERF.xvg"));
+        fileName.push_back(test::TestFileManager::getInputFilePath("testERREST.xvg"));
+        for (std::vector<std::string>::iterator i = fileName.begin(); i < fileName.end(); ++i)
         {
-        }
+            const char* name = i->c_str();
+            int         nrColumns;
+            ExpfitData  ed;
+            ed.nrLines_   = read_xvg(name, &tempValues, &nrColumns);
+            ed.dt_        = tempValues[0][1] - tempValues[0][0];
+            ed.startTime_ = tempValues[0][0];
+            ed.endTime_   = tempValues[0][ed.nrLines_ - 1];
+            for (int j = 0; j < ed.nrLines_; j++)
+            {
+                ed.x_.push_back(static_cast<real>(tempValues[0][j]));
+                ed.y_.push_back(static_cast<real>(tempValues[1][j]));
+            }
+            data_.push_back(ed);
 
-        // Static initiation, only run once every test.
-        static void SetUpTestCase()
-        {
-            double                ** tempValues = nullptr;
-            std::vector<std::string> fileName;
-            fileName.push_back(test::TestFileManager::getInputFilePath("testINVEXP.xvg"));
-            fileName.push_back(test::TestFileManager::getInputFilePath("testPRES.xvg"));
-            fileName.push_back(test::TestFileManager::getInputFilePath("testINVEXP79.xvg"));
-            fileName.push_back(test::TestFileManager::getInputFilePath("testERF.xvg"));
-            fileName.push_back(test::TestFileManager::getInputFilePath("testERREST.xvg"));
-            for (std::vector<std::string>::iterator i = fileName.begin(); i < fileName.end(); ++i)
+            // Free memory that was allocated in read_xvg
+            for (int j = 0; j < nrColumns; j++)
             {
-                const char * name = i->c_str();
-                int          nrColumns;
-                ExpfitData   ed;
-                ed.nrLines_   = read_xvg(name, &tempValues, &nrColumns);
-                ed.dt_        = tempValues[0][1] - tempValues[0][0];
-                ed.startTime_ = tempValues[0][0];
-                ed.endTime_   = tempValues[0][ed.nrLines_-1];
-                for (int j = 0; j  < ed.nrLines_; j++)
-                {
-                    ed.x_.push_back(static_cast<real>(tempValues[0][j]));
-                    ed.y_.push_back(static_cast<real>(tempValues[1][j]));
-                }
-                data_.push_back(ed);
-
-                // Free memory that was allocated in read_xvg
-                for (int j = 0; j < nrColumns; j++)
-                {
-                    sfree(tempValues[j]);
-                    tempValues[j] = nullptr;
-                }
-                sfree(tempValues);
-                tempValues = nullptr;
+                sfree(tempValues[j]);
+                tempValues[j] = nullptr;
             }
+            sfree(tempValues);
+            tempValues = nullptr;
         }
+    }
 
-        static void TearDownTestCase()
-        {
-        }
+    static void TearDownTestCase() {}
 
-        void test(int type, double result[], double tolerance,
-                  unsigned int testType)
-        {
-            int               nfitparm = effnNparams(type);
-            gmx_output_env_t *oenv;
+    void test(int type, double result[], double tolerance, unsigned int testType)
+    {
+        int               nfitparm = effnNparams(type);
+        gmx_output_env_t* oenv;
 
-            if (testType >= data_.size())
-            {
-                GMX_THROW(InvalidInputError("testType out of range"));
-            }
-            output_env_init_default(&oenv);
-            do_lmfit(data_[testType].nrLines_,
-                     &(data_[testType].y_[0]),
-                     nullptr,
-                     data_[testType].dt_,
-                     &(data_[testType].x_[0]),
-                     data_[testType].startTime_,
-                     data_[testType].endTime_,
-                     oenv, false, type, result, 0, nullptr);
-            output_env_done(oenv);
-            checker_.setDefaultTolerance(test::relativeToleranceAsFloatingPoint(1, tolerance));
-            checker_.checkSequenceArray(nfitparm, result, "result");
+        if (testType >= data_.size())
+        {
+            GMX_THROW(InvalidInputError("testType out of range"));
         }
+        output_env_init_default(&oenv);
+        do_lmfit(data_[testType].nrLines_, &(data_[testType].y_[0]), nullptr, data_[testType].dt_,
+                 &(data_[testType].x_[0]), data_[testType].startTime_, data_[testType].endTime_,
+                 oenv, false, type, result, 0, nullptr);
+        output_env_done(oenv);
+        checker_.setDefaultTolerance(test::relativeToleranceAsFloatingPoint(1, tolerance));
+        checker_.checkSequenceArray(nfitparm, result, "result");
+    }
 };
 
 
-//static var
+// static var
 std::vector<ExpfitData> ExpfitTest::data_;
 
 // TODO calling test() leads to a fatal error, which we could in
 // principle test for.
 
-TEST_F (ExpfitTest, EffnEXP1) {
-    double  param[] = {25};
+TEST_F(ExpfitTest, EffnEXP1)
+{
+    double param[] = { 25 };
     test(effnEXP1, param, 1e-5, 0);
 }
 
-TEST_F (ExpfitTest, EffnEXP2) {
-    double  param[] = {35, 0.5};
+TEST_F(ExpfitTest, EffnEXP2)
+{
+    double param[] = { 35, 0.5 };
     test(effnEXP2, param, 3e-5, 0);
 }
 
-TEST_F (ExpfitTest, EffnEXPEXP) {
-    double param[] = {5, 0.5, 45};
+TEST_F(ExpfitTest, EffnEXPEXP)
+{
+    double param[] = { 5, 0.5, 45 };
     test(effnEXPEXP, param, 1e-2, 0);
 }
 
-TEST_F (ExpfitTest, EffnEXP5) {
-    double  param[] = {0.5, 5, 0.5, 50, 0.002};
+TEST_F(ExpfitTest, EffnEXP5)
+{
+    double param[] = { 0.5, 5, 0.5, 50, 0.002 };
     test(effnEXP5, param, 1e-2, 2);
 }
 
-TEST_F (ExpfitTest, EffnEXP7) {
-    double  param[] = {0.1, 2, 0.5, 30, 0.3, 50, -0.002};
+TEST_F(ExpfitTest, EffnEXP7)
+{
+    double param[] = { 0.1, 2, 0.5, 30, 0.3, 50, -0.002 };
     test(effnEXP7, param, 1e-2, 2);
 }
 
-TEST_F (ExpfitTest, EffnEXP9) {
-    double  param[] = {0.4, 5, 0.2, 30, 0.1, 70, 0.2, 200, -0.05};
+TEST_F(ExpfitTest, EffnEXP9)
+{
+    double param[] = { 0.4, 5, 0.2, 30, 0.1, 70, 0.2, 200, -0.05 };
     test(effnEXP9, param, 4e-2, 2);
 }
 
-TEST_F (ExpfitTest, EffnERF) {
-    double  param[] = {80, 120, 180, 5};
+TEST_F(ExpfitTest, EffnERF)
+{
+    double param[] = { 80, 120, 180, 5 };
     test(effnERF, param, 1e-1, 3);
 }
 
-TEST_F (ExpfitTest, EffnERREST) {
-    double  param[] = {1, 0.9, 100};
+TEST_F(ExpfitTest, EffnERREST)
+{
+    double param[] = { 1, 0.9, 100 };
     test(effnERREST, param, 5e-3, 4);
 }
 
-TEST_F (ExpfitTest, EffnVAC) {
-    double param[] = {0.6, 0.1};
+TEST_F(ExpfitTest, EffnVAC)
+{
+    double param[] = { 0.6, 0.1 };
     test(effnVAC, param, 0.05, 0);
 }
 
-TEST_F (ExpfitTest, EffnPRES) {
-    double param[] = {0.6, 10, 7, 1, 0.25, 2};
+TEST_F(ExpfitTest, EffnPRES)
+{
+    double param[] = { 0.6, 10, 7, 1, 0.25, 2 };
     test(effnPRES, param, 1e-4, 1);
 }
 
 #endif
 
-}  // namespace
+} // namespace
 
-}  // namespace gmx
+} // namespace gmx