Skip to content

Commit e371219

Browse files
committed
Fix incorrect calculation of max in QgsStatisticalSummary
1 parent 6a312be commit e371219

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/core/qgsstatisticalsummary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void QgsStatisticalSummary::reset()
3636
mMean = 0;
3737
mMedian = 0;
3838
mMin = std::numeric_limits<double>::max();
39-
mMax = std::numeric_limits<double>::min();
39+
mMax = -std::numeric_limits<double>::max();
4040
mStdev = 0;
4141
mSampleStdev = 0;
4242
mMinority = 0;

tests/src/core/testqgsstatisticalsummary.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class TestQgsStatisticSummary: public QObject
3232
void init();// will be called before each testfunction is executed.
3333
void cleanup();// will be called after every testfunction.
3434
void stats();
35+
void maxMin();
3536

3637
private:
3738

@@ -119,5 +120,18 @@ void TestQgsStatisticSummary::stats()
119120
QCOMPARE( s.interQuartileRange(), 11.0 );
120121
}
121122

123+
void TestQgsStatisticSummary::maxMin()
124+
{
125+
QgsStatisticalSummary s( QgsStatisticalSummary::All );
126+
127+
//test max/min of negative value list
128+
QList<double> negativeVals;
129+
negativeVals << -5.0 << -10.0 << -15.0;
130+
s.calculate( negativeVals );
131+
132+
QCOMPARE( s.min(), -15.0 );
133+
QCOMPARE( s.max(), -5.0 );
134+
}
135+
122136
QTEST_MAIN( TestQgsStatisticSummary )
123137
#include "testqgsstatisticalsummary.moc"

0 commit comments

Comments
 (0)