Commit 9096ca38 authored by Csaba Kertesz's avatar Csaba Kertesz

Update the source format with clang-format

parent 679fbc8b

Too many changes to show.

To preserve performance only 184 of 184+ files are displayed.

......@@ -15,7 +15,6 @@
* *
***************************************************************************/
/* Project Includes */
#include "testcachingdms.h"
#include "nan.h"
......@@ -29,7 +28,7 @@
#include <cstdlib>
#include <cstdint>
TestCachingDms::TestCachingDms(): QObject()
TestCachingDms::TestCachingDms() : QObject()
{
}
......@@ -46,8 +45,8 @@ void TestCachingDms::defaultCtor()
// Check default empty constructor
CachingDms d;
QVERIFY(std::isnan(d.Degrees()));
QVERIFY( std::isnan( d.sin() ) );
QVERIFY( std::isnan( d.cos() ) );
QVERIFY(std::isnan(d.sin()));
QVERIFY(std::isnan(d.cos()));
}
void TestCachingDms::explicitSexigesimalCtor()
......@@ -64,9 +63,9 @@ void TestCachingDms::explicitSexigesimalCtor()
QVERIFY(d.degree() == 14);
QVERIFY(d.arcmin() == 55);
QVERIFY(d.arcsec() == 20);
QVERIFY(d.Degrees() == (14.0+55.0/60.0+20.0/3600.0));
QVERIFY( fabs( d.sin() - .25750758368074941632 ) < 1e-9 );
QVERIFY( fabs( d.cos() - .96627627744186177805 ) < 1e-9 );
QVERIFY(d.Degrees() == (14.0 + 55.0 / 60.0 + 20.0 / 3600.0));
QVERIFY(fabs(d.sin() - .25750758368074941632) < 1e-9);
QVERIFY(fabs(d.cos() - .96627627744186177805) < 1e-9);
}
void TestCachingDms::angleCtor()
......@@ -81,14 +80,14 @@ void TestCachingDms::angleCtor()
CachingDms d(angle);
QVERIFY(d.degree() == (int) angle);
QVERIFY(d.degree() == (int)angle);
QVERIFY(d.Hours() == (angle+360)/15.0);
QVERIFY(d.hour() == 16);
QVERIFY(d.Hours() == (angle + 360) / 15.0);
QVERIFY(d.hour() == 16);
QVERIFY(d.minute() == 29);
QVERIFY(d.second() == 45);
QVERIFY( fabs( d.sin() + 0.92347828085768229015 ) < 1e-9 );
QVERIFY( fabs( d.cos() + 0.38365070674265630377 ) < 1e-9 );
QVERIFY(fabs(d.sin() + 0.92347828085768229015) < 1e-9);
QVERIFY(fabs(d.cos() + 0.38365070674265630377) < 1e-9);
}
void TestCachingDms::stringCtor()
......@@ -101,222 +100,214 @@ void TestCachingDms::stringCtor()
QVERIFY(d.degree() == 14);
QVERIFY(d.arcmin() == 55);
QVERIFY(d.arcsec() == 20);
QVERIFY(d.Degrees() == (14.0+55.0/60.0+20.0/3600.0));
QVERIFY( fabs( d.sin() - .25750758368074941632 ) < 1e-9 );
QVERIFY( fabs( d.cos() - .96627627744186177805 ) < 1e-9 );
QVERIFY(d.Degrees() == (14.0 + 55.0 / 60.0 + 20.0 / 3600.0));
QVERIFY(fabs(d.sin() - .25750758368074941632) < 1e-9);
QVERIFY(fabs(d.cos() - .96627627744186177805) < 1e-9);
// From Hours
CachingDms h(hms, false);
QVERIFY(h.Degrees() == d.Degrees()*15.0);
QVERIFY(h.Degrees() == d.Degrees() * 15.0);
QVERIFY(h.Hours() == d.Degrees());
}
void TestCachingDms::setUsing_asin()
{
// Test case in first quadrant: 56.3 degrees
CachingDms d;
d.setUsing_asin( .83195412213048254606 );
QVERIFY( fabs( d.Degrees() - 56.3 ) < 1e-7 );
QVERIFY( fabs( d.cos() - .55484442744799927555 ) < 1e-9 );
d.setUsing_asin(.83195412213048254606);
QVERIFY(fabs(d.Degrees() - 56.3) < 1e-7);
QVERIFY(fabs(d.cos() - .55484442744799927555) < 1e-9);
// Test case in fourth quadrant: -56.3 degrees
d.setUsing_asin( -.83195412213048254606 );
QVERIFY( fabs( d.Degrees() + 56.3 ) < 1e-7 );
QVERIFY( fabs( d.cos() - .55484442744799927555 ) < 1e-9 );
d.setUsing_asin(-.83195412213048254606);
QVERIFY(fabs(d.Degrees() + 56.3) < 1e-7);
QVERIFY(fabs(d.cos() - .55484442744799927555) < 1e-9);
}
void TestCachingDms::setUsing_acos()
{
CachingDms d;
// Test case in first quadrant: 56.3 degrees
d.setUsing_acos( .55484442744799927555 );
QVERIFY( fabs( d.Degrees() - 56.3 ) < 1e-7 );
QVERIFY( fabs( d.sin() - .83195412213048254606 ) < 1e-9 );
d.setUsing_acos(.55484442744799927555);
QVERIFY(fabs(d.Degrees() - 56.3) < 1e-7);
QVERIFY(fabs(d.sin() - .83195412213048254606) < 1e-9);
// Test case in second quadrant: 123.7 degrees
d.setUsing_acos( -0.55484442744799927555 );
QVERIFY( fabs( d.Degrees() - 123.7 ) < 1e-7 );
QVERIFY( fabs( d.sin() - .83195412213048254606 ) < 1e-9 );
d.setUsing_acos(-0.55484442744799927555);
QVERIFY(fabs(d.Degrees() - 123.7) < 1e-7);
QVERIFY(fabs(d.sin() - .83195412213048254606) < 1e-9);
}
void TestCachingDms::setUsing_atan2()
{
// Test case in first quadrant: 56.3 degrees
CachingDms d;
d.setUsing_atan2( 2.73701935509448143467, 1.82536500102022632674 );
QVERIFY( fabs( d.Degrees() - 56.3 ) < 1e-7 );
QVERIFY( fabs( d.sin() - .83195412213048254606 ) < 1e-9 );
QVERIFY( fabs( d.cos() - .55484442744799927555 ) < 1e-9 );
d.setUsing_atan2(2.73701935509448143467, 1.82536500102022632674);
QVERIFY(fabs(d.Degrees() - 56.3) < 1e-7);
QVERIFY(fabs(d.sin() - .83195412213048254606) < 1e-9);
QVERIFY(fabs(d.cos() - .55484442744799927555) < 1e-9);
// Test case in third quadrant: -123.7 degrees
d.setUsing_atan2( -2.73701935509448143467, -1.82536500102022632674 );
QVERIFY( fabs( d.Degrees() + 123.7 ) < 1e-7 );
QVERIFY( fabs( d.sin() + .83195412213048254606 ) < 1e-9 );
QVERIFY( fabs( d.cos() + .55484442744799927555 ) < 1e-9 );
d.setUsing_atan2(-2.73701935509448143467, -1.82536500102022632674);
QVERIFY(fabs(d.Degrees() + 123.7) < 1e-7);
QVERIFY(fabs(d.sin() + .83195412213048254606) < 1e-9);
QVERIFY(fabs(d.cos() + .55484442744799927555) < 1e-9);
// Test case in second quadrant: 123.7 degrees
d.setUsing_atan2( 2.73701935509448143467, -1.82536500102022632674 );
QVERIFY( fabs( d.Degrees() - 123.7 ) < 1e-7 );
QVERIFY( fabs( d.sin() - .83195412213048254606 ) < 1e-9 );
QVERIFY( fabs( d.cos() + .55484442744799927555 ) < 1e-9 );
d.setUsing_atan2(2.73701935509448143467, -1.82536500102022632674);
QVERIFY(fabs(d.Degrees() - 123.7) < 1e-7);
QVERIFY(fabs(d.sin() - .83195412213048254606) < 1e-9);
QVERIFY(fabs(d.cos() + .55484442744799927555) < 1e-9);
// Test case in fourth quadrant: -56.3 degrees
d.setUsing_atan2( -2.73701935509448143467, +1.82536500102022632674 );
QVERIFY( fabs( d.Degrees() + 56.3 ) < 1e-7 );
QVERIFY( fabs( d.sin() + .83195412213048254606 ) < 1e-9 );
QVERIFY( fabs( d.cos() - .55484442744799927555 ) < 1e-9 );
d.setUsing_atan2(-2.73701935509448143467, +1.82536500102022632674);
QVERIFY(fabs(d.Degrees() + 56.3) < 1e-7);
QVERIFY(fabs(d.sin() + .83195412213048254606) < 1e-9);
QVERIFY(fabs(d.cos() - .55484442744799927555) < 1e-9);
// Edge case test: angle = 0
d.setUsing_atan2( 0., 1.33 );
QVERIFY( fabs( d.Degrees() - 0. ) < 1e-7 );
QVERIFY( fabs( d.sin() - 0. ) < 1e-9 );
QVERIFY( fabs( d.cos() - 1. ) < 1e-9 );
d.setUsing_atan2(0., 1.33);
QVERIFY(fabs(d.Degrees() - 0.) < 1e-7);
QVERIFY(fabs(d.sin() - 0.) < 1e-9);
QVERIFY(fabs(d.cos() - 1.) < 1e-9);
// Edge case test: angle = 90 degrees
d.setUsing_atan2( 10.12, 0. );
QVERIFY( fabs( d.Degrees() - 90. ) < 1e-7 );
QVERIFY( fabs( d.sin() - 1. ) < 1e-9 );
QVERIFY( fabs( d.cos() - 0. ) < 1e-9 );
d.setUsing_atan2(10.12, 0.);
QVERIFY(fabs(d.Degrees() - 90.) < 1e-7);
QVERIFY(fabs(d.sin() - 1.) < 1e-9);
QVERIFY(fabs(d.cos() - 0.) < 1e-9);
// Edge case test: angle = -90 degrees
d.setUsing_atan2( -3.1415, 0. );
QVERIFY( fabs( d.Degrees() + 90. ) < 1e-7 );
QVERIFY( fabs( d.sin() + 1. ) < 1e-9 );
QVERIFY( fabs( d.cos() - 0. ) < 1e-9 );
d.setUsing_atan2(-3.1415, 0.);
QVERIFY(fabs(d.Degrees() + 90.) < 1e-7);
QVERIFY(fabs(d.sin() + 1.) < 1e-9);
QVERIFY(fabs(d.cos() - 0.) < 1e-9);
// Edge case test: angle = 180 degrees
d.setUsing_atan2( 0., -724. );
QVERIFY( fabs( d.Degrees() - 180. ) < 1e-7 );
QVERIFY( fabs( d.sin() - 0. ) < 1e-9 );
QVERIFY( fabs( d.cos() + 1. ) < 1e-9 );
d.setUsing_atan2(0., -724.);
QVERIFY(fabs(d.Degrees() - 180.) < 1e-7);
QVERIFY(fabs(d.sin() - 0.) < 1e-9);
QVERIFY(fabs(d.cos() + 1.) < 1e-9);
}
void TestCachingDms::unaryMinusOperator()
{
CachingDms d( 56.3 );
qDebug() << ( -d ).Degrees();
QVERIFY( ( -d ).Degrees() == -56.3 );
QVERIFY( ( -d ).cos() == d.cos() );
QVERIFY( ( -d ).sin() == -d.sin() );
CachingDms d(56.3);
qDebug() << (-d).Degrees();
QVERIFY((-d).Degrees() == -56.3);
QVERIFY((-d).cos() == d.cos());
QVERIFY((-d).sin() == -d.sin());
}
void TestCachingDms::additionOperator()
{
const double a = 123.7;
const double b = 89.5;
CachingDms d1( a );
CachingDms d2( b );
CachingDms ds = d1 + d2;
const double sinapb = std::sin( ( a + b ) * dms::DegToRad );
const double cosapb = std::cos( ( a + b ) * dms::DegToRad );
QVERIFY( fabs( ds.sin() - sinapb ) < 1e-9 );
QVERIFY( fabs( ds.cos() - cosapb ) < 1e-9 );
CachingDms d1(a);
CachingDms d2(b);
CachingDms ds = d1 + d2;
const double sinapb = std::sin((a + b) * dms::DegToRad);
const double cosapb = std::cos((a + b) * dms::DegToRad);
QVERIFY(fabs(ds.sin() - sinapb) < 1e-9);
QVERIFY(fabs(ds.cos() - cosapb) < 1e-9);
const double c = -34.7;
const double d = 233.6;
CachingDms d3( c );
CachingDms d4( d );
CachingDms ds2 = d3 + d4;
const double sincpd = std::sin( ( c + d ) * dms::DegToRad );
const double coscpd = std::cos( ( c + d ) * dms::DegToRad );
QVERIFY( fabs( ds2.sin() - sincpd ) < 1e-9 );
QVERIFY( fabs( ds2.cos() - coscpd ) < 1e-9 );
CachingDms d3(c);
CachingDms d4(d);
CachingDms ds2 = d3 + d4;
const double sincpd = std::sin((c + d) * dms::DegToRad);
const double coscpd = std::cos((c + d) * dms::DegToRad);
QVERIFY(fabs(ds2.sin() - sincpd) < 1e-9);
QVERIFY(fabs(ds2.cos() - coscpd) < 1e-9);
}
void TestCachingDms::subtractionOperator()
{
const double a = 123.7;
const double b = 89.5;
CachingDms d1( a );
CachingDms d2( b );
CachingDms ds = d1 - d2;
const double sinamb = std::sin( ( a - b ) * dms::DegToRad );
const double cosamb = std::cos( ( a - b ) * dms::DegToRad );
QVERIFY( fabs( ds.sin() - sinamb ) < 1e-9 );
QVERIFY( fabs( ds.cos() - cosamb ) < 1e-9 );
CachingDms d1(a);
CachingDms d2(b);
CachingDms ds = d1 - d2;
const double sinamb = std::sin((a - b) * dms::DegToRad);
const double cosamb = std::cos((a - b) * dms::DegToRad);
QVERIFY(fabs(ds.sin() - sinamb) < 1e-9);
QVERIFY(fabs(ds.cos() - cosamb) < 1e-9);
const double c = -34.7;
const double d = 233.6;
CachingDms d3( c );
CachingDms d4( d );
CachingDms ds2 = d3 - d4;
const double sincmd = std::sin( ( c - d ) * dms::DegToRad );
const double coscmd = std::cos( ( c - d ) * dms::DegToRad );
QVERIFY( fabs( ds2.sin() - sincmd ) < 1e-9 );
QVERIFY( fabs( ds2.cos() - coscmd ) < 1e-9 );
CachingDms d3(c);
CachingDms d4(d);
CachingDms ds2 = d3 - d4;
const double sincmd = std::sin((c - d) * dms::DegToRad);
const double coscmd = std::cos((c - d) * dms::DegToRad);
QVERIFY(fabs(ds2.sin() - sincmd) < 1e-9);
QVERIFY(fabs(ds2.cos() - coscmd) < 1e-9);
}
void TestCachingDms::testFailsafeUseOfBaseClassPtr()
{
typedef union angle
{
typedef union angle {
double x;
int64_t y;
} angle;
const int testCases = 5000;
std::srand( std::time( 0 ) );
for ( int k = 0; k < testCases; ++k )
std::srand(std::time(0));
for (int k = 0; k < testCases; ++k)
{
angle a;
CachingDms _a;
dms __a;
a.y = std::rand();
_a.setD( a.x );
__a.setD( a.x );
dms * d;
if ( rand()%10 > 5 )
_a.setD(a.x);
__a.setD(a.x);
dms *d;
if (rand() % 10 > 5)
d = &_a;
else
d = &__a;
angle b;
b.y = std::rand();
switch( rand()%7 )
switch (rand() % 7)
{
case 0:
d->setD( b.x );
d->setD(b.x);
break;
case 1:
d->setH( b.x / 15. );
d->setH(b.x / 15.);
break;
case 2:
{
dms x( b.x );
d->setD( x.degree(), x.arcmin(), x.arcsec(), x.marcsec() );
dms x(b.x);
d->setD(x.degree(), x.arcmin(), x.arcsec(), x.marcsec());
break;
}
case 3:
{
dms x( b.x );
d->setFromString( x.toDMSString() );
dms x(b.x);
d->setFromString(x.toDMSString());
break;
}
case 4:
{
dms x( b.x );
d->setFromString( x.toHMSString(), false );
dms x(b.x);
d->setFromString(x.toHMSString(), false);
break;
}
case 5:
{
dms x( b.x );
dms y( 0.0 );
dms x(b.x);
dms y(0.0);
*d = x + y;
}
case 6:
default:
d->setRadians( b.x * dms::DegToRad );
d->setRadians(b.x * dms::DegToRad);
break;
}
QVERIFY( fabs( d->sin() - sin( b.x * dms::DegToRad ) ) < 1e-12 );
QVERIFY( fabs( d->cos() - cos( b.x * dms::DegToRad ) ) < 1e-12 );
QVERIFY(fabs(d->sin() - sin(b.x * dms::DegToRad)) < 1e-12);
QVERIFY(fabs(d->cos() - cos(b.x * dms::DegToRad)) < 1e-12);
}
}
......
......@@ -15,8 +15,6 @@
* *
***************************************************************************/
#ifndef TESTCACHINGDMS_H
#define TESTCACHINGDMS_H
......@@ -33,33 +31,31 @@
class TestCachingDms : public QObject
{
Q_OBJECT
Q_OBJECT
public:
/**
public:
/**
* @short Constructor
*/
TestCachingDms();
TestCachingDms();
/**
/**
* @short Destructor
*/
~TestCachingDms();
private slots:
void defaultCtor();
void explicitSexigesimalCtor();
void angleCtor();
void stringCtor();
void setUsing_atan2();
void setUsing_asin();
void setUsing_acos();
void additionOperator();
void subtractionOperator();
void unaryMinusOperator();
void testFailsafeUseOfBaseClassPtr();
~TestCachingDms();
private slots:
void defaultCtor();
void explicitSexigesimalCtor();
void angleCtor();
void stringCtor();
void setUsing_atan2();
void setUsing_asin();
void setUsing_acos();
void additionOperator();
void subtractionOperator();
void unaryMinusOperator();
void testFailsafeUseOfBaseClassPtr();
};
#endif
......@@ -28,7 +28,7 @@
#include <QDir>
#include <QTemporaryFile>
TestCSVParser::TestCSVParser(): QObject()
TestCSVParser::TestCSVParser() : QObject()
{
}
......@@ -72,7 +72,7 @@ void TestCSVParser::initTestCase()
"3,"
"\"isn't, pi\","
"and,"
"\"\",")); // less than required fields
"\"\",")); // less than required fields
test_cases_.append(QString(","
"isn't,"
"it,"
......@@ -81,7 +81,7 @@ void TestCSVParser::initTestCase()
"3,"
"\"isn't, pi\","
"and,"
"\"," // no matching "
"\"," // no matching "
"-3.141,"
"isn't,"
"either\n"));
......@@ -94,7 +94,7 @@ void TestCSVParser::initTestCase()
QVERIFY(temp_file.open());
test_file_name_ = temp_file.fileName();
QTextStream out_stream(&temp_file);
foreach(const QString &test_case, test_cases_)
foreach (const QString &test_case, test_cases_)
out_stream << test_case;
temp_file.close();
......@@ -125,7 +125,6 @@ void TestCSVParser::cleanupTestCase()
delete test_parser_;
}
/*
* The following tests checks for the following cases for CSV files
* 1. Mixed inputs (See test case for description)
......@@ -138,7 +137,6 @@ void TestCSVParser::cleanupTestCase()
*
*/
void TestCSVParser::CSVMixedInputs()
{
/*
......@@ -194,7 +192,6 @@ void TestCSVParser::CSVQuotesInQuotes()
QCOMPARE(row_content["field12"].toString(), QString("either"));
}
void TestCSVParser::CSVEmptyRow()
{
/* Test 2. Row with less rows than required (to be skipped)
......@@ -269,7 +266,6 @@ void TestCSVParser::CSVIgnoreHasNextRow()
}