Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix incorrect calculation of max in QgsStatisticalSummary
  • Loading branch information
nyalldawson committed May 10, 2015
1 parent 6a312be commit e371219
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgsstatisticalsummary.cpp
Expand Up @@ -36,7 +36,7 @@ void QgsStatisticalSummary::reset()
mMean = 0;
mMedian = 0;
mMin = std::numeric_limits<double>::max();
mMax = std::numeric_limits<double>::min();
mMax = -std::numeric_limits<double>::max();
mStdev = 0;
mSampleStdev = 0;
mMinority = 0;
Expand Down
14 changes: 14 additions & 0 deletions tests/src/core/testqgsstatisticalsummary.cpp
Expand Up @@ -32,6 +32,7 @@ class TestQgsStatisticSummary: public QObject
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void stats();
void maxMin();

private:

Expand Down Expand Up @@ -119,5 +120,18 @@ void TestQgsStatisticSummary::stats()
QCOMPARE( s.interQuartileRange(), 11.0 );
}

void TestQgsStatisticSummary::maxMin()
{
QgsStatisticalSummary s( QgsStatisticalSummary::All );

//test max/min of negative value list
QList<double> negativeVals;
negativeVals << -5.0 << -10.0 << -15.0;
s.calculate( negativeVals );

QCOMPARE( s.min(), -15.0 );
QCOMPARE( s.max(), -5.0 );
}

QTEST_MAIN( TestQgsStatisticSummary )
#include "testqgsstatisticalsummary.moc"

0 comments on commit e371219

Please sign in to comment.