Skip to content
Permalink
Browse files

Add unit test for ticket #15116

  • Loading branch information
mhugent committed Jun 27, 2016
1 parent 3e069c3 commit ef90c0b2f7987baf84e2c1a4bc13a276f4a0f45f
Showing with 37 additions and 0 deletions.
  1. +37 −0 tests/src/core/testqgsgeometryutils.cpp
@@ -44,6 +44,8 @@ class TestQgsGeometryUtils: public QObject
void testAverageAngle_data();
void testAverageAngle();
void testDistanceToVertex();
void testCircleCenterRadius_data();
void testCircleCenterRadius();
};


@@ -361,6 +363,41 @@ void TestQgsGeometryUtils::testDistanceToVertex()
QCOMPARE( QgsGeometryUtils::distanceToVertex( point, QgsVertexId( 0, 0, 1 ) ), -1.0 );
}

void TestQgsGeometryUtils::testCircleCenterRadius_data()
{
QTest::addColumn<double>( "x1" );
QTest::addColumn<double>( "y1" );
QTest::addColumn<double>( "x2" );
QTest::addColumn<double>( "y2" );
QTest::addColumn<double>( "x3" );
QTest::addColumn<double>( "y3" );
QTest::addColumn<double>( "expectedRadius" );
QTest::addColumn<double>( "expectedCenterX" );
QTest::addColumn<double>( "expectedCenterY" );

QTest::newRow( "circleCenterRadius1" ) << 1.0 << 1.0 << 5.0 << 7.0 << 1.0 << 1.0 << sqrt( 13.0 ) << 3.0 << 4.0;
QTest::newRow( "circleCenterRadius1" ) << 0.0 << 2.0 << 2.0 << 2.0 << 0.0 << 2.0 << 1.0 << 1.0 << 2.0;
}

void TestQgsGeometryUtils::testCircleCenterRadius()
{
QFETCH( double, x1 );
QFETCH( double, y1 );
QFETCH( double, x2 );
QFETCH( double, y2 );
QFETCH( double, x3 );
QFETCH( double, y3 );
QFETCH( double, expectedRadius );
QFETCH( double, expectedCenterX );
QFETCH( double, expectedCenterY );

double radius, centerX, centerY;
QgsGeometryUtils::circleCenterRadius( QgsPointV2( x1, y1 ), QgsPointV2( x2, y2 ), QgsPointV2( x3, y3 ), radius, centerX, centerY );
QVERIFY( qgsDoubleNear( expectedRadius, radius ) );
QVERIFY( qgsDoubleNear( expectedCenterX, centerX ) );
QVERIFY( qgsDoubleNear( expectedCenterY, centerY ) );
}


QTEST_MAIN( TestQgsGeometryUtils )
#include "testqgsgeometryutils.moc"

0 comments on commit ef90c0b

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