Skip to content

Commit

Permalink
Rework failing test for better debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 8, 2021
1 parent 5ba9950 commit f7ae01c
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -151,6 +151,7 @@ class TestQgsGeometry : public QObject

void makeValid();

void isSimple_data();
void isSimple();

void reshapeGeometryLineMerge();
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f7ae01c

Please sign in to comment.