testConversions.cpp   testConversions.cpp 
skipping to change at line 20 skipping to change at line 20
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "config.h"
#include "tests/testConversions.hpp" #include "tests/testConversions.hpp"
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QtGlobal> #include <QtGlobal>
#include <QVariantList> #include <QVariantList>
#include <QMap> #include <QMap>
#include "StelUtils.hpp" #include "StelUtils.hpp"
skipping to change at line 62 skipping to change at line 61
data << 3 << 59 << 59 << 165599*M_PI/648000; data << 3 << 59 << 59 << 165599*M_PI/648000;
while (data.count() >= 4) while (data.count() >= 4)
{ {
int h, m, s; int h, m, s;
double rad; double rad;
h = data.takeFirst().toInt(); h = data.takeFirst().toInt();
m = data.takeFirst().toInt(); m = data.takeFirst().toInt();
s = data.takeFirst().toInt(); s = data.takeFirst().toInt();
rad = data.takeFirst().toDouble(); rad = data.takeFirst().toDouble();
QVERIFY2(std::abs(StelUtils::hmsToRad(h, m, s)-rad)<=ERROR_L IMIT, qPrintable(QString("%1h%2m%3s=%4").arg(h).arg(m).arg(s).arg(rad))); QVERIFY2(qAbs(StelUtils::hmsToRad(h, m, s)-rad)<=ERROR_LIMIT , qPrintable(QString("%1h%2m%3s=%4").arg(h).arg(m).arg(s).arg(rad)));
} }
} }
void TestConversions::testDMSToRad() void TestConversions::testDMSToRad()
{ {
QVariantList data; QVariantList data;
data << 0 << 0 << 0 << 0.; data << 0 << 0 << 0 << 0.;
data << 30 << 0 << 0 << M_PI/6; data << 30 << 0 << 0 << M_PI/6;
data << 45 << 0 << 0 << M_PI/4; data << 45 << 0 << 0 << M_PI/4;
skipping to change at line 94 skipping to change at line 93
data << 10 << 59 << 59 << 39599*M_PI/648000; data << 10 << 59 << 59 << 39599*M_PI/648000;
while (data.count() >= 4) while (data.count() >= 4)
{ {
int deg, min, sec; int deg, min, sec;
double rad; double rad;
deg = data.takeFirst().toInt(); deg = data.takeFirst().toInt();
min = data.takeFirst().toInt(); min = data.takeFirst().toInt();
sec = data.takeFirst().toInt(); sec = data.takeFirst().toInt();
rad = data.takeFirst().toDouble(); rad = data.takeFirst().toDouble();
QVERIFY2(std::abs(StelUtils::dmsToRad(deg, min, sec)-rad)<=E RROR_LIMIT, qPrintable(QString("%1d%2m%3s=%4").arg(deg).arg(min).arg(sec).a rg(rad))); QVERIFY2(qAbs(StelUtils::dmsToRad(deg, min, sec)-rad)<=ERROR _LIMIT, qPrintable(QString("%1d%2m%3s=%4").arg(deg).arg(min).arg(sec).arg(r ad)));
} }
} }
void TestConversions::testRadToHMS() void TestConversions::testRadToHMS()
{ {
QVariantList data; QVariantList data;
data << 0. << 0 << 0 << 0.; data << 0. << 0 << 0 << 0.;
data << M_PI/36 << 0 << 19 << 59.9; data << M_PI/36 << 0 << 19 << 59.9;
data << 7*M_PI/8 << 10 << 30 << 0.; data << 7*M_PI/8 << 10 << 30 << 0.;
skipping to change at line 119 skipping to change at line 118
double rad, s, so, t1, t2; double rad, s, so, t1, t2;
int h, m; int h, m;
unsigned int ho, mo; unsigned int ho, mo;
rad = data.takeFirst().toDouble(); rad = data.takeFirst().toDouble();
h = data.takeFirst().toInt(); h = data.takeFirst().toInt();
m = data.takeFirst().toInt(); m = data.takeFirst().toInt();
s = data.takeFirst().toDouble(); s = data.takeFirst().toDouble();
t1 = s+m*60+h*3600; t1 = s+m*60+h*3600;
StelUtils::radToHms(rad, ho, mo, so); StelUtils::radToHms(rad, ho, mo, so);
t2 = so+mo*60+ho*3600; t2 = so+mo*60+ho*3600;
QVERIFY2(std::abs(t1-t2)<=0.1, qPrintable(QString("%1rad=%2h %3m%4s").arg(rad).arg(ho).arg(mo).arg(so))); QVERIFY2(qAbs(t1-t2)<=0.1, qPrintable(QString("%1rad=%2h%3m% 4s").arg(rad).arg(ho).arg(mo).arg(so)));
} }
} }
void TestConversions::testRadToDMS() void TestConversions::testRadToDMS()
{ {
QVariantList data; QVariantList data;
data << 0. << 0 << 0 << 0.; data << 0. << 0 << 0 << 0.;
data << M_PI/6 << 30 << 0 << 0.; data << M_PI/6 << 30 << 0 << 0.;
data << M_PI/4 << 45 << 0 << 0.; data << M_PI/4 << 45 << 0 << 0.;
skipping to change at line 161 skipping to change at line 160
unsigned int dego, mino; unsigned int dego, mino;
bool sign; bool sign;
QString s; QString s;
rad = data.takeFirst().toDouble(); rad = data.takeFirst().toDouble();
deg = data.takeFirst().toInt(); deg = data.takeFirst().toInt();
min = data.takeFirst().toInt(); min = data.takeFirst().toInt();
sec = data.takeFirst().toDouble(); sec = data.takeFirst().toDouble();
if (deg>=0) if (deg>=0)
angle1 = sec+min*60+deg*3600; angle1 = sec+min*60+deg*3600;
else else
angle1 = -1*(sec+min*60+std::abs((double)deg)*3600); angle1 = -1*(sec+min*60+qAbs((double)deg)*3600);
StelUtils::radToDms(rad, sign, dego, mino, seco); StelUtils::radToDms(rad, sign, dego, mino, seco);
angle2 = seco+mino*60+dego*3600; angle2 = seco+mino*60+dego*3600;
if (!sign) if (!sign)
{ {
angle2 = -1*angle2; angle2 = -1*angle2;
s = "-"; s = "-";
} }
else else
s = "+"; s = "+";
QVERIFY2(std::abs(angle1-angle2)<=ERROR_LIMIT, qPrintable(QS tring("%1rad=%2%3d%4m%5s").arg(rad).arg(s).arg(dego).arg(mino).arg(seco))); QVERIFY2(qAbs(angle1-angle2)<=ERROR_LIMIT, qPrintable(QStrin g("%1rad=%2%3d%4m%5s").arg(rad).arg(s).arg(dego).arg(mino).arg(seco)));
} }
} }
void TestConversions::testDDToDMS() void TestConversions::testDDToDMS()
{ {
QVariantList data; QVariantList data;
data << 0. << 0 << 0 << 0.; data << 0. << 0 << 0 << 0.;
data << 10. << 10 << 0 << 0.; data << 10. << 10 << 0 << 0.;
data << -13.5 << -13 << 30 << 0.; data << -13.5 << -13 << 30 << 0.;
skipping to change at line 204 skipping to change at line 203
unsigned int dego, mino; unsigned int dego, mino;
bool sign; bool sign;
QString s = "+"; QString s = "+";
angle = data.takeFirst().toDouble(); angle = data.takeFirst().toDouble();
deg = data.takeFirst().toInt(); deg = data.takeFirst().toInt();
min = data.takeFirst().toInt(); min = data.takeFirst().toInt();
sec = data.takeFirst().toDouble(); sec = data.takeFirst().toDouble();
if (angle>=0) if (angle>=0)
angle1 = sec+min*60+deg*3600; angle1 = sec+min*60+deg*3600;
else else
angle1 = -1*(sec+min*60+std::abs((double)deg)*3600); angle1 = -1*(sec+min*60+qAbs((double)deg)*3600);
StelUtils::decDegToDms(angle, sign, dego, mino, seco); StelUtils::decDegToDms(angle, sign, dego, mino, seco);
angle2 = seco+mino*60+dego*3600; angle2 = seco+mino*60+dego*3600;
if (!sign) if (!sign)
{ {
angle2 *= -1; angle2 *= -1;
s = "-"; s = "-";
} }
QVERIFY2(std::abs(angle1-angle2)<=ERROR_LIMIT, qPrintable(QS tring("%1degrees=%2%3d%4m%5s").arg(angle).arg(s).arg(dego).arg(mino).arg(se co))); QVERIFY2(qAbs(angle1-angle2)<=ERROR_LIMIT, qPrintable(QStrin g("%1degrees=%2%3d%4m%5s").arg(angle).arg(s).arg(dego).arg(mino).arg(seco)) );
} }
} }
 End of changes. 8 change blocks. 
8 lines changed or deleted 7 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/