Commit da8bcf7b authored by Akarsh Simha's avatar Akarsh Simha
Browse files

Tests for CachingDms

Test cases for CachingDms to check various operations.
parent 8c2dffaf
......@@ -11,3 +11,7 @@ ADD_TEST( NAME FixedWidthParserTest COMMAND testfwparser )
ADD_EXECUTABLE( testdms testdms.cpp )
TARGET_LINK_LIBRARIES( testdms ${TEST_LIBRARIES})
ADD_TEST( NAME DMSTest COMMAND testdms )
ADD_EXECUTABLE( testcachingdms testcachingdms.cpp )
TARGET_LINK_LIBRARIES( testcachingdms ${TEST_LIBRARIES})
ADD_TEST( NAME TestCachingDms COMMAND testcachingdms )
/***************************************************************************
testcachingdms.cpp -
-------------------
begin : Sun 25 Sep 2016 03:56:05 CDT
copyright : (c) 2016 by Akarsh Simha
email : akarsh.simha@kdemail.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* Project Includes */
#include "testcachingdms.h"
#include "nan.h"
/* KDE Includes */
/* Qt Includes */
/* STL Includes */
TestCachingDms::TestCachingDms(): QObject()
{
}
TestCachingDms::~TestCachingDms()
{
}
void TestCachingDms::defaultCtor()
{
/*
* Test 1: Check Default Constructor
*/
// Check default empty constructor
CachingDms d;
QVERIFY(std::isnan(d.Degrees()));
QVERIFY( std::isnan( d.sin() ) );
QVERIFY( std::isnan( d.cos() ) );
}
void TestCachingDms::explicitSexigesimalCtor()
{
/*
* Test 2: Checks Sexigesimal Ctor
*/
// DD:MM:SS
// 14:55:20
CachingDms d(14, 55, 20);
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 );
}
void TestCachingDms::angleCtor()
{
/*
* Test 3: Checks Angle Ctor
*/
// Angle = -112.56 Degrees ---> HMS (16:29:45)
double angle = -112.56;
CachingDms d(angle);
QVERIFY(d.degree() == (int) angle);
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 );
}
void TestCachingDms::stringCtor()
{
QString hms("14:55:20");
// From Degree
CachingDms d(hms);
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 );
// From Hours
CachingDms h(hms, false);
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 );
// 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 );
}
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 );
// 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 );
}
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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
}
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() );
}
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 );
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 );
}
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 );
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 );
}
QTEST_GUILESS_MAIN(TestCachingDms)
/***************************************************************************
testcachingdms.h -
-------------------
begin : Sun 25 Sep 2016 03:56:35 CDT
copyright : (c) 2016 by Akarsh Simha
email : akarsh.simha@kdemail.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef TESTCACHINGDMS_H
#define TESTCACHINGDMS_H
#include <QtTest/QtTest>
#include <QDebug>
#include "auxiliary/cachingdms.h"
/**
* @class TestCachingDms
* @short Tests for CachingDms
* @author Akarsh Simha <akarsh.simha@kdemail.net>
*/
class TestCachingDms : public QObject {
Q_OBJECT
public:
/**
* @short Constructor
*/
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();
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment