Skip to content
Permalink
Browse files

Bump QgsStatisticSummary test coverage

  • Loading branch information
nyalldawson committed Nov 12, 2015
1 parent 6e1df49 commit dfb1585c49027a8d6142795c5f2642ef7f16cac2
Showing with 47 additions and 0 deletions.
  1. +47 −0 tests/src/core/testqgsstatisticalsummary.cpp
@@ -32,6 +32,8 @@ 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 individualStatCalculations_data();
void individualStatCalculations();
void maxMin();

private:
@@ -120,6 +122,51 @@ void TestQgsStatisticSummary::stats()
QCOMPARE( s.interQuartileRange(), 11.0 );
}

void TestQgsStatisticSummary::individualStatCalculations_data()
{
QTest::addColumn< int >( "statInt" );
QTest::addColumn<double>( "expected" );

QTest::newRow( "count" ) << ( int )QgsStatisticalSummary::Count << 10.0;
QTest::newRow( "sum" ) << ( int )QgsStatisticalSummary::Sum << 45.0;
QTest::newRow( "mean" ) << ( int )QgsStatisticalSummary::Mean << 4.5;
QTest::newRow( "median" ) << ( int )QgsStatisticalSummary::Median << 4.0;
QTest::newRow( "st_dev" ) << ( int )QgsStatisticalSummary::StDev << 1.96214;
QTest::newRow( "st_dev_sample" ) << ( int )QgsStatisticalSummary::StDevSample << 2.06828;
QTest::newRow( "min" ) << ( int )QgsStatisticalSummary::Min << 2.0;
QTest::newRow( "max" ) << ( int )QgsStatisticalSummary::Max << 8.0;
QTest::newRow( "range" ) << ( int )QgsStatisticalSummary::Range << 6.0;
QTest::newRow( "minority" ) << ( int )QgsStatisticalSummary::Minority << 2.0;
QTest::newRow( "majority" ) << ( int )QgsStatisticalSummary::Majority << 3.0;
QTest::newRow( "variety" ) << ( int )QgsStatisticalSummary::Variety << 5.0;
QTest::newRow( "first_quartile" ) << ( int )QgsStatisticalSummary::FirstQuartile << 3.0;
QTest::newRow( "third_quartile" ) << ( int )QgsStatisticalSummary::ThirdQuartile << 5.0;
QTest::newRow( "iqr" ) << ( int )QgsStatisticalSummary::InterQuartileRange << 2.0;
}

void TestQgsStatisticSummary::individualStatCalculations()
{
//tests calculation of statistics one at a time, to make sure statistic calculations are not
//dependant on each other

QList<double> values;
values << 4 << 4 << 2 << 3 << 3 << 3 << 5 << 5 << 8 << 8;

QFETCH( int, statInt );
QgsStatisticalSummary::Statistic stat = ( QgsStatisticalSummary::Statistic ) statInt;
QFETCH( double, expected );

QgsStatisticalSummary s;
s.setStatistics( stat );
QCOMPARE( s.statistics(), stat );

s.calculate( values );
QVERIFY( qgsDoubleNear( s.statistic( stat ), expected, 0.00001 ) );

//make sure stat has a valid display name
QVERIFY( !QgsStatisticalSummary::displayName( stat ).isEmpty() );
}

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

0 comments on commit dfb1585

Please sign in to comment.
You can’t perform that action at this time.