Skip to content

Commit 21a3b8a

Browse files
committedAug 29, 2017
Use QGSCOMPARENEAR instead of QVERIFY( qgsDoubleNear(... ) )
QGSCOMPARENEAR gives better debugging output when the test fails
1 parent 2af10cb commit 21a3b8a

23 files changed

+295
-279
lines changed
 

‎tests/src/analysis/testqgsrastercalculator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Email : nyall dot dawson at gmail dot com
2121
#include "qgsrastermatrix.h"
2222
#include "qgsapplication.h"
2323
#include "qgsproject.h"
24+
#include "qgstestutils.h"
2425

2526
Q_DECLARE_METATYPE( QgsRasterCalcNode::Operator )
2627

@@ -212,7 +213,7 @@ void TestQgsRasterCalculator::singleOp()
212213
QVERIFY( node.calculate( rasterData, result ) );
213214

214215
qDebug() << "Result: " << result.number() << " expected: " << expected;
215-
QVERIFY( qgsDoubleNear( result.number(), expected, 0.0000000001 ) );
216+
QGSCOMPARENEAR( result.number(), expected, 0.0000000001 );
216217

217218
}
218219

‎tests/src/app/testqgsattributetable.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsvectorfilewriter.h"
2929

3030
#include "qgstest.h"
31+
#include "qgstestutils.h"
3132

3233
/** \ingroup UnitTests
3334
* This is a unit test for the attribute table dialog
@@ -114,7 +115,7 @@ void TestQgsAttributeTable::testFieldCalculation()
114115
QgsFeature f;
115116
QVERIFY( fit.nextFeature( f ) );
116117
double expected = 26932.156;
117-
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
118+
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
118119

119120
// change project length unit, check calculation respects unit
120121
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceFeet );
@@ -126,7 +127,7 @@ void TestQgsAttributeTable::testFieldCalculation()
126127
fit = tempLayer->dataProvider()->getFeatures();
127128
QVERIFY( fit.nextFeature( f ) );
128129
expected = 88360.0918635;
129-
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
130+
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
130131
}
131132

132133
void TestQgsAttributeTable::testFieldCalculationArea()
@@ -164,7 +165,7 @@ void TestQgsAttributeTable::testFieldCalculationArea()
164165
QgsFeature f;
165166
QVERIFY( fit.nextFeature( f ) );
166167
double expected = 1009089817.0;
167-
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 1.0 ) );
168+
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 1.0 );
168169

169170
// change project area unit, check calculation respects unit
170171
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMiles );
@@ -176,7 +177,7 @@ void TestQgsAttributeTable::testFieldCalculationArea()
176177
fit = tempLayer->dataProvider()->getFeatures();
177178
QVERIFY( fit.nextFeature( f ) );
178179
expected = 389.6117565069;
179-
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
180+
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
180181
}
181182

182183
void TestQgsAttributeTable::testNoGeom()

‎tests/src/app/testqgsfieldcalculator.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgsproject.h"
2525
#include "qgsmapcanvas.h"
2626
#include "qgsunittypes.h"
27+
#include "qgstestutils.h"
2728

2829
/** \ingroup UnitTests
2930
* This is a unit test for the field calculator
@@ -107,7 +108,7 @@ void TestQgsFieldCalculator::testLengthCalculations()
107108
QgsFeature f;
108109
QVERIFY( fit.nextFeature( f ) );
109110
double expected = 26932.156;
110-
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
111+
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
111112

112113
// change project length unit, check calculation respects unit
113114
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceFeet );
@@ -122,7 +123,7 @@ void TestQgsFieldCalculator::testLengthCalculations()
122123
fit = tempLayer->dataProvider()->getFeatures();
123124
QVERIFY( fit.nextFeature( f ) );
124125
expected = 88360.0918635;
125-
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
126+
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
126127

127128
}
128129

@@ -168,7 +169,7 @@ void TestQgsFieldCalculator::testAreaCalculations()
168169
QgsFeature f;
169170
QVERIFY( fit.nextFeature( f ) );
170171
double expected = 1009089817.0;
171-
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 1.0 ) );
172+
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 1.0 );
172173

173174
// change project area unit, check calculation respects unit
174175
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMiles );
@@ -183,7 +184,7 @@ void TestQgsFieldCalculator::testAreaCalculations()
183184
fit = tempLayer->dataProvider()->getFeatures();
184185
QVERIFY( fit.nextFeature( f ) );
185186
expected = 389.6117565069;
186-
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
187+
QGSCOMPARENEAR( f.attribute( "col1" ).toDouble(), expected, 0.001 );
187188
}
188189

189190
QGSTEST_MAIN( TestQgsFieldCalculator )

‎tests/src/app/testqgsmaptoolidentifyaction.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsunittypes.h"
2727
#include "qgsmaptoolidentifyaction.h"
2828
#include "qgssettings.h"
29+
#include "qgstestutils.h"
2930

3031
#include "cpl_conv.h"
3132

@@ -142,23 +143,23 @@ void TestQgsMapToolIdentifyAction::lengthCalculation()
142143
QCOMPARE( result.length(), 1 );
143144
QString derivedLength = result.at( 0 ).mDerivedAttributes[tr( "Length" )];
144145
double length = derivedLength.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
145-
QVERIFY( qgsDoubleNear( length, 26932.2, 0.1 ) );
146+
QGSCOMPARENEAR( length, 26932.2, 0.1 );
146147

147148
//check that project units are respected
148149
QgsProject::instance()->setDistanceUnits( QgsUnitTypes::DistanceFeet );
149150
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
150151
QCOMPARE( result.length(), 1 );
151152
derivedLength = result.at( 0 ).mDerivedAttributes[tr( "Length" )];
152153
length = derivedLength.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
153-
QVERIFY( qgsDoubleNear( length, 88360.1, 0.1 ) );
154+
QGSCOMPARENEAR( length, 88360.1, 0.1 );
154155

155156
//test unchecked "keep base units" setting
156157
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), false );
157158
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
158159
QCOMPARE( result.length(), 1 );
159160
derivedLength = result.at( 0 ).mDerivedAttributes[tr( "Length" )];
160161
length = derivedLength.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
161-
QVERIFY( qgsDoubleNear( length, 16.735, 0.001 ) );
162+
QGSCOMPARENEAR( length, 16.735, 0.001 );
162163
}
163164

164165
void TestQgsMapToolIdentifyAction::perimeterCalculation()
@@ -203,15 +204,15 @@ void TestQgsMapToolIdentifyAction::perimeterCalculation()
203204
QCOMPARE( result.length(), 1 );
204205
derivedPerimeter = result.at( 0 ).mDerivedAttributes[tr( "Perimeter" )];
205206
perimeter = derivedPerimeter.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
206-
QVERIFY( qgsDoubleNear( perimeter, 420896.0, 0.1 ) );
207+
QGSCOMPARENEAR( perimeter, 420896.0, 0.1 );
207208

208209
//test unchecked "keep base units" setting
209210
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), false );
210211
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
211212
QCOMPARE( result.length(), 1 );
212213
derivedPerimeter = result.at( 0 ).mDerivedAttributes[tr( "Perimeter" )];
213214
perimeter = derivedPerimeter.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
214-
QVERIFY( qgsDoubleNear( perimeter, 79.715, 0.001 ) );
215+
QGSCOMPARENEAR( perimeter, 79.715, 0.001 );
215216
}
216217

217218
void TestQgsMapToolIdentifyAction::areaCalculation()
@@ -249,15 +250,15 @@ void TestQgsMapToolIdentifyAction::areaCalculation()
249250
QCOMPARE( result.length(), 1 );
250251
QString derivedArea = result.at( 0 ).mDerivedAttributes[tr( "Area" )];
251252
double area = derivedArea.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
252-
QVERIFY( qgsDoubleNear( area, 1009089817.0, 1.0 ) );
253+
QGSCOMPARENEAR( area, 1009089817.0, 1.0 );
253254

254255
//check that project units are respected
255256
QgsProject::instance()->setAreaUnits( QgsUnitTypes::AreaSquareMiles );
256257
result = action->identify( mapPoint.x(), mapPoint.y(), QList<QgsMapLayer *>() << tempLayer.get() );
257258
QCOMPARE( result.length(), 1 );
258259
derivedArea = result.at( 0 ).mDerivedAttributes[tr( "Area" )];
259260
area = derivedArea.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
260-
QVERIFY( qgsDoubleNear( area, 389.6117, 0.001 ) );
261+
QGSCOMPARENEAR( area, 389.6117, 0.001 );
261262

262263
//test unchecked "keep base units" setting
263264
s.setValue( QStringLiteral( "/qgis/measure/keepbaseunit" ), false );
@@ -266,7 +267,7 @@ void TestQgsMapToolIdentifyAction::areaCalculation()
266267
QCOMPARE( result.length(), 1 );
267268
derivedArea = result.at( 0 ).mDerivedAttributes[tr( "Area" )];
268269
area = derivedArea.remove( ',' ).split( ' ' ).at( 0 ).toDouble();
269-
QVERIFY( qgsDoubleNear( area, 389.6117, 0.001 ) );
270+
QGSCOMPARENEAR( area, 389.6117, 0.001 );
270271
}
271272

272273
// private

‎tests/src/core/testqgscomposermap.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "qgsproperty.h"
3030
#include <QObject>
3131
#include "qgstest.h"
32+
#include "qgstestutils.h"
3233

3334
class TestQgsComposerMap : public QObject
3435
{
@@ -176,34 +177,34 @@ void TestQgsComposerMap::worldFileGeneration()
176177
double a, b, c, d, e, f;
177178
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
178179

179-
QVERIFY( qgsDoubleNear( a, 4.18048, 0.001 ) );
180-
QVERIFY( qgsDoubleNear( b, 2.41331, 0.001 ) );
181-
QVERIFY( qgsDoubleNear( c, 779444, 1 ) );
182-
QVERIFY( qgsDoubleNear( d, 2.4136, 0.001 ) );
183-
QVERIFY( qgsDoubleNear( e, -4.17997, 0.001 ) );
184-
QVERIFY( qgsDoubleNear( f, 3.34241e+06, 1e+03 ) );
180+
QGSCOMPARENEAR( a, 4.18048, 0.001 );
181+
QGSCOMPARENEAR( b, 2.41331, 0.001 );
182+
QGSCOMPARENEAR( c, 779444, 1 );
183+
QGSCOMPARENEAR( d, 2.4136, 0.001 );
184+
QGSCOMPARENEAR( e, -4.17997, 0.001 );
185+
QGSCOMPARENEAR( f, 3.34241e+06, 1e+03 );
185186

186187
//test with map on second page. Parameters should be the same
187188
mComposerMap->setItemPosition( 20, 20, QgsComposerItem::UpperLeft, 2 );
188189
mComposition->computeWorldFileParameters( a, b, c, d, e, f );
189190

190-
QVERIFY( qgsDoubleNear( a, 4.18048, 0.001 ) );
191-
QVERIFY( qgsDoubleNear( b, 2.41331, 0.001 ) );
192-
QVERIFY( qgsDoubleNear( c, 779444, 1 ) );
193-
QVERIFY( qgsDoubleNear( d, 2.4136, 0.001 ) );
194-
QVERIFY( qgsDoubleNear( e, -4.17997, 0.001 ) );
195-
QVERIFY( qgsDoubleNear( f, 3.34241e+06, 1e+03 ) );
191+
QGSCOMPARENEAR( a, 4.18048, 0.001 );
192+
QGSCOMPARENEAR( b, 2.41331, 0.001 );
193+
QGSCOMPARENEAR( c, 779444, 1 );
194+
QGSCOMPARENEAR( d, 2.4136, 0.001 );
195+
QGSCOMPARENEAR( e, -4.17997, 0.001 );
196+
QGSCOMPARENEAR( f, 3.34241e+06, 1e+03 );
196197

197198
//test computing parameters for specific region
198199
mComposerMap->setItemPosition( 20, 20, QgsComposerItem::UpperLeft, 2 );
199200
mComposition->computeWorldFileParameters( QRectF( 10, 5, 260, 200 ), a, b, c, d, e, f );
200201

201-
QVERIFY( qgsDoubleNear( a, 4.18061, 0.001 ) );
202-
QVERIFY( qgsDoubleNear( b, 2.41321, 0.001 ) );
203-
QVERIFY( qgsDoubleNear( c, 773810, 1 ) );
204-
QVERIFY( qgsDoubleNear( d, 2.4137, 0.001 ) );
205-
QVERIFY( qgsDoubleNear( e, -4.1798, 0.001 ) );
206-
QVERIFY( qgsDoubleNear( f, 3.35331e+06, 1e+03 ) );
202+
QGSCOMPARENEAR( a, 4.18061, 0.001 );
203+
QGSCOMPARENEAR( b, 2.41321, 0.001 );
204+
QGSCOMPARENEAR( c, 773810, 1 );
205+
QGSCOMPARENEAR( d, 2.4137, 0.001 );
206+
QGSCOMPARENEAR( e, -4.1798, 0.001 );
207+
QGSCOMPARENEAR( f, 3.35331e+06, 1e+03 );
207208

208209
mComposition->setGenerateWorldFile( false );
209210
mComposerMap->setMapRotation( 0.0 );

‎tests/src/core/testqgscomposerutils.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ void TestQgsComposerUtils::rotate()
169169
double x = ( *it ).first.x1();
170170
double y = ( *it ).first.y1();
171171
QgsComposerUtils::rotate( ( *it ).second, x, y );
172-
QVERIFY( qgsDoubleNear( x, ( *it ).first.x2() ) );
173-
QVERIFY( qgsDoubleNear( y, ( *it ).first.y2() ) );
172+
QGSCOMPARENEAR( x, ( *it ).first.x2(), 4 * DBL_EPSILON );
173+
QGSCOMPARENEAR( y, ( *it ).first.y2(), 4 * DBL_EPSILON );
174174
}
175175
}
176176

@@ -194,7 +194,7 @@ void TestQgsComposerUtils::normalizedAngle()
194194
QList< QPair< double, double > >::const_iterator it = testVals.constBegin();
195195
for ( ; it != testVals.constEnd(); ++it )
196196
{
197-
QVERIFY( qgsDoubleNear( QgsComposerUtils::normalizedAngle( ( *it ).first ), ( *it ).second ) );
197+
QGSCOMPARENEAR( QgsComposerUtils::normalizedAngle( ( *it ).first ), ( *it ).second, 4 * DBL_EPSILON );
198198
}
199199
}
200200

@@ -243,7 +243,7 @@ void TestQgsComposerUtils::snappedAngle()
243243
QList< QPair< double, double > >::const_iterator it = testVals.constBegin();
244244
for ( ; it != testVals.constEnd(); ++it )
245245
{
246-
QVERIFY( qgsDoubleNear( QgsComposerUtils::snappedAngle( ( *it ).first ), ( *it ).second ) );
246+
QGSCOMPARENEAR( QgsComposerUtils::snappedAngle( ( *it ).first ), ( *it ).second, 4 * DBL_EPSILON );
247247
}
248248
}
249249

@@ -293,7 +293,7 @@ void TestQgsComposerUtils::largestRotatedRect()
293293
|| ( qgsDoubleNear( rotatedRectBounds.height(), bounds.height(), 0.001 ) && ( rotatedRectBounds.width() <= bounds.width() ) ) );
294294

295295
//also verify that aspect ratio of rectangle has not changed
296-
QVERIFY( qgsDoubleNear( result.width() / result.height(), wideRect.width() / wideRect.height() ) );
296+
QGSCOMPARENEAR( result.width() / result.height(), wideRect.width() / wideRect.height(), 4 * DBL_EPSILON );
297297
}
298298
//and again for the high rectangle
299299
for ( double rotation = 10; rotation < 360; rotation += 10 )
@@ -308,48 +308,48 @@ void TestQgsComposerUtils::largestRotatedRect()
308308
|| ( qgsDoubleNear( rotatedRectBounds.height(), bounds.height(), 0.001 ) && ( rotatedRectBounds.width() <= bounds.width() ) ) );
309309

310310
//also verify that aspect ratio of rectangle has not changed
311-
QVERIFY( qgsDoubleNear( result.width() / result.height(), highRect.width() / highRect.height() ) );
311+
QGSCOMPARENEAR( result.width() / result.height(), highRect.width() / highRect.height(), 4 * DBL_EPSILON );
312312
}
313313
}
314314

315315
void TestQgsComposerUtils::pointsToMM()
316316
{
317317
//test conversion of points to mm, based on 1 point = 1 / 72 of an inch
318-
QVERIFY( qgsDoubleNear( QgsComposerUtils::pointsToMM( 72 / 25.4 ), 1, 0.001 ) );
318+
QGSCOMPARENEAR( QgsComposerUtils::pointsToMM( 72 / 25.4 ), 1, 0.001 );
319319
}
320320

321321
void TestQgsComposerUtils::mmToPoints()
322322
{
323323
//test conversion of mm to points, based on 1 point = 1 / 72 of an inch
324-
QVERIFY( qgsDoubleNear( QgsComposerUtils::mmToPoints( 25.4 / 72 ), 1, 0.001 ) );
324+
QGSCOMPARENEAR( QgsComposerUtils::mmToPoints( 25.4 / 72 ), 1, 0.001 );
325325
}
326326

327327
void TestQgsComposerUtils::relativePosition()
328328
{
329329
//+ve gradient
330-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 1, 0, 2, 0, 4 ), 2, 0.001 ) );
331-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 0, 0, 2, 0, 4 ), 0, 0.001 ) );
332-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 2, 0, 2, 0, 4 ), 4, 0.001 ) );
333-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 4, 0, 2, 0, 4 ), 8, 0.001 ) );
334-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( -2, 0, 2, 0, 4 ), -4, 0.001 ) );
330+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 1, 0, 2, 0, 4 ), 2, 0.001 );
331+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 0, 0, 2, 0, 4 ), 0, 0.001 );
332+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 2, 0, 2, 0, 4 ), 4, 0.001 );
333+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 4, 0, 2, 0, 4 ), 8, 0.001 );
334+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( -2, 0, 2, 0, 4 ), -4, 0.001 );
335335
//-ve gradient
336-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 1, 0, 2, 4, 0 ), 2, 0.001 ) );
337-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 0, 0, 2, 4, 0 ), 4, 0.001 ) );
338-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 2, 0, 2, 4, 0 ), 0, 0.001 ) );
339-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 4, 0, 2, 4, 0 ), -4, 0.001 ) );
340-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( -2, 0, 2, 4, 0 ), 8, 0.001 ) );
336+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 1, 0, 2, 4, 0 ), 2, 0.001 );
337+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 0, 0, 2, 4, 0 ), 4, 0.001 );
338+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 2, 0, 2, 4, 0 ), 0, 0.001 );
339+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 4, 0, 2, 4, 0 ), -4, 0.001 );
340+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( -2, 0, 2, 4, 0 ), 8, 0.001 );
341341
//-ve domain
342-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 1, 2, 0, 0, 4 ), 2, 0.001 ) );
343-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 0, 2, 0, 0, 4 ), 4, 0.001 ) );
344-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 2, 2, 0, 0, 4 ), 0, 0.001 ) );
345-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 4, 2, 0, 0, 4 ), -4, 0.001 ) );
346-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( -2, 2, 0, 0, 4 ), 8, 0.001 ) );
342+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 1, 2, 0, 0, 4 ), 2, 0.001 );
343+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 0, 2, 0, 0, 4 ), 4, 0.001 );
344+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 2, 2, 0, 0, 4 ), 0, 0.001 );
345+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 4, 2, 0, 0, 4 ), -4, 0.001 );
346+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( -2, 2, 0, 0, 4 ), 8, 0.001 );
347347
//-ve domain and gradient
348-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 1, 2, 0, 4, 0 ), 2, 0.001 ) );
349-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 0, 2, 0, 4, 0 ), 0, 0.001 ) );
350-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 2, 2, 0, 4, 0 ), 4, 0.001 ) );
351-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( 4, 2, 0, 4, 0 ), 8, 0.001 ) );
352-
QVERIFY( qgsDoubleNear( QgsComposerUtils::relativePosition( -2, 2, 0, 4, 0 ), -4, 0.001 ) );
348+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 1, 2, 0, 4, 0 ), 2, 0.001 );
349+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 0, 2, 0, 4, 0 ), 0, 0.001 );
350+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 2, 2, 0, 4, 0 ), 4, 0.001 );
351+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( 4, 2, 0, 4, 0 ), 8, 0.001 );
352+
QGSCOMPARENEAR( QgsComposerUtils::relativePosition( -2, 2, 0, 4, 0 ), -4, 0.001 );
353353
}
354354

355355
void TestQgsComposerUtils::relativeResizeRect()
@@ -528,50 +528,50 @@ void TestQgsComposerUtils::fontAscentMM()
528528
{
529529
mTestFont.setPointSize( 12 );
530530
//platform specific font rendering differences mean these tests need to be very leniant
531-
QVERIFY( qgsDoubleNear( QgsComposerUtils::fontAscentMM( mTestFont ), 3.9, 0.5 ) );
531+
QGSCOMPARENEAR( QgsComposerUtils::fontAscentMM( mTestFont ), 3.9, 0.5 );
532532
}
533533

534534
void TestQgsComposerUtils::fontDescentMM()
535535
{
536536
mTestFont.setPointSize( 12 );
537-
QVERIFY( qgsDoubleNear( QgsComposerUtils::fontDescentMM( mTestFont ), 0.9, 0.05 ) );
537+
QGSCOMPARENEAR( QgsComposerUtils::fontDescentMM( mTestFont ), 0.9, 0.05 );
538538
}
539539

540540
void TestQgsComposerUtils::fontHeightMM()
541541
{
542542
mTestFont.setPointSize( 12 );
543543
//platform specific font rendering differences mean these tests need to be very leniant
544-
QVERIFY( qgsDoubleNear( QgsComposerUtils::fontHeightMM( mTestFont ), 4.9, 0.5 ) );
544+
QGSCOMPARENEAR( QgsComposerUtils::fontHeightMM( mTestFont ), 4.9, 0.5 );
545545
}
546546

547547
void TestQgsComposerUtils::fontHeightCharacterMM()
548548
{
549549
mTestFont.setPointSize( 12 );
550550
//platform specific font rendering differences mean these tests need to be very leniant
551-
QVERIFY( qgsDoubleNear( QgsComposerUtils::fontHeightCharacterMM( mTestFont, QChar( 'a' ) ), 2.4, 0.15 ) );
552-
QVERIFY( qgsDoubleNear( QgsComposerUtils::fontHeightCharacterMM( mTestFont, QChar( 'l' ) ), 3.15, 0.16 ) );
553-
QVERIFY( qgsDoubleNear( QgsComposerUtils::fontHeightCharacterMM( mTestFont, QChar( 'g' ) ), 3.2, 0.11 ) );
551+
QGSCOMPARENEAR( QgsComposerUtils::fontHeightCharacterMM( mTestFont, QChar( 'a' ) ), 2.4, 0.15 );
552+
QGSCOMPARENEAR( QgsComposerUtils::fontHeightCharacterMM( mTestFont, QChar( 'l' ) ), 3.15, 0.16 );
553+
QGSCOMPARENEAR( QgsComposerUtils::fontHeightCharacterMM( mTestFont, QChar( 'g' ) ), 3.2, 0.11 );
554554
}
555555

556556
void TestQgsComposerUtils::textWidthMM()
557557
{
558558
//platform specific font rendering differences mean this test needs to be very leniant
559559
mTestFont.setPointSize( 12 );
560-
QVERIFY( qgsDoubleNear( QgsComposerUtils::textWidthMM( mTestFont, QString( "test string" ) ), 20, 2 ) );
560+
QGSCOMPARENEAR( QgsComposerUtils::textWidthMM( mTestFont, QString( "test string" ) ), 20, 2 );
561561
}
562562

563563
void TestQgsComposerUtils::textHeightMM()
564564
{
565565
//platform specific font rendering differences mean this test needs to be very leniant
566566
mTestFont.setPointSize( 12 );
567567
QgsDebugMsg( QString( "height: %1" ).arg( QgsComposerUtils::textHeightMM( mTestFont, QString( "test string" ) ) ) );
568-
QVERIFY( qgsDoubleNear( QgsComposerUtils::textHeightMM( mTestFont, QString( "test string" ) ), 3.9, 0.2 ) );
568+
QGSCOMPARENEAR( QgsComposerUtils::textHeightMM( mTestFont, QString( "test string" ) ), 3.9, 0.2 );
569569
QgsDebugMsg( QString( "height: %1" ).arg( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring" ) ) ) );
570-
QVERIFY( qgsDoubleNear( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring" ) ), 8.7, 0.2 ) );
570+
QGSCOMPARENEAR( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring" ) ), 8.7, 0.2 );
571571
QgsDebugMsg( QString( "height: %1" ).arg( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring" ), 2 ) ) );
572-
QVERIFY( qgsDoubleNear( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring" ), 2 ), 13.5, 0.2 ) );
572+
QGSCOMPARENEAR( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring" ), 2 ), 13.5, 0.2 );
573573
QgsDebugMsg( QString( "height: %1" ).arg( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring\nstring" ) ) ) );
574-
QVERIFY( qgsDoubleNear( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring\nstring" ) ), 13.5, 0.2 ) );
574+
QGSCOMPARENEAR( QgsComposerUtils::textHeightMM( mTestFont, QString( "test\nstring\nstring" ) ), 13.5, 0.2 );
575575
}
576576

577577
void TestQgsComposerUtils::drawTextPos()

‎tests/src/core/testqgscomposition.cpp

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -365,34 +365,34 @@ void TestQgsComposition::bounds()
365365

366366
//check bounds
367367
QRectF compositionBounds = composition->compositionBounds( false );
368-
QVERIFY( qgsDoubleNear( compositionBounds.height(), 372.15, 0.01 ) );
369-
QVERIFY( qgsDoubleNear( compositionBounds.width(), 301.00, 0.01 ) );
370-
QVERIFY( qgsDoubleNear( compositionBounds.left(), -2, 0.01 ) );
371-
QVERIFY( qgsDoubleNear( compositionBounds.top(), -2, 0.01 ) );
368+
QGSCOMPARENEAR( compositionBounds.height(), 372.15, 0.01 );
369+
QGSCOMPARENEAR( compositionBounds.width(), 301.00, 0.01 );
370+
QGSCOMPARENEAR( compositionBounds.left(), -2, 0.01 );
371+
QGSCOMPARENEAR( compositionBounds.top(), -2, 0.01 );
372372

373373
QRectF compositionBoundsNoPage = composition->compositionBounds( true );
374-
QVERIFY( qgsDoubleNear( compositionBoundsNoPage.height(), 320.36, 0.01 ) );
375-
QVERIFY( qgsDoubleNear( compositionBoundsNoPage.width(), 250.30, 0.01 ) );
376-
QVERIFY( qgsDoubleNear( compositionBoundsNoPage.left(), 9.85, 0.01 ) );
377-
QVERIFY( qgsDoubleNear( compositionBoundsNoPage.top(), 49.79, 0.01 ) );
374+
QGSCOMPARENEAR( compositionBoundsNoPage.height(), 320.36, 0.01 );
375+
QGSCOMPARENEAR( compositionBoundsNoPage.width(), 250.30, 0.01 );
376+
QGSCOMPARENEAR( compositionBoundsNoPage.left(), 9.85, 0.01 );
377+
QGSCOMPARENEAR( compositionBoundsNoPage.top(), 49.79, 0.01 );
378378

379379
QRectF page1Bounds = composition->pageItemBounds( 0, true );
380-
QVERIFY( qgsDoubleNear( page1Bounds.height(), 150.36, 0.01 ) );
381-
QVERIFY( qgsDoubleNear( page1Bounds.width(), 155.72, 0.01 ) );
382-
QVERIFY( qgsDoubleNear( page1Bounds.left(), 54.43, 0.01 ) );
383-
QVERIFY( qgsDoubleNear( page1Bounds.top(), 49.79, 0.01 ) );
380+
QGSCOMPARENEAR( page1Bounds.height(), 150.36, 0.01 );
381+
QGSCOMPARENEAR( page1Bounds.width(), 155.72, 0.01 );
382+
QGSCOMPARENEAR( page1Bounds.left(), 54.43, 0.01 );
383+
QGSCOMPARENEAR( page1Bounds.top(), 49.79, 0.01 );
384384

385385
QRectF page2Bounds = composition->pageItemBounds( 1, true );
386-
QVERIFY( qgsDoubleNear( page2Bounds.height(), 100.30, 0.01 ) );
387-
QVERIFY( qgsDoubleNear( page2Bounds.width(), 50.30, 0.01 ) );
388-
QVERIFY( qgsDoubleNear( page2Bounds.left(), 209.85, 0.01 ) );
389-
QVERIFY( qgsDoubleNear( page2Bounds.top(), 249.85, 0.01 ) );
386+
QGSCOMPARENEAR( page2Bounds.height(), 100.30, 0.01 );
387+
QGSCOMPARENEAR( page2Bounds.width(), 50.30, 0.01 );
388+
QGSCOMPARENEAR( page2Bounds.left(), 209.85, 0.01 );
389+
QGSCOMPARENEAR( page2Bounds.top(), 249.85, 0.01 );
390390

391391
QRectF page2BoundsWithHidden = composition->pageItemBounds( 1, false );
392-
QVERIFY( qgsDoubleNear( page2BoundsWithHidden.height(), 120.30, 0.01 ) );
393-
QVERIFY( qgsDoubleNear( page2BoundsWithHidden.width(), 250.30, 0.01 ) );
394-
QVERIFY( qgsDoubleNear( page2BoundsWithHidden.left(), 9.85, 0.01 ) );
395-
QVERIFY( qgsDoubleNear( page2BoundsWithHidden.top(), 249.85, 0.01 ) );
392+
QGSCOMPARENEAR( page2BoundsWithHidden.height(), 120.30, 0.01 );
393+
QGSCOMPARENEAR( page2BoundsWithHidden.width(), 250.30, 0.01 );
394+
QGSCOMPARENEAR( page2BoundsWithHidden.left(), 9.85, 0.01 );
395+
QGSCOMPARENEAR( page2BoundsWithHidden.top(), 249.85, 0.01 );
396396

397397
delete composition;
398398
}
@@ -539,54 +539,54 @@ void TestQgsComposition::georeference()
539539
composition->addComposerMap( map );
540540

541541
t = composition->computeGeoTransform( map );
542-
QVERIFY( qgsDoubleNear( t[0], 1925.0, 1.0 ) );
543-
QVERIFY( qgsDoubleNear( t[1], 0.211719, 0.0001 ) );
544-
QVERIFY( qgsDoubleNear( t[2], 0.0 ) );
545-
QVERIFY( qgsDoubleNear( t[3], 3200, 1 ) );
546-
QVERIFY( qgsDoubleNear( t[4], 0.0 ) );
547-
QVERIFY( qgsDoubleNear( t[5], -0.211694, 0.0001 ) );
542+
QGSCOMPARENEAR( t[0], 1925.0, 1.0 );
543+
QGSCOMPARENEAR( t[1], 0.211719, 0.0001 );
544+
QGSCOMPARENEAR( t[2], 0.0, 4 * DBL_EPSILON );
545+
QGSCOMPARENEAR( t[3], 3200, 1 );
546+
QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON );
547+
QGSCOMPARENEAR( t[5], -0.211694, 0.0001 );
548548
delete[] t;
549549

550550
// don't specify map
551551
composition->setReferenceMap( map );
552552
t = composition->computeGeoTransform();
553-
QVERIFY( qgsDoubleNear( t[0], 1925.0, 1.0 ) );
554-
QVERIFY( qgsDoubleNear( t[1], 0.211719, 0.0001 ) );
555-
QVERIFY( qgsDoubleNear( t[2], 0.0 ) );
556-
QVERIFY( qgsDoubleNear( t[3], 3200, 1 ) );
557-
QVERIFY( qgsDoubleNear( t[4], 0.0 ) );
558-
QVERIFY( qgsDoubleNear( t[5], -0.211694, 0.0001 ) );
553+
QGSCOMPARENEAR( t[0], 1925.0, 1.0 );
554+
QGSCOMPARENEAR( t[1], 0.211719, 0.0001 );
555+
QGSCOMPARENEAR( t[2], 0.0, 4 * DBL_EPSILON );
556+
QGSCOMPARENEAR( t[3], 3200, 1 );
557+
QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON );
558+
QGSCOMPARENEAR( t[5], -0.211694, 0.0001 );
559559
delete[] t;
560560

561561
// specify extent
562562
t = composition->computeGeoTransform( map, QRectF( 70, 100, 50, 60 ) );
563-
QVERIFY( qgsDoubleNear( t[0], 2100.0, 1.0 ) );
564-
QVERIFY( qgsDoubleNear( t[1], 0.211864, 0.0001 ) );
565-
QVERIFY( qgsDoubleNear( t[2], 0.0 ) );
566-
QVERIFY( qgsDoubleNear( t[3], 2950, 1 ) );
567-
QVERIFY( qgsDoubleNear( t[4], 0.0 ) );
568-
QVERIFY( qgsDoubleNear( t[5], -0.211864, 0.0001 ) );
563+
QGSCOMPARENEAR( t[0], 2100.0, 1.0 );
564+
QGSCOMPARENEAR( t[1], 0.211864, 0.0001 );
565+
QGSCOMPARENEAR( t[2], 0.0, 4 * DBL_EPSILON );
566+
QGSCOMPARENEAR( t[3], 2950, 1 );
567+
QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON );
568+
QGSCOMPARENEAR( t[5], -0.211864, 0.0001 );
569569
delete[] t;
570570

571571
// specify dpi
572572
t = composition->computeGeoTransform( map, QRectF(), 75 );
573-
QVERIFY( qgsDoubleNear( t[0], 1925.0, 1 ) );
574-
QVERIFY( qgsDoubleNear( t[1], 0.847603, 0.0001 ) );
575-
QVERIFY( qgsDoubleNear( t[2], 0.0 ) );
576-
QVERIFY( qgsDoubleNear( t[3], 3200.0, 1 ) );
577-
QVERIFY( qgsDoubleNear( t[4], 0.0 ) );
578-
QVERIFY( qgsDoubleNear( t[5], -0.846774, 0.0001 ) );
573+
QGSCOMPARENEAR( t[0], 1925.0, 1 );
574+
QGSCOMPARENEAR( t[1], 0.847603, 0.0001 );
575+
QGSCOMPARENEAR( t[2], 0.0, 4 * DBL_EPSILON );
576+
QGSCOMPARENEAR( t[3], 3200.0, 1 );
577+
QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON );
578+
QGSCOMPARENEAR( t[5], -0.846774, 0.0001 );
579579
delete[] t;
580580

581581
// rotation
582582
map->setMapRotation( 45 );
583583
t = composition->computeGeoTransform( map );
584-
QVERIFY( qgsDoubleNear( t[0], 1825.7, 1 ) );
585-
QVERIFY( qgsDoubleNear( t[1], 0.149708, 0.0001 ) );
586-
QVERIFY( qgsDoubleNear( t[2], 0.149708, 0.0001 ) );
587-
QVERIFY( qgsDoubleNear( t[3], 2889.64, 1 ) );
588-
QVERIFY( qgsDoubleNear( t[4], 0.14969, 0.0001 ) );
589-
QVERIFY( qgsDoubleNear( t[5], -0.14969, 0.0001 ) );
584+
QGSCOMPARENEAR( t[0], 1825.7, 1 );
585+
QGSCOMPARENEAR( t[1], 0.149708, 0.0001 );
586+
QGSCOMPARENEAR( t[2], 0.149708, 0.0001 );
587+
QGSCOMPARENEAR( t[3], 2889.64, 1 );
588+
QGSCOMPARENEAR( t[4], 0.14969, 0.0001 );
589+
QGSCOMPARENEAR( t[5], -0.14969, 0.0001 );
590590
delete[] t;
591591

592592
delete composition;

‎tests/src/core/testqgscoordinatetransform.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsrectangle.h"
2020
#include <QObject>
2121
#include "qgstest.h"
22+
#include "qgstestutils.h"
2223

2324
class TestQgsCoordinateTransform: public QObject
2425
{
@@ -200,10 +201,10 @@ void TestQgsCoordinateTransform::transformBoundingBox()
200201
qDebug( "BBox transform y min: %.17f", resultRect.yMinimum() );
201202
qDebug( "BBox transform y max: %.17f", resultRect.yMaximum() );
202203

203-
QVERIFY( qgsDoubleNear( resultRect.xMinimum(), expectedRect.xMinimum(), 0.001 ) );
204-
QVERIFY( qgsDoubleNear( resultRect.yMinimum(), expectedRect.yMinimum(), 0.001 ) );
205-
QVERIFY( qgsDoubleNear( resultRect.xMaximum(), expectedRect.xMaximum(), 0.001 ) );
206-
QVERIFY( qgsDoubleNear( resultRect.yMaximum(), expectedRect.yMaximum(), 0.001 ) );
204+
QGSCOMPARENEAR( resultRect.xMinimum(), expectedRect.xMinimum(), 0.001 );
205+
QGSCOMPARENEAR( resultRect.yMinimum(), expectedRect.yMinimum(), 0.001 );
206+
QGSCOMPARENEAR( resultRect.xMaximum(), expectedRect.xMaximum(), 0.001 );
207+
QGSCOMPARENEAR( resultRect.yMaximum(), expectedRect.yMaximum(), 0.001 );
207208
}
208209

209210
QGSTEST_MAIN( TestQgsCoordinateTransform )

‎tests/src/core/testqgsdistancearea.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ void TestQgsDistanceArea::collections()
234234
double result = myDa.measureLength( lines );
235235
QGSCOMPARENEAR( result, 12006159, 1 );
236236
result = myDa.measureArea( lines );
237-
QVERIFY( qgsDoubleNear( result, 0 ) );
237+
QGSCOMPARENEAR( result, 0, 4 * DBL_EPSILON );
238238

239239
//collection of polygons
240240
QgsGeometry polys( QgsGeometryFactory::geomFromWkt( QStringLiteral( "GeometryCollection( Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) ).release() );
241241
result = myDa.measureArea( polys );
242242
QGSCOMPARENEAR( result, 670434859475LL, 1 );
243243
result = myDa.measureLength( polys );
244-
QVERIFY( qgsDoubleNear( result, 0 ) );
244+
QGSCOMPARENEAR( result, 0, 4 * DBL_EPSILON );
245245

246246
//mixed collection
247247
QgsGeometry mixed( QgsGeometryFactory::geomFromWkt( QStringLiteral( "GeometryCollection( LineString(0 36.53, 5.76 -48.16), LineString(0 25.54, 24.20 36.70), Polygon((0 36.53, 5.76 -48.16, 0 25.54, 0 36.53)), Polygon((10 20, 15 20, 15 10, 10 20)) )" ) ).release() );

‎tests/src/core/testqgsexpression.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "qgsrasterlayer.h"
3434
#include "qgsproject.h"
3535
#include "qgsexpressionnodeimpl.h"
36+
#include "qgstestutils.h"
3637

3738
static void _parseAndEvalExpr( int arg )
3839
{
@@ -921,7 +922,7 @@ class TestQgsExpression: public QObject
921922
QTest::newRow( "wordwrap with negative length" ) << "wordwrap('university of qgis',-3)" << false << QVariant( "university\nof qgis" );
922923
QTest::newRow( "wordwrap with negative length, custom delimiter" ) << "wordwrap('university of qgis',-3,' ')" << false << QVariant( "university\nof qgis" );
923924
QTest::newRow( "wordwrap on multi line" ) << "wordwrap('university of qgis\nsupports many multiline',-5,' ')" << false << QVariant( "university\nof qgis\nsupports\nmany multiline" );
924-
QTest::newRow( "wordwrap on zero-space width" ) << QStringLiteral( "wordwrap('test%1zero-width space',4)" ).arg( QChar(8203) ) << false << QVariant( "test\nzero-width\nspace" );
925+
QTest::newRow( "wordwrap on zero-space width" ) << QStringLiteral( "wordwrap('test%1zero-width space',4)" ).arg( QChar( 8203 ) ) << false << QVariant( "test\nzero-width\nspace" );
925926
QTest::newRow( "format" ) << "format('%1 %2 %3 %1', 'One', 'Two', 'Three')" << false << QVariant( "One Two Three One" );
926927
QTest::newRow( "concat" ) << "concat('a', 'b', 'c', 'd')" << false << QVariant( "abcd" );
927928
QTest::newRow( "concat function single" ) << "concat('a')" << false << QVariant( "a" );
@@ -1638,7 +1639,7 @@ class TestQgsExpression: public QObject
16381639
qDebug() << exp.evalErrorString();
16391640

16401641
QCOMPARE( exp.hasEvalError(), false );
1641-
QVERIFY( qgsDoubleNear( res.toDouble(), -85.65217, 0.00001 ) );
1642+
QGSCOMPARENEAR( res.toDouble(), -85.65217, 0.00001 );
16421643
}
16431644

16441645
void eval_rand()
@@ -1940,63 +1941,63 @@ class TestQgsExpression: public QObject
19401941
QgsExpression expArea( QStringLiteral( "$area" ) );
19411942
QVariant vArea = expArea.evaluate( &context );
19421943
double expected = 1005640568.0;
1943-
QVERIFY( qgsDoubleNear( vArea.toDouble(), expected, 1.0 ) );
1944+
QGSCOMPARENEAR( vArea.toDouble(), expected, 1.0 );
19441945
// units should not be converted if no geometry calculator set
19451946
expArea.setAreaUnits( QgsUnitTypes::AreaSquareFeet );
19461947
vArea = expArea.evaluate( &context );
1947-
QVERIFY( qgsDoubleNear( vArea.toDouble(), expected, 1.0 ) );
1948+
QGSCOMPARENEAR( vArea.toDouble(), expected, 1.0 );
19481949
expArea.setAreaUnits( QgsUnitTypes::AreaSquareNauticalMiles );
19491950
vArea = expArea.evaluate( &context );
1950-
QVERIFY( qgsDoubleNear( vArea.toDouble(), expected, 1.0 ) );
1951+
QGSCOMPARENEAR( vArea.toDouble(), expected, 1.0 );
19511952

19521953
// test area with geomCalculator
19531954
QgsExpression expArea2( QStringLiteral( "$area" ) );
19541955
expArea2.setGeomCalculator( &da );
19551956
vArea = expArea2.evaluate( &context );
19561957
expected = 1009089817.0;
1957-
QVERIFY( qgsDoubleNear( vArea.toDouble(), expected, 1.0 ) );
1958+
QGSCOMPARENEAR( vArea.toDouble(), expected, 1.0 );
19581959
// test unit conversion
19591960
expArea2.setAreaUnits( QgsUnitTypes::AreaSquareMeters ); //default units should be square meters
19601961
vArea = expArea2.evaluate( &context );
1961-
QVERIFY( qgsDoubleNear( vArea.toDouble(), expected, 1.0 ) );
1962+
QGSCOMPARENEAR( vArea.toDouble(), expected, 1.0 );
19621963
expArea2.setAreaUnits( QgsUnitTypes::AreaUnknownUnit ); //unknown units should not be converted
19631964
vArea = expArea2.evaluate( &context );
1964-
QVERIFY( qgsDoubleNear( vArea.toDouble(), expected, 1.0 ) );
1965+
QGSCOMPARENEAR( vArea.toDouble(), expected, 1.0 );
19651966
expArea2.setAreaUnits( QgsUnitTypes::AreaSquareMiles );
19661967
expected = 389.6117565069;
19671968
vArea = expArea2.evaluate( &context );
1968-
QVERIFY( qgsDoubleNear( vArea.toDouble(), expected, 0.001 ) );
1969+
QGSCOMPARENEAR( vArea.toDouble(), expected, 0.001 );
19691970

19701971
// test perimeter without geomCalculator
19711972
QgsExpression expPerimeter( QStringLiteral( "$perimeter" ) );
19721973
QVariant vPerimeter = expPerimeter.evaluate( &context );
19731974
expected = 128282.086;
1974-
QVERIFY( qgsDoubleNear( vPerimeter.toDouble(), expected, 0.001 ) );
1975+
QGSCOMPARENEAR( vPerimeter.toDouble(), expected, 0.001 );
19751976
// units should not be converted if no geometry calculator set
19761977
expPerimeter.setDistanceUnits( QgsUnitTypes::DistanceFeet );
19771978
vPerimeter = expPerimeter.evaluate( &context );
1978-
QVERIFY( qgsDoubleNear( vPerimeter.toDouble(), expected, 0.001 ) );
1979+
QGSCOMPARENEAR( vPerimeter.toDouble(), expected, 0.001 );
19791980
expPerimeter.setDistanceUnits( QgsUnitTypes::DistanceNauticalMiles );
19801981
vPerimeter = expPerimeter.evaluate( &context );
1981-
QVERIFY( qgsDoubleNear( vPerimeter.toDouble(), expected, 0.001 ) );
1982+
QGSCOMPARENEAR( vPerimeter.toDouble(), expected, 0.001 );
19821983

19831984
// test perimeter with geomCalculator
19841985
QgsExpression expPerimeter2( QStringLiteral( "$perimeter" ) );
19851986
expPerimeter2.setGeomCalculator( &da );
19861987
vPerimeter = expPerimeter2.evaluate( &context );
19871988
expected = 128289.074;
1988-
QVERIFY( qgsDoubleNear( vPerimeter.toDouble(), expected, 0.001 ) );
1989+
QGSCOMPARENEAR( vPerimeter.toDouble(), expected, 0.001 );
19891990
// test unit conversion
19901991
expPerimeter2.setDistanceUnits( QgsUnitTypes::DistanceMeters ); //default units should be meters
19911992
vPerimeter = expPerimeter2.evaluate( &context );
1992-
QVERIFY( qgsDoubleNear( vPerimeter.toDouble(), expected, 0.001 ) );
1993+
QGSCOMPARENEAR( vPerimeter.toDouble(), expected, 0.001 );
19931994
expPerimeter2.setDistanceUnits( QgsUnitTypes::DistanceUnknownUnit ); //unknown units should not be converted
19941995
vPerimeter = expPerimeter2.evaluate( &context );
1995-
QVERIFY( qgsDoubleNear( vPerimeter.toDouble(), expected, 0.001 ) );
1996+
QGSCOMPARENEAR( vPerimeter.toDouble(), expected, 0.001 );
19961997
expPerimeter2.setDistanceUnits( QgsUnitTypes::DistanceFeet );
19971998
expected = 420895.9120735;
19981999
vPerimeter = expPerimeter2.evaluate( &context );
1999-
QVERIFY( qgsDoubleNear( vPerimeter.toDouble(), expected, 0.001 ) );
2000+
QGSCOMPARENEAR( vPerimeter.toDouble(), expected, 0.001 );
20002001

20012002
// test length without geomCalculator
20022003
QgsPolyline line3111;
@@ -2008,32 +2009,32 @@ class TestQgsExpression: public QObject
20082009
QgsExpression expLength( QStringLiteral( "$length" ) );
20092010
QVariant vLength = expLength.evaluate( &context );
20102011
expected = 26930.637;
2011-
QVERIFY( qgsDoubleNear( vLength.toDouble(), expected, 0.001 ) );
2012+
QGSCOMPARENEAR( vLength.toDouble(), expected, 0.001 );
20122013
// units should not be converted if no geometry calculator set
20132014
expLength.setDistanceUnits( QgsUnitTypes::DistanceFeet );
20142015
vLength = expLength.evaluate( &context );
2015-
QVERIFY( qgsDoubleNear( vLength.toDouble(), expected, 0.001 ) );
2016+
QGSCOMPARENEAR( vLength.toDouble(), expected, 0.001 );
20162017
expLength.setDistanceUnits( QgsUnitTypes::DistanceNauticalMiles );
20172018
vLength = expLength.evaluate( &context );
2018-
QVERIFY( qgsDoubleNear( vLength.toDouble(), expected, 0.001 ) );
2019+
QGSCOMPARENEAR( vLength.toDouble(), expected, 0.001 );
20192020

20202021
// test length with geomCalculator
20212022
QgsExpression expLength2( QStringLiteral( "$length" ) );
20222023
expLength2.setGeomCalculator( &da );
20232024
vLength = expLength2.evaluate( &context );
20242025
expected = 26932.156;
2025-
QVERIFY( qgsDoubleNear( vLength.toDouble(), expected, 0.001 ) );
2026+
QGSCOMPARENEAR( vLength.toDouble(), expected, 0.001 );
20262027
// test unit conversion
20272028
expLength2.setDistanceUnits( QgsUnitTypes::DistanceMeters ); //default units should be meters
20282029
vLength = expLength2.evaluate( &context );
2029-
QVERIFY( qgsDoubleNear( vLength.toDouble(), expected, 0.001 ) );
2030+
QGSCOMPARENEAR( vLength.toDouble(), expected, 0.001 );
20302031
expLength2.setDistanceUnits( QgsUnitTypes::DistanceUnknownUnit ); //unknown units should not be converted
20312032
vLength = expLength2.evaluate( &context );
2032-
QVERIFY( qgsDoubleNear( vLength.toDouble(), expected, 0.001 ) );
2033+
QGSCOMPARENEAR( vLength.toDouble(), expected, 0.001 );
20332034
expLength2.setDistanceUnits( QgsUnitTypes::DistanceFeet );
20342035
expected = 88360.0918635;
20352036
vLength = expLength2.evaluate( &context );
2036-
QVERIFY( qgsDoubleNear( vLength.toDouble(), expected, 0.001 ) );
2037+
QGSCOMPARENEAR( vLength.toDouble(), expected, 0.001 );
20372038
}
20382039

20392040
void eval_geometry_wkt()

‎tests/src/core/testqgsgeometry.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ void TestQgsGeometry::point()
577577
//toQPointF
578578
QgsPoint p11a( 5.0, 9.0 );
579579
QPointF result = p11a.toQPointF();
580-
QVERIFY( qgsDoubleNear( result.x(), 5.0 ) );
581-
QVERIFY( qgsDoubleNear( result.y(), 9.0 ) );
580+
QGSCOMPARENEAR( result.x(), 5.0, 4 * DBL_EPSILON );
581+
QGSCOMPARENEAR( result.y(), 9.0, 4 * DBL_EPSILON );
582582

583583
//to/from WKB
584584
QgsPoint p12( QgsWkbTypes::PointZM, 1.0, 2.0, 3.0, -4.0 );
@@ -2360,26 +2360,26 @@ void TestQgsGeometry::lineString()
23602360
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) );
23612361
QVERIFY( l35.closestSegment( QgsPoint( 5, 10 ), p, v, 0, 0 ) < 0 );
23622362
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) << QgsPoint( 10, 10 ) );
2363-
QVERIFY( qgsDoubleNear( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf, 0 ), 2.0 ) );
2363+
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 4, 11 ), p, v, &leftOf, 0 ), 2.0, 4 * DBL_EPSILON );
23642364
QCOMPARE( p, QgsPoint( 5, 10 ) );
23652365
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
23662366
QCOMPARE( leftOf, true );
2367-
QVERIFY( qgsDoubleNear( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf, 0 ), 1.0 ) );
2367+
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 11 ), p, v, &leftOf, 0 ), 1.0, 4 * DBL_EPSILON );
23682368
QCOMPARE( p, QgsPoint( 8, 10 ) );
23692369
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
23702370
QCOMPARE( leftOf, true );
2371-
QVERIFY( qgsDoubleNear( l35.closestSegment( QgsPoint( 8, 9 ), p, v, &leftOf, 0 ), 1.0 ) );
2371+
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 8, 9 ), p, v, &leftOf, 0 ), 1.0, 4 * DBL_EPSILON );
23722372
QCOMPARE( p, QgsPoint( 8, 10 ) );
23732373
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
23742374
QCOMPARE( leftOf, false );
2375-
QVERIFY( qgsDoubleNear( l35.closestSegment( QgsPoint( 11, 9 ), p, v, &leftOf, 0 ), 2.0 ) );
2375+
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 9 ), p, v, &leftOf, 0 ), 2.0, 4 * DBL_EPSILON );
23762376
QCOMPARE( p, QgsPoint( 10, 10 ) );
23772377
QCOMPARE( v, QgsVertexId( 0, 0, 1 ) );
23782378
QCOMPARE( leftOf, false );
23792379
l35.setPoints( QgsPointSequence() << QgsPoint( 5, 10 )
23802380
<< QgsPoint( 10, 10 )
23812381
<< QgsPoint( 10, 15 ) );
2382-
QVERIFY( qgsDoubleNear( l35.closestSegment( QgsPoint( 11, 12 ), p, v, &leftOf, 0 ), 1.0 ) );
2382+
QGSCOMPARENEAR( l35.closestSegment( QgsPoint( 11, 12 ), p, v, &leftOf, 0 ), 1.0, 4 * DBL_EPSILON );
23832383
QCOMPARE( p, QgsPoint( 10, 12 ) );
23842384
QCOMPARE( v, QgsVertexId( 0, 0, 2 ) );
23852385
QCOMPARE( leftOf, false );
@@ -2394,13 +2394,13 @@ void TestQgsGeometry::lineString()
23942394
QCOMPARE( area, 1.0 );
23952395
l36.setPoints( QgsPointSequence() << QgsPoint( 5, 10 ) << QgsPoint( 10, 10 ) );
23962396
l36.sumUpArea( area );
2397-
QVERIFY( qgsDoubleNear( area, -24 ) );
2397+
QGSCOMPARENEAR( area, -24, 4 * DBL_EPSILON );
23982398
l36.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 2, 0 ) << QgsPoint( 2, 2 ) );
23992399
l36.sumUpArea( area );
2400-
QVERIFY( qgsDoubleNear( area, -22 ) );
2400+
QGSCOMPARENEAR( area, -22, 4 * DBL_EPSILON );
24012401
l36.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 2, 0 ) << QgsPoint( 2, 2 ) << QgsPoint( 0, 2 ) );
24022402
l36.sumUpArea( area );
2403-
QVERIFY( qgsDoubleNear( area, -18 ) );
2403+
QGSCOMPARENEAR( area, -18, 4 * DBL_EPSILON );
24042404

24052405
//boundingBox - test that bounding box is updated after every modification to the line string
24062406
QgsLineString l37;
@@ -2445,36 +2445,36 @@ void TestQgsGeometry::lineString()
24452445
l38.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) );
24462446
( void )l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ); //just want no crash, any answer is meaningless
24472447
l38.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 1, 0 ) );
2448-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 1.5708, 0.0001 ) );
2449-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 1.5708, 0.0001 ) );
2448+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 1.5708, 0.0001 );
2449+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 1.5708, 0.0001 );
24502450
( void )l38.vertexAngle( QgsVertexId( 0, 0, 2 ) ); //no crash
24512451
l38.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 0, 1 ) );
2452-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 0.0 ) );
2453-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 0.0 ) );
2452+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 0.0, 4 * DBL_EPSILON );
2453+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 0.0, 4 * DBL_EPSILON );
24542454
l38.setPoints( QgsPointSequence() << QgsPoint( 1, 0 ) << QgsPoint( 0, 0 ) );
2455-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 4.71239, 0.0001 ) );
2456-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 4.71239, 0.0001 ) );
2455+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 4.71239, 0.0001 );
2456+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 4.71239, 0.0001 );
24572457
l38.setPoints( QgsPointSequence() << QgsPoint( 0, 1 ) << QgsPoint( 0, 0 ) );
2458-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 3.1416, 0.0001 ) );
2459-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 3.1416, 0.0001 ) );
2458+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 3.1416, 0.0001 );
2459+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 3.1416, 0.0001 );
24602460
l38.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 1, 0 ) << QgsPoint( 1, 1 ) );
2461-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 1.5708, 0.0001 ) );
2462-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 0.7854, 0.0001 ) );
2463-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 2 ) ), 0.0, 0.0001 ) );
2461+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 1.5708, 0.0001 );
2462+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 0.7854, 0.0001 );
2463+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 2 ) ), 0.0, 0.0001 );
24642464
l38.setPoints( QgsPointSequence() << QgsPoint( 0, 0 ) << QgsPoint( 0.5, 0 ) << QgsPoint( 1, 0 )
24652465
<< QgsPoint( 2, 1 ) << QgsPoint( 1, 2 ) << QgsPoint( 0, 2 ) );
24662466
( void )l38.vertexAngle( QgsVertexId( 0, 0, 20 ) );
2467-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 1.5708, 0.0001 ) );
2468-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 1.5708, 0.0001 ) );
2469-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 2 ) ), 1.17809, 0.00001 ) );
2470-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 3 ) ), 0.0, 0.00001 ) );
2471-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 4 ) ), 5.10509, 0.00001 ) );
2472-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 5 ) ), 4.71239, 0.00001 ) );
2467+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 1.5708, 0.0001 );
2468+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 1 ) ), 1.5708, 0.0001 );
2469+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 2 ) ), 1.17809, 0.00001 );
2470+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 3 ) ), 0.0, 0.00001 );
2471+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 4 ) ), 5.10509, 0.00001 );
2472+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 5 ) ), 4.71239, 0.00001 );
24732473
//closed line string
24742474
l38.close();
2475-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 5 ) ), 3.92699, 0.00001 ) );
2476-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 2.35619, 0.00001 ) );
2477-
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 6 ) ), 2.35619, 0.00001 ) );
2475+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 5 ) ), 3.92699, 0.00001 );
2476+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 2.35619, 0.00001 );
2477+
QGSCOMPARENEAR( l38.vertexAngle( QgsVertexId( 0, 0, 6 ) ), 2.35619, 0.00001 );
24782478

24792479
//removing the second to last vertex should remove the whole line
24802480
QgsLineString l39;
@@ -4473,7 +4473,7 @@ void TestQgsGeometry::compoundCurve()
44734473
<< QgsPoint( 1, 1 ) );
44744474
double lsArea = 0.0;
44754475
ls.sumUpArea( lsArea );
4476-
QVERIFY( qgsDoubleNear( ccArea, lsArea ) );
4476+
QGSCOMPARENEAR( ccArea, lsArea, 4 * DBL_EPSILON );
44774477
}
44784478

44794479
void TestQgsGeometry::multiPoint()

‎tests/src/core/testqgsgeometryimport.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222

2323
#include "qgstest.h"
24+
#include "qgstestutils.h"
25+
2426
#include <QObject>
2527

2628
class TestQgsGeometryImport: public QObject
@@ -81,8 +83,8 @@ void TestQgsGeometryImport::pointWkt()
8183
QCOMPARE( geom.wkbType(), QgsWkbTypes::Point );
8284
QgsPointXY point = geom.asPoint();
8385

84-
QVERIFY( qgsDoubleNear( point.x(), x ) );
85-
QVERIFY( qgsDoubleNear( point.y(), y ) );
86+
QGSCOMPARENEAR( point.x(), x, 4 * DBL_EPSILON );
87+
QGSCOMPARENEAR( point.y(), y, 4 * DBL_EPSILON );
8688
}
8789

8890
void TestQgsGeometryImport::pointWkb_data()
@@ -109,8 +111,8 @@ void TestQgsGeometryImport::pointWkb()
109111
QgsPointXY point = geom.asPoint();
110112

111113
QCOMPARE( geom.wkbType(), QgsWkbTypes::Point );
112-
QVERIFY( qgsDoubleNear( point.x(), x ) );
113-
QVERIFY( qgsDoubleNear( point.y(), y ) );
114+
QGSCOMPARENEAR( point.x(), x, 4 * DBL_EPSILON );
115+
QGSCOMPARENEAR( point.y(), y, 4 * DBL_EPSILON );
114116
}
115117

116118
void TestQgsGeometryImport::pointGeos_data()
@@ -137,8 +139,8 @@ void TestQgsGeometryImport::pointGeos()
137139

138140
QgsPointXY geomPt = geom.asPoint();
139141

140-
QVERIFY( qgsDoubleNear( x, geomPt.x() ) );
141-
QVERIFY( qgsDoubleNear( y, geomPt.y() ) );
142+
QGSCOMPARENEAR( x, geomPt.x(), 4 * DBL_EPSILON );
143+
QGSCOMPARENEAR( y, geomPt.y(), 4 * DBL_EPSILON );
142144
}
143145

144146
void TestQgsGeometryImport::linestringWkt_data()

‎tests/src/core/testqgsgeometryutils.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ void TestQgsGeometryUtils::testSegmentMidPoint()
190190
midPoint, radius, left );
191191

192192
QVERIFY( ok );
193-
QVERIFY( qgsDoubleNear( midPoint.x(), expectedX ) );
194-
QVERIFY( qgsDoubleNear( midPoint.y(), expectedY ) );
193+
QGSCOMPARENEAR( midPoint.x(), expectedX, 4 * DBL_EPSILON );
194+
QGSCOMPARENEAR( midPoint.y(), expectedY, 4 * DBL_EPSILON );
195195
}
196196

197197
void TestQgsGeometryUtils::testCircleLength_data()
@@ -218,7 +218,7 @@ void TestQgsGeometryUtils::testCircleLength()
218218
QFETCH( double, y3 );
219219
QFETCH( double, expected );
220220

221-
QVERIFY( qgsDoubleNear( expected, QgsGeometryUtils::circleLength( x1, y1, x2, y2, x3, y3 ) ) );
221+
QGSCOMPARENEAR( expected, QgsGeometryUtils::circleLength( x1, y1, x2, y2, x3, y3 ), 4 * DBL_EPSILON );
222222
}
223223

224224
void TestQgsGeometryUtils::testNormalizedAngle_data()
@@ -243,7 +243,7 @@ void TestQgsGeometryUtils::testNormalizedAngle()
243243
{
244244
QFETCH( double, input );
245245
QFETCH( double, expected );
246-
QVERIFY( qgsDoubleNear( expected, QgsGeometryUtils::normalizedAngle( input ), 0.0001 ) );
246+
QGSCOMPARENEAR( expected, QgsGeometryUtils::normalizedAngle( input ), 0.0001 );
247247
}
248248

249249
void TestQgsGeometryUtils::testLineAngle_data()
@@ -275,7 +275,7 @@ void TestQgsGeometryUtils::testLineAngle()
275275

276276
double lineAngle = QgsGeometryUtils::lineAngle( x1, y1, x2, y2 ) * 180 / M_PI;
277277
if ( expected > -99999 )
278-
QVERIFY( qgsDoubleNear( lineAngle, expected ) );
278+
QGSCOMPARENEAR( lineAngle, expected, 4 * DBL_EPSILON );
279279
}
280280

281281
void TestQgsGeometryUtils::testLinePerpendicularAngle_data()
@@ -307,7 +307,7 @@ void TestQgsGeometryUtils::testLinePerpendicularAngle()
307307

308308
double pAngle = QgsGeometryUtils::linePerpendicularAngle( x1, y1, x2, y2 ) * 180 / M_PI;
309309
if ( expected > -99999 )
310-
QVERIFY( qgsDoubleNear( pAngle, expected, 0.01 ) );
310+
QGSCOMPARENEAR( pAngle, expected, 0.01 );
311311
}
312312

313313
void TestQgsGeometryUtils::testAverageAngle_data()
@@ -340,7 +340,7 @@ void TestQgsGeometryUtils::testAverageAngle()
340340
QFETCH( double, expected );
341341

342342
double averageAngle = QgsGeometryUtils::averageAngle( angle1 * M_PI / 180.0, angle2 * M_PI / 180.0 ) * 180.0 / M_PI;
343-
QVERIFY( qgsDoubleNear( averageAngle, expected, 0.0000000001 ) );
343+
QGSCOMPARENEAR( averageAngle, expected, 0.0000000001 );
344344
}
345345

346346
void TestQgsGeometryUtils::testAdjacentVertices()
@@ -503,9 +503,9 @@ void TestQgsGeometryUtils::testCircleCenterRadius()
503503

504504
double radius, centerX, centerY;
505505
QgsGeometryUtils::circleCenterRadius( QgsPoint( x1, y1 ), QgsPoint( x2, y2 ), QgsPoint( x3, y3 ), radius, centerX, centerY );
506-
QVERIFY( qgsDoubleNear( expectedRadius, radius ) );
507-
QVERIFY( qgsDoubleNear( expectedCenterX, centerX ) );
508-
QVERIFY( qgsDoubleNear( expectedCenterY, centerY ) );
506+
QGSCOMPARENEAR( expectedRadius, radius, 4 * DBL_EPSILON );
507+
QGSCOMPARENEAR( expectedCenterX, centerX, 4 * DBL_EPSILON );
508+
QGSCOMPARENEAR( expectedCenterY, centerY, 4 * DBL_EPSILON );
509509
}
510510

511511
//QgsGeometryUtils::sqrDistToLine

‎tests/src/core/testqgshistogram.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgsvectorlayer.h"
2121
#include "qgsvectordataprovider.h"
2222
#include "qgshistogram.h"
23+
#include "qgstestutils.h"
2324

2425
/** \ingroup UnitTests
2526
* This is a unit test for QgsHistogram
@@ -70,7 +71,7 @@ void TestQgsHistogram::optimalBinWidth()
7071

7172
QgsHistogram h;
7273
h.setValues( vals );
73-
QVERIFY( qgsDoubleNear( h.optimalBinWidth(), 4.641, 0.001 ) );
74+
QGSCOMPARENEAR( h.optimalBinWidth(), 4.641, 0.001 );
7475
}
7576

7677
void TestQgsHistogram::optimalBinCount()

‎tests/src/core/testqgslayoutitem.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgstest.h"
2323
#include "qgsproject.h"
2424
#include "qgsreadwritecontext.h"
25+
#include "qgstestutils.h"
2526
#include <QObject>
2627
#include <QPainter>
2728
#include <QImage>
@@ -1009,13 +1010,13 @@ void TestQgsLayoutItem::fixedSize()
10091010
item->setRect( 0, 0, 5.0, 6.0 ); //temporarily set rect to random size
10101011
item->attemptResize( QgsLayoutSize( 7.0, 8.0, QgsUnitTypes::LayoutPoints ) );
10111012
//check size matches fixed item size converted to mm
1012-
QVERIFY( qgsDoubleNear( item->rect().width(), 2.0 * 25.4 ) );
1013-
QVERIFY( qgsDoubleNear( item->rect().height(), 4.0 * 25.4 ) );
1013+
QGSCOMPARENEAR( item->rect().width(), 2.0 * 25.4, 4 * DBL_EPSILON );
1014+
QGSCOMPARENEAR( item->rect().height(), 4.0 * 25.4, 4 * DBL_EPSILON );
10141015

10151016
//check that setting a fixed size applies this size immediately
10161017
item->updateFixedSize( QgsLayoutSize( 150, 250, QgsUnitTypes::LayoutMillimeters ) );
1017-
QVERIFY( qgsDoubleNear( item->rect().width(), 150.0 ) );
1018-
QVERIFY( qgsDoubleNear( item->rect().height(), 250.0 ) );
1018+
QGSCOMPARENEAR( item->rect().width(), 150.0, 4 * DBL_EPSILON );
1019+
QGSCOMPARENEAR( item->rect().height(), 250.0, 4 * DBL_EPSILON );
10191020
}
10201021

10211022
void TestQgsLayoutItem::minSize()
@@ -1033,18 +1034,18 @@ void TestQgsLayoutItem::minSize()
10331034
//try to resize to less than minimum size
10341035
item->attemptResize( QgsLayoutSize( 1.0, 0.5, QgsUnitTypes::LayoutPoints ) );
10351036
//check size matches min item size converted to mm
1036-
QVERIFY( qgsDoubleNear( item->rect().width(), 50.0 ) );
1037-
QVERIFY( qgsDoubleNear( item->rect().height(), 100.0 ) );
1037+
QGSCOMPARENEAR( item->rect().width(), 50.0, 4 * DBL_EPSILON );
1038+
QGSCOMPARENEAR( item->rect().height(), 100.0, 4 * DBL_EPSILON );
10381039

10391040
//check that resize to larger than min size works
10401041
item->attemptResize( QgsLayoutSize( 0.1, 0.2, QgsUnitTypes::LayoutMeters ) );
1041-
QVERIFY( qgsDoubleNear( item->rect().width(), 100.0 ) );
1042-
QVERIFY( qgsDoubleNear( item->rect().height(), 200.0 ) );
1042+
QGSCOMPARENEAR( item->rect().width(), 100.0, 4 * DBL_EPSILON );
1043+
QGSCOMPARENEAR( item->rect().height(), 200.0, 4 * DBL_EPSILON );
10431044

10441045
//check that setting a minimum size applies this size immediately
10451046
item->updateMinSize( QgsLayoutSize( 150, 250, QgsUnitTypes::LayoutMillimeters ) );
1046-
QVERIFY( qgsDoubleNear( item->rect().width(), 150.0 ) );
1047-
QVERIFY( qgsDoubleNear( item->rect().height(), 250.0 ) );
1047+
QGSCOMPARENEAR( item->rect().width(), 150.0, 4 * DBL_EPSILON );
1048+
QGSCOMPARENEAR( item->rect().height(), 250.0, 4 * DBL_EPSILON );
10481049

10491050
//also need check that fixed size trumps min size
10501051
FixedMinSizedItem *fixedMinItem = new FixedMinSizedItem( &l );
@@ -1057,8 +1058,8 @@ void TestQgsLayoutItem::minSize()
10571058
//try to resize to less than minimum size
10581059
fixedMinItem->attemptResize( QgsLayoutSize( 1.0, 0.5, QgsUnitTypes::LayoutPoints ) );
10591060
//check size matches fixed item size, not minimum size (converted to mm)
1060-
QVERIFY( qgsDoubleNear( fixedMinItem->rect().width(), 50.0 ) );
1061-
QVERIFY( qgsDoubleNear( fixedMinItem->rect().height(), 90.0 ) );
1061+
QGSCOMPARENEAR( fixedMinItem->rect().width(), 50.0, 4 * DBL_EPSILON );
1062+
QGSCOMPARENEAR( fixedMinItem->rect().height(), 90.0, 4 * DBL_EPSILON );
10621063
}
10631064

10641065
void TestQgsLayoutItem::move()

‎tests/src/core/testqgslayoutunits.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgslayoutsize.h"
2424
#include "qgslayoutmeasurementconverter.h"
2525
#include "qgis.h"
26+
#include "qgstestutils.h"
2627

2728
class TestQgsLayoutUnits : public QObject
2829
{
@@ -670,13 +671,13 @@ void TestQgsLayoutUnits::conversionToInches()
670671
QCOMPARE( convertedFromPoints.units(), QgsUnitTypes::LayoutInches );
671672
QCOMPARE( convertedFromPicas.units(), QgsUnitTypes::LayoutInches );
672673

673-
QVERIFY( qgsDoubleNear( convertedFromMillimeters.length(), 0.0393701, 0.000001 ) );
674-
QVERIFY( qgsDoubleNear( convertedFromCentimeters.length(), 0.3937008, 0.000001 ) );
675-
QVERIFY( qgsDoubleNear( convertedFromMeters.length(), 39.3700787, 0.000001 ) );
674+
QGSCOMPARENEAR( convertedFromMillimeters.length(), 0.0393701, 0.000001 );
675+
QGSCOMPARENEAR( convertedFromCentimeters.length(), 0.3937008, 0.000001 );
676+
QGSCOMPARENEAR( convertedFromMeters.length(), 39.3700787, 0.000001 );
676677
QCOMPARE( convertedFromInches.length(), 1.0 );
677678
QCOMPARE( convertedFromFeet.length(), 12.0 );
678-
QVERIFY( qgsDoubleNear( convertedFromPoints.length(), 0.0138888889, 0.000001 ) );
679-
QVERIFY( qgsDoubleNear( convertedFromPicas.length(), 0.166666667, 0.000001 ) );
679+
QGSCOMPARENEAR( convertedFromPoints.length(), 0.0138888889, 0.000001 );
680+
QGSCOMPARENEAR( convertedFromPicas.length(), 0.166666667, 0.000001 );
680681
}
681682

682683
void TestQgsLayoutUnits::conversionToFeet()
@@ -706,13 +707,13 @@ void TestQgsLayoutUnits::conversionToFeet()
706707
QCOMPARE( convertedFromPoints.units(), QgsUnitTypes::LayoutFeet );
707708
QCOMPARE( convertedFromPicas.units(), QgsUnitTypes::LayoutFeet );
708709

709-
QVERIFY( qgsDoubleNear( convertedFromMillimeters.length(), 0.0032808399, 0.000001 ) );
710-
QVERIFY( qgsDoubleNear( convertedFromCentimeters.length(), 0.032808399, 0.000001 ) );
711-
QVERIFY( qgsDoubleNear( convertedFromMeters.length(), 3.2808399, 0.000001 ) );
712-
QVERIFY( qgsDoubleNear( convertedFromInches.length(), 0.0833333, 0.000001 ) );
710+
QGSCOMPARENEAR( convertedFromMillimeters.length(), 0.0032808399, 0.000001 );
711+
QGSCOMPARENEAR( convertedFromCentimeters.length(), 0.032808399, 0.000001 );
712+
QGSCOMPARENEAR( convertedFromMeters.length(), 3.2808399, 0.000001 );
713+
QGSCOMPARENEAR( convertedFromInches.length(), 0.0833333, 0.000001 );
713714
QCOMPARE( convertedFromFeet.length(), 1.0 );
714-
QVERIFY( qgsDoubleNear( convertedFromPoints.length(), 0.00115740741, 0.000001 ) );
715-
QVERIFY( qgsDoubleNear( convertedFromPicas.length(), 0.0138888889, 0.000001 ) );
715+
QGSCOMPARENEAR( convertedFromPoints.length(), 0.00115740741, 0.000001 );
716+
QGSCOMPARENEAR( convertedFromPicas.length(), 0.0138888889, 0.000001 );
716717
}
717718

718719
void TestQgsLayoutUnits::conversionToPoints()
@@ -742,13 +743,13 @@ void TestQgsLayoutUnits::conversionToPoints()
742743
QCOMPARE( convertedFromPoints.units(), QgsUnitTypes::LayoutPoints );
743744
QCOMPARE( convertedFromPicas.units(), QgsUnitTypes::LayoutPoints );
744745

745-
QVERIFY( qgsDoubleNear( convertedFromMillimeters.length(), 2.83464567, 0.000001 ) );
746-
QVERIFY( qgsDoubleNear( convertedFromCentimeters.length(), 28.3464567, 0.000001 ) );
747-
QVERIFY( qgsDoubleNear( convertedFromMeters.length(), 2834.64567, 0.000001 ) );
748-
QVERIFY( qgsDoubleNear( convertedFromInches.length(), 72.0, 0.000001 ) );
749-
QVERIFY( qgsDoubleNear( convertedFromFeet.length(), 864.0, 0.000001 ) );
746+
QGSCOMPARENEAR( convertedFromMillimeters.length(), 2.83464567, 0.000001 );
747+
QGSCOMPARENEAR( convertedFromCentimeters.length(), 28.3464567, 0.000001 );
748+
QGSCOMPARENEAR( convertedFromMeters.length(), 2834.64567, 0.000001 );
749+
QGSCOMPARENEAR( convertedFromInches.length(), 72.0, 0.000001 );
750+
QGSCOMPARENEAR( convertedFromFeet.length(), 864.0, 0.000001 );
750751
QCOMPARE( convertedFromPoints.length(), 1.0 );
751-
QVERIFY( qgsDoubleNear( convertedFromPicas.length(), 12.0, 0.000001 ) );
752+
QGSCOMPARENEAR( convertedFromPicas.length(), 12.0, 0.000001 );
752753
}
753754

754755
void TestQgsLayoutUnits::conversionToPicas()
@@ -778,12 +779,12 @@ void TestQgsLayoutUnits::conversionToPicas()
778779
QCOMPARE( convertedFromPoints.units(), QgsUnitTypes::LayoutPicas );
779780
QCOMPARE( convertedFromPicas.units(), QgsUnitTypes::LayoutPicas );
780781

781-
QVERIFY( qgsDoubleNear( convertedFromMillimeters.length(), 0.236220472, 0.000001 ) );
782-
QVERIFY( qgsDoubleNear( convertedFromCentimeters.length(), 2.36220472, 0.000001 ) );
783-
QVERIFY( qgsDoubleNear( convertedFromMeters.length(), 236.220472, 0.000001 ) );
784-
QVERIFY( qgsDoubleNear( convertedFromInches.length(), 6.0, 0.000001 ) );
785-
QVERIFY( qgsDoubleNear( convertedFromFeet.length(), 72.0, 0.000001 ) );
786-
QVERIFY( qgsDoubleNear( convertedFromPoints.length(), 0.0833333333, 0.000001 ) );
782+
QGSCOMPARENEAR( convertedFromMillimeters.length(), 0.236220472, 0.000001 );
783+
QGSCOMPARENEAR( convertedFromCentimeters.length(), 2.36220472, 0.000001 );
784+
QGSCOMPARENEAR( convertedFromMeters.length(), 236.220472, 0.000001 );
785+
QGSCOMPARENEAR( convertedFromInches.length(), 6.0, 0.000001 );
786+
QGSCOMPARENEAR( convertedFromFeet.length(), 72.0, 0.000001 );
787+
QGSCOMPARENEAR( convertedFromPoints.length(), 0.0833333333, 0.000001 );
787788
QCOMPARE( convertedFromPicas.length(), 1.0 );
788789
}
789790

@@ -803,19 +804,19 @@ void TestQgsLayoutUnits::conversionFromPixels()
803804
converter.setDpi( 300.0 );
804805
QgsLayoutMeasurement convertedToInches = converter.convert( measurementInPixels, QgsUnitTypes::LayoutInches );
805806
QCOMPARE( convertedToInches.units(), QgsUnitTypes::LayoutInches );
806-
QVERIFY( qgsDoubleNear( convertedToInches.length(), 1.0, 0.000001 ) );
807+
QGSCOMPARENEAR( convertedToInches.length(), 1.0, 0.000001 );
807808
QgsLayoutMeasurement convertedToMM = converter.convert( measurementInPixels, QgsUnitTypes::LayoutMillimeters );
808809
QCOMPARE( convertedToMM.units(), QgsUnitTypes::LayoutMillimeters );
809-
QVERIFY( qgsDoubleNear( convertedToMM.length(), 25.4, 0.000001 ) );
810+
QGSCOMPARENEAR( convertedToMM.length(), 25.4, 0.000001 );
810811

811812
//try with 96 dpi
812813
converter.setDpi( 96.0 );
813814
convertedToInches = converter.convert( measurementInPixels, QgsUnitTypes::LayoutInches );
814815
QCOMPARE( convertedToInches.units(), QgsUnitTypes::LayoutInches );
815-
QVERIFY( qgsDoubleNear( convertedToInches.length(), 3.125, 0.000001 ) );
816+
QGSCOMPARENEAR( convertedToInches.length(), 3.125, 0.000001 );
816817
convertedToMM = converter.convert( measurementInPixels, QgsUnitTypes::LayoutMillimeters );
817818
QCOMPARE( convertedToMM.units(), QgsUnitTypes::LayoutMillimeters );
818-
QVERIFY( qgsDoubleNear( convertedToMM.length(), 79.375, 0.000001 ) );
819+
QGSCOMPARENEAR( convertedToMM.length(), 79.375, 0.000001 );
819820
}
820821

821822
void TestQgsLayoutUnits::conversionToPixels()
@@ -828,19 +829,19 @@ void TestQgsLayoutUnits::conversionToPixels()
828829
converter.setDpi( 300.0 );
829830
QgsLayoutMeasurement convertedToPixels = converter.convert( measurementInInches, QgsUnitTypes::LayoutPixels );
830831
QCOMPARE( convertedToPixels.units(), QgsUnitTypes::LayoutPixels );
831-
QVERIFY( qgsDoubleNear( convertedToPixels.length(), 300.0, 0.000001 ) );
832+
QGSCOMPARENEAR( convertedToPixels.length(), 300.0, 0.000001 );
832833
convertedToPixels = converter.convert( measurementInMM, QgsUnitTypes::LayoutPixels );
833834
QCOMPARE( convertedToPixels.units(), QgsUnitTypes::LayoutPixels );
834-
QVERIFY( qgsDoubleNear( convertedToPixels.length(), 11.811023622, 0.000001 ) );
835+
QGSCOMPARENEAR( convertedToPixels.length(), 11.811023622, 0.000001 );
835836

836837
//try with 96 dpi
837838
converter.setDpi( 96.0 );
838839
convertedToPixels = converter.convert( measurementInInches, QgsUnitTypes::LayoutPixels );
839840
QCOMPARE( convertedToPixels.units(), QgsUnitTypes::LayoutPixels );
840-
QVERIFY( qgsDoubleNear( convertedToPixels.length(), 96.0, 0.000001 ) );
841+
QGSCOMPARENEAR( convertedToPixels.length(), 96.0, 0.000001 );
841842
convertedToPixels = converter.convert( measurementInMM, QgsUnitTypes::LayoutPixels );
842843
QCOMPARE( convertedToPixels.units(), QgsUnitTypes::LayoutPixels );
843-
QVERIFY( qgsDoubleNear( convertedToPixels.length(), 3.77952755906, 0.000001 ) );
844+
QGSCOMPARENEAR( convertedToPixels.length(), 3.77952755906, 0.000001 );
844845
}
845846

846847
void TestQgsLayoutUnits::sizeConversion()

‎tests/src/core/testqgslayoututils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void TestQgsLayoutUtils::normalizedAngle()
9090
{
9191
double result = QgsLayoutUtils::normalizedAngle( ( *it ).first );
9292
qDebug() << QString( "actual: %1 expected: %2" ).arg( result ).arg( ( *it ).second );
93-
QVERIFY( qgsDoubleNear( result, ( *it ).second ) );
93+
QGSCOMPARENEAR( result, ( *it ).second, 4 * DBL_EPSILON );
9494

9595
}
9696

@@ -111,7 +111,7 @@ void TestQgsLayoutUtils::normalizedAngle()
111111
{
112112
double result = QgsLayoutUtils::normalizedAngle( ( *it ).first, true );
113113
qDebug() << QString( "actual: %1 expected: %2" ).arg( result ).arg( ( *it ).second );
114-
QVERIFY( qgsDoubleNear( result, ( *it ).second ) );
114+
QGSCOMPARENEAR( result, ( *it ).second, 4 * DBL_EPSILON );
115115

116116
}
117117
}

‎tests/src/core/testqgspoint.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <qgsgeometry.h>
2626
//header for class being tested
2727
#include <qgspoint.h>
28+
#include "qgstestutils.h"
2829

2930
class TestQgsPointXY: public QObject
3031
{
@@ -711,30 +712,30 @@ void TestQgsPointXY::vector()
711712

712713
// length
713714
QCOMPARE( v1.length(), 0.0 );
714-
QVERIFY( qgsDoubleNear( v2.length(), std::sqrt( 5.0 ), 0.000000001 ) );
715+
QGSCOMPARENEAR( v2.length(), std::sqrt( 5.0 ), 0.000000001 );
715716

716717
// perpVector
717718
QCOMPARE( QgsVector( 2, 3 ).perpVector().x(), -3.0 );
718719
QCOMPARE( QgsVector( 2, 3 ).perpVector().y(), 2.0 );
719720

720721
// angle
721-
QVERIFY( qgsDoubleNear( QgsVector( 0, 1 ).angle(), M_PI_2, 0.0000001 ) );
722-
QVERIFY( qgsDoubleNear( QgsVector( 1, 0 ).angle(), 0, 0.0000001 ) );
723-
QVERIFY( qgsDoubleNear( QgsVector( -1, 0 ).angle(), M_PI, 0.0000001 ) );
724-
QVERIFY( qgsDoubleNear( QgsVector( 0, -1 ).angle(), 3 * M_PI_2, 0.0000001 ) );
725-
QVERIFY( qgsDoubleNear( QgsVector( 0, 0 ).angle(), 0, 0.0000001 ) );
726-
727-
QVERIFY( qgsDoubleNear( QgsVector( 0, 1 ).angle( QgsVector( 0, 1 ) ), 0, 0.0000001 ) );
728-
QVERIFY( qgsDoubleNear( QgsVector( 1, 0 ).angle( QgsVector( 0, 1 ) ), M_PI_2, 0.0000001 ) );
729-
QVERIFY( qgsDoubleNear( QgsVector( 0, 1 ).angle( QgsVector( -1, 0 ) ), M_PI_2, 0.0000001 ) );
730-
QVERIFY( qgsDoubleNear( QgsVector( 1, 0 ).angle( QgsVector( -1, 0 ) ), M_PI, 0.0000001 ) );
731-
QVERIFY( qgsDoubleNear( QgsVector( -1, 0 ).angle( QgsVector( 0, 0 ) ), -M_PI, 0.0000001 ) );
722+
QGSCOMPARENEAR( QgsVector( 0, 1 ).angle(), M_PI_2, 0.0000001 );
723+
QGSCOMPARENEAR( QgsVector( 1, 0 ).angle(), 0, 0.0000001 );
724+
QGSCOMPARENEAR( QgsVector( -1, 0 ).angle(), M_PI, 0.0000001 );
725+
QGSCOMPARENEAR( QgsVector( 0, -1 ).angle(), 3 * M_PI_2, 0.0000001 );
726+
QGSCOMPARENEAR( QgsVector( 0, 0 ).angle(), 0, 0.0000001 );
727+
728+
QGSCOMPARENEAR( QgsVector( 0, 1 ).angle( QgsVector( 0, 1 ) ), 0, 0.0000001 );
729+
QGSCOMPARENEAR( QgsVector( 1, 0 ).angle( QgsVector( 0, 1 ) ), M_PI_2, 0.0000001 );
730+
QGSCOMPARENEAR( QgsVector( 0, 1 ).angle( QgsVector( -1, 0 ) ), M_PI_2, 0.0000001 );
731+
QGSCOMPARENEAR( QgsVector( 1, 0 ).angle( QgsVector( -1, 0 ) ), M_PI, 0.0000001 );
732+
QGSCOMPARENEAR( QgsVector( -1, 0 ).angle( QgsVector( 0, 0 ) ), -M_PI, 0.0000001 );
732733

733734
// rotateBy
734-
QVERIFY( qgsDoubleNear( QgsVector( 0, 1 ).rotateBy( M_PI_2 ).x(), -1.0, 0.0000001 ) );
735-
QVERIFY( qgsDoubleNear( QgsVector( 0, 1 ).rotateBy( M_PI_2 ).y(), 0.0, 0.0000001 ) );
736-
QVERIFY( qgsDoubleNear( QgsVector( 0, 1 ).rotateBy( M_PI ).x(), 0.0, 0.0000001 ) );
737-
QVERIFY( qgsDoubleNear( QgsVector( 0, 1 ).rotateBy( M_PI ).y(), -1.0, 0.0000001 ) );
735+
QGSCOMPARENEAR( QgsVector( 0, 1 ).rotateBy( M_PI_2 ).x(), -1.0, 0.0000001 );
736+
QGSCOMPARENEAR( QgsVector( 0, 1 ).rotateBy( M_PI_2 ).y(), 0.0, 0.0000001 );
737+
QGSCOMPARENEAR( QgsVector( 0, 1 ).rotateBy( M_PI ).x(), 0.0, 0.0000001 );
738+
QGSCOMPARENEAR( QgsVector( 0, 1 ).rotateBy( M_PI ).y(), -1.0, 0.0000001 );
738739

739740
// normalized
740741
QCOMPARE( QgsVector( 0, 2 ).normalized().x(), 0.0 );

‎tests/src/core/testqgsproperty.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ void TestQgsProperty::genericNumericTransformer()
804804
//test exponential scaling
805805
t.setExponent( 1.5 );
806806
QCOMPARE( t.value( 100 ), 10.0 );
807-
QVERIFY( qgsDoubleNear( t.value( 150 ), 13.5355, 0.001 ) );
807+
QGSCOMPARENEAR( t.value( 150 ), 13.5355, 0.001 );
808808
QCOMPARE( t.value( 200 ), 20.0 );
809809

810810
//as expression
@@ -1010,18 +1010,18 @@ void TestQgsProperty::sizeScaleTransformer()
10101010
//test area scaling
10111011
t.setType( QgsSizeScaleTransformer::Area );
10121012
QCOMPARE( t.size( 100 ), 10.0 );
1013-
QVERIFY( qgsDoubleNear( t.size( 150 ), 17.0711, 0.001 ) );
1013+
QGSCOMPARENEAR( t.size( 150 ), 17.0711, 0.001 );
10141014
QCOMPARE( t.size( 200 ), 20.0 );
10151015
//test flannery scaling
10161016
t.setType( QgsSizeScaleTransformer::Flannery );
10171017
QCOMPARE( t.size( 100 ), 10.0 );
1018-
QVERIFY( qgsDoubleNear( t.size( 150 ), 16.7362, 0.001 ) );
1018+
QGSCOMPARENEAR( t.size( 150 ), 16.7362, 0.001 );
10191019
QCOMPARE( t.size( 200 ), 20.0 );
10201020
//test exponential scaling
10211021
t.setType( QgsSizeScaleTransformer::Exponential );
10221022
t.setExponent( 1.5 );
10231023
QCOMPARE( t.size( 100 ), 10.0 );
1024-
QVERIFY( qgsDoubleNear( t.size( 150 ), 13.5355, 0.001 ) );
1024+
QGSCOMPARENEAR( t.size( 150 ), 13.5355, 0.001 );
10251025
QCOMPARE( t.size( 200 ), 20.0 );
10261026

10271027
//as expression

‎tests/src/core/testqgsrasterlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,11 @@ void TestQgsRasterLayer::checkStats()
398398
//QVERIFY( myStatistics.elementCount == 100 );
399399
QVERIFY( myStatistics.minimumValue == 0 );
400400
QVERIFY( myStatistics.maximumValue == 9 );
401-
QVERIFY( qgsDoubleNear( myStatistics.mean, 4.5 ) );
401+
QGSCOMPARENEAR( myStatistics.mean, 4.5, 4 * DBL_EPSILON );
402402
double stdDev = 2.87228132326901431;
403403
// TODO: verify why GDAL stdDev is so different from generic (2.88675)
404404
mReport += QStringLiteral( "stdDev = %1 expected = %2<br>\n" ).arg( myStatistics.stdDev ).arg( stdDev );
405-
QVERIFY( qgsDoubleNear( myStatistics.stdDev, stdDev, 0.00000000000001 ) );
405+
QGSCOMPARENEAR( myStatistics.stdDev, stdDev, 0.00000000000001 );
406406
mReport += QLatin1String( "<p>Passed</p>" );
407407
}
408408

‎tests/src/core/testqgsrastersublayer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
//qgis unit test includes
4141
#include <qgsrenderchecker.h>
42+
#include "qgstestutils.h"
4243

4344
/** \ingroup UnitTests
4445
* This is a unit test for raster sublayers
@@ -175,8 +176,8 @@ void TestQgsRasterSubLayer::checkStats()
175176

176177
QVERIFY( sublayer->width() == width );
177178
QVERIFY( sublayer->height() == height );
178-
QVERIFY( qgsDoubleNear( myStatistics.minimumValue, min ) );
179-
QVERIFY( qgsDoubleNear( myStatistics.maximumValue, max ) );
179+
QGSCOMPARENEAR( myStatistics.minimumValue, min, 4 * DBL_EPSILON );
180+
QGSCOMPARENEAR( myStatistics.maximumValue, max, 4 * DBL_EPSILON );
180181
mReport += QLatin1String( "<p>Passed</p>" );
181182
delete sublayer;
182183
}

‎tests/src/core/testqgsstatisticalsummary.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "qgsstatisticalsummary.h"
2222
#include "qgis.h"
23+
#include "qgstestutils.h"
2324

2425
class TestQgsStatisticSummary: public QObject
2526
{
@@ -85,10 +86,10 @@ void TestQgsStatisticSummary::stats()
8586
QCOMPARE( s2.sum(), 24.0 );
8687
QCOMPARE( s.mean(), 4.0 );
8788
QCOMPARE( s2.mean(), 4.0 );
88-
QVERIFY( qgsDoubleNear( s.stDev(), 2.0816, 0.0001 ) );
89-
QVERIFY( qgsDoubleNear( s2.stDev(), 2.0816, 0.0001 ) );
90-
QVERIFY( qgsDoubleNear( s.sampleStDev(), 2.2803, 0.0001 ) );
91-
QVERIFY( qgsDoubleNear( s2.sampleStDev(), 2.2803, 0.0001 ) );
89+
QGSCOMPARENEAR( s.stDev(), 2.0816, 0.0001 );
90+
QGSCOMPARENEAR( s2.stDev(), 2.0816, 0.0001 );
91+
QGSCOMPARENEAR( s.sampleStDev(), 2.2803, 0.0001 );
92+
QGSCOMPARENEAR( s2.sampleStDev(), 2.2803, 0.0001 );
9293

9394
QCOMPARE( s.min(), 2.0 );
9495
QCOMPARE( s2.min(), 2.0 );
@@ -248,7 +249,7 @@ void TestQgsStatisticSummary::individualStatCalculations()
248249
QCOMPARE( s.statistics(), stat );
249250

250251
s.calculate( values );
251-
QVERIFY( qgsDoubleNear( s.statistic( stat ), expected, 0.00001 ) );
252+
QGSCOMPARENEAR( s.statistic( stat ), expected, 0.00001 );
252253

253254
//also test using values added one-at-a-time
254255
QgsStatisticalSummary s2( QgsStatisticalSummary::Statistics( 0 ) );

‎tests/src/providers/testqgsgdalprovider.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <qgsproviderregistry.h>
3030
#include <qgsrasterdataprovider.h>
3131
#include <qgsrectangle.h>
32+
#include "qgstestutils.h"
3233

3334
/** \ingroup UnitTests
3435
* This is a unit test for the gdal provider
@@ -104,10 +105,10 @@ void TestQgsGdalProvider::warpedVrt()
104105
qDebug() << "y min: " << rp->extent().yMinimum();
105106
qDebug() << "y max: " << rp->extent().yMaximum();
106107

107-
QVERIFY( qgsDoubleNear( rp->extent().xMinimum(), 2058589, 1 ) );
108-
QVERIFY( qgsDoubleNear( rp->extent().xMaximum(), 3118999, 1 ) );
109-
QVERIFY( qgsDoubleNear( rp->extent().yMinimum(), 2281355, 1 ) );
110-
QVERIFY( qgsDoubleNear( rp->extent().yMaximum(), 3129683, 1 ) );
108+
QGSCOMPARENEAR( rp->extent().xMinimum(), 2058589, 1 );
109+
QGSCOMPARENEAR( rp->extent().xMaximum(), 3118999, 1 );
110+
QGSCOMPARENEAR( rp->extent().yMinimum(), 2281355, 1 );
111+
QGSCOMPARENEAR( rp->extent().yMaximum(), 3129683, 1 );
111112
delete provider;
112113
}
113114

0 commit comments

Comments
 (0)
Please sign in to comment.