Skip to content
Permalink
Browse files

update tests for new algorithms

  • Loading branch information
root676 authored and nyalldawson committed Jul 28, 2020
1 parent 2a7dc93 commit 7066a87d1a8e3a312b3370fa7bc3e19f3d1bfc66
Showing with 114 additions and 14 deletions.
  1. +114 −14 tests/src/analysis/testqgsprocessingalgs.cpp
@@ -102,8 +102,8 @@ class TestQgsProcessingAlgs: public QObject
void rasterLogicOp();
void cellStatistics_data();
void cellStatistics();
void equalToFrequency_data();
void equalToFrequency();
void rasterFrequencyByComparisonOperator_data();
void rasterFrequencyByComparisonOperator();
void roundRasterValues_data();
void roundRasterValues();

@@ -2269,8 +2269,9 @@ void TestQgsProcessingAlgs::cellStatistics()
}
}

void TestQgsProcessingAlgs::equalToFrequency_data()
void TestQgsProcessingAlgs::rasterFrequencyByComparisonOperator_data()
{
QTest::addColumn<QString>( "algName" );
QTest::addColumn<QString>( "inputValueRaster" );
QTest::addColumn<int>( "inputValueRasterBand" );
QTest::addColumn<QStringList>( "inputRasters" );
@@ -2279,51 +2280,150 @@ void TestQgsProcessingAlgs::equalToFrequency_data()
QTest::addColumn<Qgis::DataType>( "expectedDataType" );

/*
* Testcase 1: don't ignore NoData
* Testcase 1 - equal to frequency: don't ignore NoData
*/
QTest::newRow( "testcase_1" )
<< QStringLiteral( "native:equaltofrequency")
<< QStringLiteral( "/raster/valueRas1_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/equalToFrequencyTest1.tif" )
<< QStringLiteral( "/expected_equalToFrequency/equalToFrequencyTest1.tif" )
<< Qgis::Int32;
/*
* Testcase 2: ignore NoData
* Testcase 2 - equal to frequency: ignore NoData
*/
QTest::newRow( "testcase_2" )
<< QStringLiteral( "native:equaltofrequency")
<< QStringLiteral( "/raster/valueRas1_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< true
<< QStringLiteral( "/equalToFrequencyTest2.tif" )
<< QStringLiteral( "/expected_equalToFrequency/equalToFrequencyTest2.tif" )
<< Qgis::Int32;

/*
* Testcase 3: NoData in value raster
* Testcase 3 - equal to frequency: NoData in value raster
*/
QTest::newRow( "testcase_3" )
<< QStringLiteral( "native:equaltofrequency")
<< QStringLiteral( "/raster/valueRas2_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/equalToFrequencyTest3.tif" )
<< QStringLiteral( "/expected_equalToFrequency/equalToFrequencyTest3.tif" )
<< Qgis::Int32;

/*
* Testcase 4: test with random byte raster
* Testcase 4 - equal to frequency: test with random byte raster
*/
QTest::newRow( "testcase_4" )
<< QStringLiteral( "native:equaltofrequency")
<< QStringLiteral( "/raster/valueRas3_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/equalToFrequencyTest4.tif" )
<< QStringLiteral( "/expected_equalToFrequency/equalToFrequencyTest4.tif" )
<< Qgis::Int32;

/*
* Testcase 5 - greater than frequency: don't ignore NoData
*/
QTest::newRow( "testcase_5" )
<< QStringLiteral( "native:greaterthanfrequency")
<< QStringLiteral( "/raster/valueRas1_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/expected_greaterThanFrequency/greaterThanFrequencyTest1.tif" )
<< Qgis::Int32;
/*
* Testcase 6 - greater than frequency: ignore NoData
*/
QTest::newRow( "testcase_6" )
<< QStringLiteral( "native:greaterthanfrequency")
<< QStringLiteral( "/raster/valueRas1_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< true
<< QStringLiteral( "/expected_greaterThanFrequency/greaterThanFrequencyTest2.tif" )
<< Qgis::Int32;

/*
* Testcase 7 - greater than frequency: NoData in value raster
*/
QTest::newRow( "testcase_7" )
<< QStringLiteral( "native:greaterthanfrequency")
<< QStringLiteral( "/raster/valueRas2_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/expected_greaterThanFrequency/greaterThanFrequencyTest3.tif" )
<< Qgis::Int32;

/*
* Testcase 8 - greater than frequency: test with random byte raster
*/
QTest::newRow( "testcase_8" )
<< QStringLiteral( "native:greaterthanfrequency")
<< QStringLiteral( "/raster/valueRas3_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/expected_greaterThanFrequency/greaterThanFrequencyTest4.tif" )
<< Qgis::Int32;

/*
* Testcase 9 - less than frequency: don't ignore NoData
*/
QTest::newRow( "testcase_9" )
<< QStringLiteral( "native:lessthanfrequency")
<< QStringLiteral( "/raster/valueRas1_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/expected_lessThanFrequency/lessThanFrequencyTest1.tif" )
<< Qgis::Int32;
/*
* Testcase 10 - greater than frequency: ignore NoData
*/
QTest::newRow( "testcase_10" )
<< QStringLiteral( "native:lessthanfrequency")
<< QStringLiteral( "/raster/valueRas1_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< true
<< QStringLiteral( "/expected_lessThanFrequency/lessThanFrequencyTest2.tif" )
<< Qgis::Int32;

/*
* Testcase 11 - less than frequency: NoData in value raster
*/
QTest::newRow( "testcase_11" )
<< QStringLiteral( "native:lessthanfrequency")
<< QStringLiteral( "/raster/valueRas2_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/expected_lessThanFrequency/lessThanFrequencyTest3.tif" )
<< Qgis::Int32;

/*
* Testcase 12 - less than frequency: test with random byte raster
*/
QTest::newRow( "testcase_12" )
<< QStringLiteral( "native:lessthanfrequency")
<< QStringLiteral( "/raster/valueRas3_float64.asc" )
<< 1
<< QStringList( {"/raster/statisticsRas1_float64.asc", "/raster/statisticsRas2_float64.asc", "/raster/statisticsRas3_float64.asc"} )
<< false
<< QStringLiteral( "/expected_lessThanFrequency/lessThanFrequencyTest4.tif" )
<< Qgis::Int32;
}

void TestQgsProcessingAlgs::equalToFrequency()
void TestQgsProcessingAlgs::rasterFrequencyByComparisonOperator()
{
QFETCH( QString, algName);
QFETCH( QString, inputValueRaster );
QFETCH( int, inputValueRasterBand );
QFETCH( QStringList, inputRasters );
@@ -2333,7 +2433,7 @@ void TestQgsProcessingAlgs::equalToFrequency()

//prepare input params
QgsProject p;
std::unique_ptr< QgsProcessingAlgorithm > alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:equaltofrequency" ) ) );
std::unique_ptr< QgsProcessingAlgorithm > alg( QgsApplication::processingRegistry()->createAlgorithmById( algName ) );

QString myDataPath( TEST_DATA_DIR ); //defined in CmakeLists.txt

@@ -2362,7 +2462,7 @@ void TestQgsProcessingAlgs::equalToFrequency()
parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT );

//prepare expectedRaster
std::unique_ptr<QgsRasterLayer> expectedRasterLayer = qgis::make_unique< QgsRasterLayer >( myDataPath + "/control_images/expected_equalToFrequency/" + expectedRaster, "expectedDataset", "gdal" );
std::unique_ptr<QgsRasterLayer> expectedRasterLayer = qgis::make_unique< QgsRasterLayer >( myDataPath + "/control_images" + expectedRaster, "expectedDataset", "gdal" );
std::unique_ptr< QgsRasterInterface > expectedInterface( expectedRasterLayer->dataProvider()->clone() );
QgsRasterIterator expectedIter( expectedInterface.get() );
expectedIter.startRasterRead( 1, expectedRasterLayer->width(), expectedRasterLayer->height(), expectedInterface->extent() );

0 comments on commit 7066a87

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