Remove explicit end-of-array markers from tests.
authorTeemu Murtola <teemu.murtola@gmail.com>
Mon, 15 Oct 2012 07:45:06 +0000 (10:45 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Mon, 15 Oct 2012 15:13:32 +0000 (18:13 +0300)
Instead of using NULL- or otherwise terminated arrays as input to test
functions, use a template wrapper for the functions that take these
arrays to allow the compiler to pass the declared size of the array.
This is safer, as with this approach it is not possible to forget the
terminator.

Change-Id: I7cdb91c055d9026dabebcd9adc657a66fb9a99c3

src/gromacs/analysisdata/tests/analysisdata.cpp
src/gromacs/analysisdata/tests/arraydata.cpp
src/gromacs/analysisdata/tests/average.cpp
src/gromacs/analysisdata/tests/histogram.cpp
src/gromacs/selection/tests/selectioncollection.cpp
src/testutils/datatest.cpp
src/testutils/datatest.h

index e111d5b85f8f55b1cca1578fec5cf6d437f0a479..a1c10c02daa82a8b112216702f31133c9b562b43 100644 (file)
@@ -124,14 +124,12 @@ TEST(AnalysisDataInitializationTest, ChecksMultiPointModules)
 typedef gmx::test::AnalysisDataTestFixture AnalysisDataTest;
 
 // Input data for the tests below.
-using gmx::test::END_OF_DATA;
 using gmx::test::END_OF_FRAME;
 using gmx::test::MPSTOP;
 static const real inputdata[] = {
     1.0,  0.0, 1.0, 2.0, END_OF_FRAME,
     2.0,  1.0, 1.0, 1.0, END_OF_FRAME,
-    3.0,  2.0, 0.0, 0.0, END_OF_FRAME,
-    END_OF_DATA
+    3.0,  2.0, 0.0, 0.0, END_OF_FRAME
 };
 
 /*
@@ -236,8 +234,7 @@ TEST_F(AnalysisDataTest, LimitedStorageWorks)
 static const real multipointinputdata[] = {
     1.0,  0.0, 1.0, 2.0, MPSTOP, 1.1, 2.1, 1.1, MPSTOP, 2.2, 1.2, 0.2, END_OF_FRAME,
     2.0,  1.0, 1.0, 1.0, MPSTOP, 2.1, 1.1, 0.1, MPSTOP, 1.2, 0.2, 1.2, END_OF_FRAME,
-    3.0,  2.0, 0.0, 0.0, MPSTOP, 3.1, 2.1, 1.1, MPSTOP, 0.2, 2.2, 1.2, END_OF_FRAME,
-    END_OF_DATA
+    3.0,  2.0, 0.0, 0.0, MPSTOP, 3.1, 2.1, 1.1, MPSTOP, 0.2, 2.2, 1.2, END_OF_FRAME
 };
 
 /*
index 23d357579e6c316c31b257440c295ea0502a99a0..f135242947e7afdeeb001551fda0e7b0475a73d1 100644 (file)
@@ -55,14 +55,12 @@ namespace
 
 typedef gmx::test::AnalysisDataTestFixture AnalysisArrayDataTest;
 
-using gmx::test::END_OF_DATA;
 using gmx::test::END_OF_FRAME;
 static const real inputdata[] = {
     1.0,  0.0, 1.0, 2.0, END_OF_FRAME,
     2.0,  1.0, 1.0, 1.0, END_OF_FRAME,
     3.0,  2.0, 0.0, 0.0, END_OF_FRAME,
-    4.0,  3.0, 2.0, 1.0, END_OF_FRAME,
-    END_OF_DATA
+    4.0,  3.0, 2.0, 1.0, END_OF_FRAME
 };
 
 TEST_F(AnalysisArrayDataTest, CallsModuleCorrectly)
index f519d78c885cd620f79f8df2cf8ff11443317629..5dc2dafb60a3364acdb557ca4ec072732417b08b 100644 (file)
@@ -58,13 +58,11 @@ namespace
 typedef gmx::test::AnalysisDataTestFixture AverageModuleTest;
 
 // Input data for the tests below.
-using gmx::test::END_OF_DATA;
 using gmx::test::END_OF_FRAME;
 static const real inputdata[] = {
     1.0,  0.0, 1.0, 2.0, END_OF_FRAME,
     2.0,  1.0, 1.0, 1.0, END_OF_FRAME,
-    3.0,  2.0, 0.0, 0.0, END_OF_FRAME,
-    END_OF_DATA
+    3.0,  2.0, 0.0, 0.0, END_OF_FRAME
 };
 
 TEST_F(AverageModuleTest, BasicTest)
index 1b1b604a0922507498371e59e7e522f8f9137d42..bca838d962ec2d0127bcc65435f2da01cf8a1d70 100644 (file)
@@ -144,14 +144,12 @@ TEST(AnalysisHistogramSettingsTest, InitializesFromRangeWithRoundedRange)
 typedef gmx::test::AnalysisDataTestFixture SimpleHistogramModuleTest;
 
 // Input data for the tests below.
-using gmx::test::END_OF_DATA;
 using gmx::test::END_OF_FRAME;
 using gmx::test::MPSTOP;
 static const real simpleinputdata[] = {
     1.0,  0.7, MPSTOP, 1.1, MPSTOP, 2.3, MPSTOP, 2.9, END_OF_FRAME,
     2.0,  1.3, MPSTOP, 2.2, END_OF_FRAME,
-    3.0,  3.3, MPSTOP, 1.2, MPSTOP, 1.3, END_OF_FRAME,
-    END_OF_DATA
+    3.0,  3.3, MPSTOP, 1.2, MPSTOP, 1.3, END_OF_FRAME
 };
 
 TEST_F(SimpleHistogramModuleTest, ComputesCorrectly)
@@ -206,8 +204,7 @@ typedef gmx::test::AnalysisDataTestFixture WeightedHistogramModuleTest;
 static const real weightedinputdata[] = {
     1.0,  0.7, 0.5, MPSTOP, 1.1, 1.0, MPSTOP, 2.3, 1.0, MPSTOP, 2.9, 2.0, END_OF_FRAME,
     2.0,  1.3, 1.0, MPSTOP, 2.2, 3.0, END_OF_FRAME,
-    3.0,  3.3, 0.5, MPSTOP, 1.2, 2.0, MPSTOP, 1.3, 1.0, END_OF_FRAME,
-    END_OF_DATA
+    3.0,  3.3, 0.5, MPSTOP, 1.2, 2.0, MPSTOP, 1.3, 1.0, END_OF_FRAME
 };
 
 TEST_F(WeightedHistogramModuleTest, ComputesCorrectly)
@@ -311,8 +308,7 @@ static const real averageinputdata[] = {
     2.5, 4.0, 2.0, END_OF_FRAME,
     3.0, 2.0, 1.0, END_OF_FRAME,
     3.5, 0.0, 3.0, END_OF_FRAME,
-    4.0, 1.0, 3.0, END_OF_FRAME,
-    END_OF_DATA
+    4.0, 1.0, 3.0, END_OF_FRAME
 };
 
 /*! \internal \brief
index b56f1a7e32b65e7e239def758f72a041a1d10ec3..7596a961077610d88eaf825f3385db78856e6fa7 100644 (file)
@@ -171,14 +171,25 @@ class SelectionCollectionDataTest : public SelectionCollectionTest
 
         void setFlags(TestFlags flags) { flags_ = flags; }
 
-        void runTest(int natoms, const char *const *selections);
-        void runTest(const char *filename, const char *const *selections);
+        void runTest(int natoms, const char *const *selections, size_t count);
+        void runTest(const char *filename, const char *const *selections,
+                     size_t count);
+        template <size_t count>
+        void runTest(int natoms, const char *const (&selections)[count])
+        {
+            runTest(natoms, selections, count);
+        }
+        template <size_t count>
+        void runTest(const char *filename, const char *const (&selections)[count])
+        {
+            runTest(filename, selections, count);
+        }
 
     private:
         static void checkSelection(gmx::test::TestReferenceChecker *checker,
                                    const gmx::Selection &sel, TestFlags flags);
 
-        void runParser(const char *const *selections);
+        void runParser(const char *const *selections, size_t count);
         void runCompiler();
         void checkCompiled();
         void runEvaluate();
@@ -233,14 +244,15 @@ SelectionCollectionDataTest::checkSelection(
 
 
 void
-SelectionCollectionDataTest::runParser(const char *const *selections)
+SelectionCollectionDataTest::runParser(const char *const *selections,
+                                       size_t count)
 {
     using gmx::test::TestReferenceChecker;
 
     TestReferenceChecker compound(checker_.checkCompound("ParsedSelections", "Parsed"));
     size_t varcount = 0;
     count_ = 0;
-    for (size_t i = 0; selections[i] != NULL; ++i)
+    for (size_t i = 0; i < count; ++i)
     {
         SCOPED_TRACE(std::string("Parsing selection \"")
                      + selections[i] + "\"");
@@ -335,18 +347,21 @@ SelectionCollectionDataTest::runEvaluateFinal()
 
 
 void
-SelectionCollectionDataTest::runTest(int natoms, const char * const *selections)
+SelectionCollectionDataTest::runTest(int natoms, const char * const *selections,
+                                     size_t count)
 {
-    ASSERT_NO_FATAL_FAILURE(runParser(selections));
+    ASSERT_NO_FATAL_FAILURE(runParser(selections, count));
     ASSERT_NO_FATAL_FAILURE(setAtomCount(natoms));
     ASSERT_NO_FATAL_FAILURE(runCompiler());
 }
 
 
 void
-SelectionCollectionDataTest::runTest(const char *filename, const char * const *selections)
+SelectionCollectionDataTest::runTest(const char *filename,
+                                     const char * const *selections,
+                                     size_t count)
 {
-    ASSERT_NO_FATAL_FAILURE(runParser(selections));
+    ASSERT_NO_FATAL_FAILURE(runParser(selections, count));
     ASSERT_NO_FATAL_FAILURE(loadTopology(filename));
     ASSERT_NO_FATAL_FAILURE(runCompiler());
     if (flags_.test(efTestEvaluation))
@@ -486,8 +501,7 @@ TEST_F(SelectionCollectionDataTest, HandlesAllNone)
 {
     static const char * const selections[] = {
         "all",
-        "none",
-        NULL
+        "none"
     };
     runTest(10, selections);
 }
@@ -497,8 +511,7 @@ TEST_F(SelectionCollectionDataTest, HandlesAtomnr)
     static const char * const selections[] = {
         "atomnr 1 to 3 6 to 8",
         "atomnr 4 2 5 to 7",
-        "atomnr <= 5",
-        NULL
+        "atomnr <= 5"
     };
     runTest(10, selections);
 }
@@ -507,8 +520,7 @@ TEST_F(SelectionCollectionDataTest, HandlesResnr)
 {
     static const char * const selections[] = {
         "resnr 1 2 5",
-        "resid 4 to 3",
-        NULL
+        "resid 4 to 3"
     };
     runTest("simple.gro", selections);
 }
@@ -517,8 +529,7 @@ TEST_F(SelectionCollectionDataTest, HandlesResIndex)
 {
     static const char * const selections[] = {
         "resindex 1 4",
-        "residue 1 3",
-        NULL
+        "residue 1 3"
     };
     runTest("simple.pdb", selections);
 }
@@ -529,8 +540,7 @@ TEST_F(SelectionCollectionDataTest, HandlesAtomname)
 {
     static const char * const selections[] = {
         "name CB",
-        "atomname S1 S2",
-        NULL
+        "atomname S1 S2"
     };
     runTest("simple.gro", selections);
 }
@@ -541,8 +551,7 @@ TEST_F(SelectionCollectionDataTest, HandlesPdbAtomname)
         "name HG21",
         "name 1HG2",
         "pdbname HG21 CB",
-        "pdbatomname 1HG2",
-        NULL
+        "pdbatomname 1HG2"
     };
     runTest("simple.pdb", selections);
 }
@@ -553,8 +562,7 @@ TEST_F(SelectionCollectionDataTest, HandlesChain)
 {
     static const char * const selections[] = {
         "chain A",
-        "chain B",
-        NULL
+        "chain B"
     };
     runTest("simple.pdb", selections);
 }
@@ -566,8 +574,7 @@ TEST_F(SelectionCollectionDataTest, HandlesAltLoc)
 {
     static const char * const selections[] = {
         "altloc \" \"",
-        "altloc A",
-        NULL
+        "altloc A"
     };
     runTest("simple.pdb", selections);
 }
@@ -576,8 +583,7 @@ TEST_F(SelectionCollectionDataTest, HandlesInsertCode)
 {
     static const char * const selections[] = {
         "insertcode \" \"",
-        "insertcode A",
-        NULL
+        "insertcode A"
     };
     runTest("simple.pdb", selections);
 }
@@ -586,8 +592,7 @@ TEST_F(SelectionCollectionDataTest, HandlesOccupancy)
 {
     static const char * const selections[] = {
         "occupancy 1",
-        "occupancy < .5",
-        NULL
+        "occupancy < .5"
     };
     runTest("simple.pdb", selections);
 }
@@ -596,8 +601,7 @@ TEST_F(SelectionCollectionDataTest, HandlesBeta)
 {
     static const char * const selections[] = {
         "beta 0",
-        "beta >= 0.3",
-        NULL
+        "beta >= 0.3"
     };
     runTest("simple.pdb", selections);
 }
@@ -606,8 +610,7 @@ TEST_F(SelectionCollectionDataTest, HandlesResname)
 {
     static const char * const selections[] = {
         "resname RA",
-        "resname RB RC",
-        NULL
+        "resname RB RC"
     };
     runTest("simple.gro", selections);
 }
@@ -617,8 +620,7 @@ TEST_F(SelectionCollectionDataTest, HandlesCoordinateKeywords)
     static const char * const selections[] = {
         "x < 3",
         "y >= 3",
-        "x {-1 to 2}",
-        NULL
+        "x {-1 to 2}"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -628,8 +630,7 @@ TEST_F(SelectionCollectionDataTest, HandlesCoordinateKeywords)
 TEST_F(SelectionCollectionDataTest, HandlesSameResidue)
 {
     static const char * const selections[] = {
-        "same residue as atomnr 1 4 12",
-        NULL
+        "same residue as atomnr 1 4 12"
     };
     runTest("simple.gro", selections);
 }
@@ -638,8 +639,7 @@ TEST_F(SelectionCollectionDataTest, HandlesSameResidue)
 TEST_F(SelectionCollectionDataTest, HandlesSameResidueName)
 {
     static const char * const selections[] = {
-        "same resname as atomnr 1 14",
-        NULL
+        "same resname as atomnr 1 14"
     };
     runTest("simple.gro", selections);
 }
@@ -652,8 +652,7 @@ TEST_F(SelectionCollectionDataTest, HandlesPositionKeywords)
         "res_cog of name CB and resnr 1 3",
         "whole_res_cog of name CB and resnr 1 3",
         "part_res_cog of x < 3",
-        "dyn_res_cog of x < 3",
-        NULL
+        "dyn_res_cog of x < 3"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates
              | efTestPositionAtoms);
@@ -664,8 +663,7 @@ TEST_F(SelectionCollectionDataTest, HandlesPositionKeywords)
 TEST_F(SelectionCollectionDataTest, HandlesDistanceKeyword)
 {
     static const char * const selections[] = {
-        "distance from cog of resnr 1 < 2",
-        NULL
+        "distance from cog of resnr 1 < 2"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -675,8 +673,7 @@ TEST_F(SelectionCollectionDataTest, HandlesDistanceKeyword)
 TEST_F(SelectionCollectionDataTest, HandlesMinDistanceKeyword)
 {
     static const char * const selections[] = {
-        "mindistance from resnr 1 < 2",
-        NULL
+        "mindistance from resnr 1 < 2"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -686,8 +683,7 @@ TEST_F(SelectionCollectionDataTest, HandlesMinDistanceKeyword)
 TEST_F(SelectionCollectionDataTest, HandlesWithinKeyword)
 {
     static const char * const selections[] = {
-        "within 1 of resnr 2",
-        NULL
+        "within 1 of resnr 2"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -699,8 +695,7 @@ TEST_F(SelectionCollectionDataTest, HandlesInSolidAngleKeyword)
     // Both of these should evaluate to empty on a correct implementation.
     static const char * const selections[] = {
         "resname TP and not insolidangle center cog of resname C span resname R cutoff 20",
-        "resname TN and insolidangle center cog of resname C span resname R cutoff 20",
-        NULL
+        "resname TN and insolidangle center cog of resname C span resname R cutoff 20"
     };
     setFlags(TestFlags() | efDontTestCompiledAtoms | efTestEvaluation);
     runTest("sphere.gro", selections);
@@ -712,8 +707,7 @@ TEST_F(SelectionCollectionDataTest, HandlesPermuteModifier)
     static const char * const selections[] = {
         "all permute 3 1 2",
         "res_cog of resnr 1 to 4 permute 2 1",
-        "name CB S1 and res_cog x < 3 permute 2 1",
-        NULL
+        "name CB S1 and res_cog x < 3 permute 2 1"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates
              | efTestPositionAtoms | efTestPositionMapping);
@@ -726,8 +720,7 @@ TEST_F(SelectionCollectionDataTest, HandlesPlusModifier)
     static const char * const selections[] = {
         "name S2 plus name S1",
         "res_cog of resnr 2 plus res_cog of resnr 1 plus res_cog of resnr 3",
-        "name S1 and y < 3 plus res_cog of x < 2.5",
-        NULL
+        "name S1 and y < 3 plus res_cog of x < 2.5"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates
              | efTestPositionAtoms | efTestPositionMapping);
@@ -740,8 +733,7 @@ TEST_F(SelectionCollectionDataTest, HandlesMergeModifier)
     static const char * const selections[] = {
         "name S2 merge name S1",
         "resnr 1 2 and name S2 merge resnr 1 2 and name S1 merge res_cog of resnr 1 2",
-        "name S1 and x < 2.5 merge res_cog of x < 2.5",
-        NULL
+        "name S1 and x < 2.5 merge res_cog of x < 2.5"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates
              | efTestPositionAtoms | efTestPositionMapping);
@@ -756,8 +748,7 @@ TEST_F(SelectionCollectionDataTest, HandlesMergeModifier)
 TEST_F(SelectionCollectionDataTest, HandlesConstantPositions)
 {
     static const char * const selections[] = {
-        "[1, -2, 3.5]",
-        NULL
+        "[1, -2, 3.5]"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -767,8 +758,7 @@ TEST_F(SelectionCollectionDataTest, HandlesConstantPositions)
 TEST_F(SelectionCollectionDataTest, HandlesWithinConstantPositions)
 {
     static const char * const selections[] = {
-        "within 1 of [2, 1, 0]",
-        NULL
+        "within 1 of [2, 1, 0]"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -779,8 +769,7 @@ TEST_F(SelectionCollectionDataTest, HandlesForcedStringMatchingMode)
 {
     static const char * const selections[] = {
         "name = S1 \"C?\"",
-        "name ? S1 \"C?\"",
-        NULL
+        "name ? S1 \"C?\""
     };
     runTest("simple.gro", selections);
 }
@@ -790,8 +779,7 @@ TEST_F(SelectionCollectionDataTest, HandlesWildcardMatching)
 {
     static const char * const selections[] = {
         "name \"S?\"",
-        "name ? \"S?\"",
-        NULL
+        "name ? \"S?\""
     };
     runTest("simple.gro", selections);
 }
@@ -801,8 +789,7 @@ TEST_F(SelectionCollectionDataTest, HandlesRegexMatching)
 {
     static const char * const selections[] = {
         "resname \"R[BD]\"",
-        "resname ~ \"R[BD]\"",
-        NULL
+        "resname ~ \"R[BD]\""
     };
     if (gmx::Regex::isSupported())
     {
@@ -818,8 +805,7 @@ TEST_F(SelectionCollectionDataTest, HandlesBasicBoolean)
         "atomnr 1 to 5 or not atomnr 3 to 8",
         "not not atomnr 1 to 5 and atomnr 2 to 6 and not not atomnr 3 to 7",
         "atomnr 1 to 5 and (atomnr 2 to 7 and atomnr 3 to 6)",
-        "x < 5 and atomnr 1 to 5 and y < 3 and atomnr 2 to 4",
-        NULL
+        "x < 5 and atomnr 1 to 5 and y < 3 and atomnr 2 to 4"
     };
     runTest(10, selections);
 }
@@ -832,8 +818,7 @@ TEST_F(SelectionCollectionDataTest, HandlesNumericComparisons)
         "2 < x",
         "y > resnr",
         "resnr < 2.5",
-        "2.5 > resnr",
-        NULL
+        "2.5 > resnr"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -846,8 +831,7 @@ TEST_F(SelectionCollectionDataTest, HandlesArithmeticExpressions)
         "x+1 > 3",
         "(y-1)^2 <= 1",
         "x+--1 > 3",
-        "-x+-1 < -3",
-        NULL
+        "-x+-1 < -3"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -860,8 +844,7 @@ TEST_F(SelectionCollectionDataTest, HandlesNumericVariables)
         "value = x + y",
         "value <= 4",
         "index = resnr",
-        "index < 3",
-        NULL
+        "index < 3"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -876,8 +859,7 @@ TEST_F(SelectionCollectionDataTest, HandlesComplexNumericVariables)
         "resname RA RB and x < 3 and value <= 4",
         "index = atomnr",
         "resname RA and index < 3",
-        "resname RB and y < 3 and index < 6",
-        NULL
+        "resname RB and y < 3 and index < 6"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -892,8 +874,7 @@ TEST_F(SelectionCollectionDataTest, HandlesPositionVariables)
         "within 1 of foo",
         "bar = cog of resname RA",
         "bar",
-        "within 1 of bar",
-        NULL
+        "within 1 of bar"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -905,8 +886,7 @@ TEST_F(SelectionCollectionDataTest, HandlesConstantPositionInVariable)
     static const char * const selections[] = {
         "constpos = [1.0, 2.5, 0.5]",
         "constpos",
-        "within 2 of constpos",
-        NULL
+        "within 2 of constpos"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates
             | efTestPositionAtoms);
@@ -921,8 +901,7 @@ TEST_F(SelectionCollectionDataTest, HandlesNumericConstantsInVariables)
         "constreal1 = 0.5",
         "constreal2 = 2.7",
         "resnr < constint",
-        "x + constreal1 < constreal2",
-        NULL
+        "x + constreal1 < constreal2"
     };
     setFlags(TestFlags() | efTestEvaluation | efTestPositionCoordinates);
     runTest("simple.gro", selections);
@@ -940,8 +919,7 @@ TEST_F(SelectionCollectionDataTest, HandlesBooleanStaticAnalysis)
         "atomnr 1 to 5 and (atomnr 4 to 7 or x < 2)",
         "atomnr 1 to 5 and y < 3 and (atomnr 4 to 7 or x < 2)",
         "atomnr 1 to 5 and not (atomnr 4 to 7 or x < 2)",
-        "atomnr 1 to 5 or (atomnr 4 to 6 and (atomnr 5 to 7 or x < 2))",
-        NULL
+        "atomnr 1 to 5 or (atomnr 4 to 6 and (atomnr 5 to 7 or x < 2))"
     };
     runTest(10, selections);
 }
@@ -953,8 +931,7 @@ TEST_F(SelectionCollectionDataTest, HandlesBooleanStaticAnalysisWithVariables)
         "foo = atomnr 4 to 7 or x < 2",
         "atomnr 1 to 4 and foo",
         "atomnr 2 to 6 and y < 3 and foo",
-        "atomnr 6 to 10 and not foo",
-        NULL
+        "atomnr 6 to 10 and not foo"
     };
     runTest(10, selections);
 }
@@ -968,8 +945,7 @@ TEST_F(SelectionCollectionDataTest, HandlesBooleanStaticAnalysisWithMoreVariable
         "bar2 = foo and y < 2",
         "atomnr 1 to 4 and bar",
         "atomnr 2 to 6 and y < 3 and bar2",
-        "atomnr 6 to 10 and not foo",
-        NULL
+        "atomnr 6 to 10 and not foo"
     };
     runTest(10, selections);
 }
@@ -988,8 +964,7 @@ TEST_F(SelectionCollectionDataTest, HandlesUnusedVariables)
         "unused1 = atomnr 1 to 3",
         "foo = atomnr 4 to 7",
         "atomnr 1 to 6 and foo",
-        "unused2 = atomnr 3 to 5",
-        NULL
+        "unused2 = atomnr 3 to 5"
     };
     runTest(10, selections);
 }
@@ -1000,8 +975,7 @@ TEST_F(SelectionCollectionDataTest, HandlesVariablesWithStaticEvaluationGroups)
     static const char * const selections[] = {
         "foo = atomnr 4 to 7 and x < 2",
         "atomnr 1 to 5 and foo",
-        "atomnr 3 to 7 and foo",
-        NULL
+        "atomnr 3 to 7 and foo"
     };
     runTest(10, selections);
 }
@@ -1013,8 +987,7 @@ TEST_F(SelectionCollectionDataTest, HandlesVariablesWithMixedEvaluationGroups)
         "foo = atomnr 4 to 7 and x < 2",
         "atomnr 1 to 6 and foo",
         "within 1 of foo",
-        "foo",
-        NULL
+        "foo"
     };
     runTest(10, selections);
 }
index 4f0d4654c07ef6f0881f986b5187d4f1577ba38a..ab940c403e5450700364959cd16fa7f59ac37758 100644 (file)
@@ -77,36 +77,38 @@ AnalysisDataTestInputFrame::AnalysisDataTestInputFrame(int index, real x)
  * AnalysisDataTestInput
  */
 
-AnalysisDataTestInput::AnalysisDataTestInput(const real *data)
-    : columnCount_(0), bMultipoint_(false)
+void AnalysisDataTestInput::initFromArray(const real *data, size_t count)
 {
     size_t columns = 0;
-    const real *dataptr = data;
 
-    while (*dataptr != END_OF_DATA)
+    for (size_t i = 0; i < count; ++i)
     {
-        frames_.push_back(AnalysisDataTestInputFrame(frames_.size(), *dataptr));
+        if (data[i] == MPSTOP)
+        {
+            bMultipoint_ = true;
+            break;
+        }
+    }
+    for (size_t i = 0; i < count; )
+    {
+        frames_.push_back(AnalysisDataTestInputFrame(frames_.size(), data[i]));
         AnalysisDataTestInputFrame &frame = frames_.back();
-        GMX_RELEASE_ASSERT(*dataptr != END_OF_FRAME && *dataptr != MPSTOP,
+        GMX_RELEASE_ASSERT(data[i] != END_OF_FRAME && data[i] != MPSTOP,
                            "Empty data frame");
-        while (*dataptr != END_OF_FRAME)
+        while (data[i] != END_OF_FRAME)
         {
-            ++dataptr;
+            ++i;
             frame.points_.push_back(AnalysisDataTestInputPointSet());
             AnalysisDataTestInputPointSet &points = frame.points_.back();
-            while (*dataptr != MPSTOP && *dataptr != END_OF_FRAME)
+            while (data[i] != MPSTOP && data[i] != END_OF_FRAME)
             {
-                GMX_RELEASE_ASSERT(*dataptr != END_OF_DATA,
-                                   "Premature end of data marker");
-                points.y_.push_back(*dataptr);
-                ++dataptr;
+                GMX_RELEASE_ASSERT(i < count,
+                                   "Premature end of data");
+                points.y_.push_back(data[i]);
+                ++i;
             }
             size_t frameColumns = points.y_.size();
             GMX_RELEASE_ASSERT(frameColumns > 0U, "Empty data point set");
-            if (*dataptr == MPSTOP)
-            {
-                bMultipoint_ = true;
-            }
             GMX_RELEASE_ASSERT(!(!bMultipoint_ && columns > 0U && columns != frameColumns),
                                "Different frames have different number of columns");
             if (columns < frameColumns)
@@ -114,9 +116,9 @@ AnalysisDataTestInput::AnalysisDataTestInput(const real *data)
                 columns = frameColumns;
             }
         }
-        ++dataptr;
+        ++i;
     }
-    GMX_RELEASE_ASSERT(frames_.size() > 0U, "Empty data");
+    GMX_RELEASE_ASSERT(!frames_.empty(), "Empty data");
     columnCount_ = columns;
 }
 
index a41e808630671733137bef13d316e1676de0310c..daeb79e0004fe0d3d7c9b0f993b7810317ec4b47 100644 (file)
@@ -60,10 +60,8 @@ class AnalysisDataHandle;
 namespace test
 {
 
-//! Constant to use to signify end of data for AnalysisDataTestInput.
-const real END_OF_DATA = std::numeric_limits<real>::max();
 //! Constant to use to signify end of one data frame for AnalysisDataTestInput.
-const real END_OF_FRAME = std::numeric_limits<real>::min();
+const real END_OF_FRAME = std::numeric_limits<real>::max();
 //! Constant to use to signify end of one multipoint set for AnalysisDataTestInput.
 const real MPSTOP = -std::numeric_limits<real>::max();
 
@@ -155,6 +153,7 @@ class AnalysisDataTestInput
         /*! \brief
          * Constructs data representation from a simple array.
          *
+         * \tparam    count Number of elements in the array.
          * \param[in] data  Array to construct data from.
          *
          * The input array should consist of a set of frames, separated by a
@@ -166,10 +165,14 @@ class AnalysisDataTestInput
          * assumed to start from column zero, but the sets may contain
          * different number of columns.  For non-multipoint data, all frames
          * must containt the same number of columns.
-         * The final element in the array (after the last END_OF_FRAME) should
-         * be END_OF_DATA.
+         * The final element in the array should be an END_OF_FRAME.
          */
-        explicit AnalysisDataTestInput(const real *data);
+        template <size_t count>
+        explicit AnalysisDataTestInput(const real (&data)[count])
+            : columnCount_(0), bMultipoint_(false)
+        {
+            initFromArray(data, count);
+        }
         ~AnalysisDataTestInput();
 
         //! Returns the number of frames in the input data.
@@ -182,6 +185,8 @@ class AnalysisDataTestInput
         const AnalysisDataTestInputFrame &frame(int index) const;
 
     private:
+        void initFromArray(const real *data, size_t count);
+
         int                     columnCount_;
         bool                    bMultipoint_;
         std::vector<AnalysisDataTestInputFrame> frames_;