Add support for cumulative histograms
[alexxy/gromacs.git] / src / gromacs / analysisdata / tests / histogram.cpp
index 14057e93f3b2b8c63c7b0331ec214c942d3cce9c..3fef0ef42ceab21d90eb0770ea561cefdc9660f5 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * 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.
  *
  * GROMACS is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_analysisdata
  */
+#include "gmxpre.h"
+
+#include "gromacs/analysisdata/modules/histogram.h"
+
 #include <gtest/gtest.h>
 
 #include "gromacs/analysisdata/analysisdata.h"
-#include "gromacs/analysisdata/modules/histogram.h"
 
-#include "testutils/datatest.h"
+#include "gromacs/analysisdata/tests/datatest.h"
 #include "testutils/testasserts.h"
 
 using gmx::test::AnalysisDataTestInput;
@@ -157,8 +160,13 @@ class SimpleInputData
     public:
         static const AnalysisDataTestInput &get()
         {
+#ifndef STATIC_ANON_NAMESPACE_BUG
             static SimpleInputData singleton;
             return singleton.data_;
+#else
+            static SimpleInputData singleton_histogram;
+            return singleton_histogram.data_;
+#endif
         }
 
         SimpleInputData() : data_(1, true)
@@ -238,8 +246,13 @@ class WeightedSimpleInputData
     public:
         static const AnalysisDataTestInput &get()
         {
+#ifndef STATIC_ANON_NAMESPACE_BUG
             static WeightedSimpleInputData singleton;
             return singleton.data_;
+#else
+            static WeightedSimpleInputData singleton_histogram;
+            return singleton_histogram.data_;
+#endif
         }
 
         WeightedSimpleInputData() : data_(1, true)
@@ -270,8 +283,13 @@ class WeightedDataSetInputData
     public:
         static const AnalysisDataTestInput &get()
         {
+#ifndef STATIC_ANON_NAMESPACE_BUG
             static WeightedDataSetInputData singleton;
             return singleton.data_;
+#else
+            static WeightedDataSetInputData singleton_histogram;
+            return singleton_histogram.data_;
+#endif
         }
 
         WeightedDataSetInputData() : data_(2, true)
@@ -437,8 +455,13 @@ class AverageInputData
     public:
         static const AnalysisDataTestInput &get()
         {
+#ifndef STATIC_ANON_NAMESPACE_BUG
             static AverageInputData singleton;
             return singleton.data_;
+#else
+            static AverageInputData singleton_histogram;
+            return singleton_histogram.data_;
+#endif
         }
 
         AverageInputData() : data_(1, false)
@@ -468,7 +491,6 @@ class AverageInputData
 class MockAverageHistogram : public gmx::AbstractAverageHistogram
 {
     public:
-        MockAverageHistogram() {}
         //! Creates a histogram module with defined bin parameters.
         explicit MockAverageHistogram(const gmx::AnalysisHistogramSettings &settings)
             : AbstractAverageHistogram(settings)
@@ -501,6 +523,24 @@ TEST_F(AbstractAverageHistogramTest, ClonesCorrectly)
 }
 
 
+TEST_F(AbstractAverageHistogramTest, ComputesCumulativeHistogram)
+{
+    const AnalysisDataTestInput &input = AverageInputData::get();
+    MockAverageHistogram         data(
+            gmx::histogramFromBins(1.0, input.frameCount(), 0.5).integerBins());
+    setupArrayData(input, &data);
+
+    ASSERT_NO_THROW_GMX(addStaticCheckerModule(input, &data));
+    ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data));
+    ASSERT_NO_THROW_GMX(data.done());
+
+    gmx::AverageHistogramPointer cumulative(data.clone());
+    cumulative->makeCumulative();
+    ASSERT_NO_THROW_GMX(addReferenceCheckerModule("CumulativeHistogram", cumulative.get()));
+    ASSERT_NO_THROW_GMX(cumulative->done());
+}
+
+
 TEST_F(AbstractAverageHistogramTest, ResamplesAtDoubleBinWidth)
 {
     const AnalysisDataTestInput &input = AverageInputData::get();