Changeset 37ec1b


Ignore:
Timestamp:
Apr 15, 2010, 3:05:18 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Children:
ce0de8
Parents:
e34098
Message:

BUGFIX: Extended AverageColumnsUnitTest, found one bug in AverageColumns.

Location:
util/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • util/src/average.cpp

    re34098 r37ec1b  
    1010#include <iostream>
    1111#include <iomanip>
     12#include <math.h>
    1213#include <string>
    1314#include <sstream>
     
    5960      }
    6061      // skip to next desired column
     62      tmp = 0.;
    6163      for(;cols!=*ColRunner;++cols)
    6264        if (!line.eof()) // check for end of line
     
    113115    lines++;
    114116    // go through the columns
    115     cols = 0;
     117    cols = -1;
    116118    for (IndexSet::const_iterator ColRunner = Columns.begin(); ColRunner != Columns.end(); ++ColRunner) {
    117119      // skip to next desired column
     120      tmp = 0.;
    118121      for(;cols!=*ColRunner;++cols)
    119122        if (!line.eof()) // check for end of line
     
    132135  // go through each value in Results and take std deviation
    133136  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
    137141      cerr << "For column " << CountMap[Runner->first] << " no entries have been found." << endl;
    138142
  • util/src/unittests/AverageColumnsUnitTest.cpp

    re34098 r37ec1b  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13
     14#include <math.h>
    1315
    1416#include "../average.hpp"
     
    3638/** UnitTest for calculations in AverageColumns().
    3739 */
    38 void AverageColumnsTest::CalculationsTest()
     40void AverageColumnsTest::SimpleCalculationsTest()
    3941{
    40   // fill stream
    4142  input.str("1\n1\n1\n");
    4243  Columns.insert(0);
     
    4748  CPPUNIT_ASSERT_EQUAL( 1., mean );
    4849  CPPUNIT_ASSERT_EQUAL( 0., dev );
    49 };
     50}
     51
     52/** UnitTest for some real calculations in AverageColumns().
     53 */
     54void 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}
    5071
    5172/** UnitTest for too few columns in AverageColumns().
  • util/src/unittests/AverageColumnsUnitTest.hpp

    re34098 r37ec1b  
    1616{
    1717    CPPUNIT_TEST_SUITE( AverageColumnsTest) ;
    18     CPPUNIT_TEST ( CalculationsTest );
    1918    CPPUNIT_TEST ( NoRowsTest );
    2019    CPPUNIT_TEST ( MissingColumnsTest );
     20    CPPUNIT_TEST ( SimpleCalculationsTest );
     21    CPPUNIT_TEST ( CalculationsTest );
    2122    CPPUNIT_TEST_SUITE_END();
    2223
     
    2425      void setUp();
    2526      void tearDown();
    26       void CalculationsTest();
    2727      void MissingColumnsTest();
    2828      void NoRowsTest();
     29      void SimpleCalculationsTest();
     30      void CalculationsTest();
    2931
    3032private:
Note: See TracChangeset for help on using the changeset viewer.