Changeset 37ec1b
- Timestamp:
- Apr 15, 2010, 3:05:18 PM (15 years ago)
- Children:
- ce0de8
- Parents:
- e34098
- Location:
- util/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
util/src/average.cpp
re34098 r37ec1b 10 10 #include <iostream> 11 11 #include <iomanip> 12 #include <math.h> 12 13 #include <string> 13 14 #include <sstream> … … 59 60 } 60 61 // skip to next desired column 62 tmp = 0.; 61 63 for(;cols!=*ColRunner;++cols) 62 64 if (!line.eof()) // check for end of line … … 113 115 lines++; 114 116 // go through the columns 115 cols = 0;117 cols = -1; 116 118 for (IndexSet::const_iterator ColRunner = Columns.begin(); ColRunner != Columns.end(); ++ColRunner) { 117 119 // skip to next desired column 120 tmp = 0.; 118 121 for(;cols!=*ColRunner;++cols) 119 122 if (!line.eof()) // check for end of line … … 132 135 // go through each value in Results and take std deviation 133 136 for (MeanErrorMap::iterator Runner = Values->begin(); Runner != Values->end(); ++Runner) 134 if (CountMap[Runner->first] != 0) 135 Runner->second.second /= CountMap[Runner->first]; 136 else 137 if (CountMap[Runner->first] != 0) { 138 tmp = Runner->second.second; 139 Runner->second.second = sqrt(tmp)/CountMap[Runner->first]; 140 } else 137 141 cerr << "For column " << CountMap[Runner->first] << " no entries have been found." << endl; 138 142 -
util/src/unittests/AverageColumnsUnitTest.cpp
re34098 r37ec1b 11 11 #include <cppunit/extensions/TestFactoryRegistry.h> 12 12 #include <cppunit/ui/text/TestRunner.h> 13 14 #include <math.h> 13 15 14 16 #include "../average.hpp" … … 36 38 /** UnitTest for calculations in AverageColumns(). 37 39 */ 38 void AverageColumnsTest:: CalculationsTest()40 void AverageColumnsTest::SimpleCalculationsTest() 39 41 { 40 // fill stream41 42 input.str("1\n1\n1\n"); 42 43 Columns.insert(0); … … 47 48 CPPUNIT_ASSERT_EQUAL( 1., mean ); 48 49 CPPUNIT_ASSERT_EQUAL( 0., dev ); 49 }; 50 } 51 52 /** UnitTest for some real calculations in AverageColumns(). 53 */ 54 void AverageColumnsTest::CalculationsTest() 55 { 56 MeanErrorMap::iterator Runner; 57 input.clear(); 58 input.str("1.\t1.\n2.\t3.\n3.\t5.\n"); 59 Columns.insert(0); 60 Columns.insert(1); 61 Results = AverageColumns(input, Columns); 62 Runner = Results->begin(); 63 CPPUNIT_ASSERT ( Runner != Results->end() ); 64 CPPUNIT_ASSERT_EQUAL( 2., (*Runner).second.first ); 65 CPPUNIT_ASSERT_EQUAL( sqrt(2)/3., (*Runner).second.second ); 66 Runner++; 67 CPPUNIT_ASSERT ( Runner != Results->end() ); 68 CPPUNIT_ASSERT_EQUAL( 3., (*Runner).second.first ); 69 CPPUNIT_ASSERT_EQUAL( sqrt(8.)/3., (*Runner).second.second ); 70 } 50 71 51 72 /** UnitTest for too few columns in AverageColumns(). -
util/src/unittests/AverageColumnsUnitTest.hpp
re34098 r37ec1b 16 16 { 17 17 CPPUNIT_TEST_SUITE( AverageColumnsTest) ; 18 CPPUNIT_TEST ( CalculationsTest );19 18 CPPUNIT_TEST ( NoRowsTest ); 20 19 CPPUNIT_TEST ( MissingColumnsTest ); 20 CPPUNIT_TEST ( SimpleCalculationsTest ); 21 CPPUNIT_TEST ( CalculationsTest ); 21 22 CPPUNIT_TEST_SUITE_END(); 22 23 … … 24 25 void setUp(); 25 26 void tearDown(); 26 void CalculationsTest();27 27 void MissingColumnsTest(); 28 28 void NoRowsTest(); 29 void SimpleCalculationsTest(); 30 void CalculationsTest(); 29 31 30 32 private:
Note:
See TracChangeset
for help on using the changeset viewer.