Skip to content
Permalink
Browse files

Rework failing test for better debug output

  • Loading branch information
nyalldawson committed Feb 5, 2021
1 parent e47fbd7 commit d2be3ca772cd8351834d07c945693fab36efb155
Showing with 27 additions and 22 deletions.
  1. +27 −22 tests/src/core/testqgsgeometry.cpp
@@ -151,6 +151,7 @@ class TestQgsGeometry : public QObject

void makeValid();

void isSimple_data();
void isSimple();

void reshapeGeometryLineMerge();
@@ -17649,31 +17650,35 @@ void TestQgsGeometry::makeValid()
}
}

void TestQgsGeometry::isSimple_data()
{
QTest::addColumn<QString>( "wkt" );
QTest::addColumn<bool>( "simple" );

QTest::newRow( "linestring" ) << QStringLiteral( "LINESTRING(0 0, 1 0, 1 1)" ) << true;
QTest::newRow( "may be closed (linear ring)" ) << QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0 0)" ) << true;
QTest::newRow( "self-intersection" ) << QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0 -1)" ) << false;
QTest::newRow( "self-tangency" ) << QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0.5 0, 0 1)" ) << false;
QTest::newRow( "points are simple" ) << QStringLiteral( "POINT(1 1)" ) << true;
QTest::newRow( "polygons are always simple, even if they are invalid" ) << QStringLiteral( "POLYGON((0 0, 1 1, 1 1, 0 0))" ) << true;
QTest::newRow( "multipoint" ) << QStringLiteral( "MULTIPOINT((1 1), (2 2))" ) << true;
QTest::newRow( "must not contain the same point twice" ) << QStringLiteral( "MULTIPOINT((1 1), (1 1))" ) << false;
QTest::newRow( "multiline string simple" ) << QStringLiteral( "MULTILINESTRING((0 0, 1 0), (0 1, 1 1))" ) << true;
QTest::newRow( "may be touching at endpoints" ) << QStringLiteral( "MULTILINESTRING((0 0, 1 0), (0 0, 1 0))" ) << true;
QTest::newRow( "must not intersect each other" ) << QStringLiteral( "MULTILINESTRING((0 0, 1 1), (0 1, 1 0))" ) << false;
QTest::newRow( "multi-polygons are always simple" ) << QStringLiteral( "MULTIPOLYGON(((0 0, 1 1, 1 1, 0 0)),((0 0, 1 1, 1 1, 0 0)))" ) << true;
}

void TestQgsGeometry::isSimple()
{
typedef QPair<QString, bool> InputWktAndExpectedResult;
QList<InputWktAndExpectedResult> geoms;
geoms << qMakePair( QStringLiteral( "LINESTRING(0 0, 1 0, 1 1)" ), true );
geoms << qMakePair( QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0 0)" ), true ); // may be closed (linear ring)
geoms << qMakePair( QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0 -1)" ), false ); // self-intersection
geoms << qMakePair( QStringLiteral( "LINESTRING(0 0, 1 0, 1 1, 0.5 0, 0 1)" ), false ); // self-tangency
geoms << qMakePair( QStringLiteral( "POINT(1 1)" ), true ); // points are simple
geoms << qMakePair( QStringLiteral( "POLYGON((0 0, 1 1, 1 1, 0 0))" ), true ); // polygons are always simple, even if they are invalid
geoms << qMakePair( QStringLiteral( "MULTIPOINT((1 1), (2 2))" ), true );
geoms << qMakePair( QStringLiteral( "MULTIPOINT((1 1), (1 1))" ), false ); // must not contain the same point twice
geoms << qMakePair( QStringLiteral( "MULTILINESTRING((0 0, 1 0), (0 1, 1 1))" ), true );
geoms << qMakePair( QStringLiteral( "MULTILINESTRING((0 0, 1 0), (0 0, 1 0))" ), true ); // may be touching at endpoints
geoms << qMakePair( QStringLiteral( "MULTILINESTRING((0 0, 1 1), (0 1, 1 0))" ), false ); // must not intersect each other
geoms << qMakePair( QStringLiteral( "MULTIPOLYGON(((0 0, 1 1, 1 1, 0 0)),((0 0, 1 1, 1 1, 0 0)))" ), true ); // multi-polygons are always simple

Q_FOREACH ( const InputWktAndExpectedResult &pair, geoms )
{
QgsGeometry gInput = QgsGeometry::fromWkt( pair.first );
QVERIFY( !gInput.isNull() );
QFETCH( QString, wkt );
QFETCH( bool, simple );

bool res = gInput.isSimple();
QCOMPARE( res, pair.second );
}
QgsGeometry gInput = QgsGeometry::fromWkt( wkt );
QVERIFY( !gInput.isNull() );

bool res = gInput.isSimple();
QCOMPARE( res, simple );
}

void TestQgsGeometry::reshapeGeometryLineMerge()

0 comments on commit d2be3ca

Please sign in to comment.