File indexing completed on 2024-04-14 14:12:12
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 /* 0008 * This file contains unit tests for the GreatCircle class. 0009 */ 0010 0011 #include <QObject> 0012 #include <QTest> 0013 #include <cmath> 0014 #include <memory> 0015 0016 #include "greatcircle.h" 0017 0018 class TestGreatCircle : public QObject 0019 { 0020 Q_OBJECT 0021 0022 public: 0023 /** @short Constructor */ 0024 TestGreatCircle(); 0025 0026 /** @short Destructor */ 0027 ~TestGreatCircle() override = default; 0028 0029 private slots: 0030 void greatCircleTest_data(); 0031 void greatCircleTest(); 0032 0033 private: 0034 }; 0035 0036 // This include must go after the class declaration. 0037 #include "testgreatcircle.moc" 0038 0039 TestGreatCircle::TestGreatCircle() : QObject() 0040 { 0041 } 0042 0043 namespace 0044 { 0045 0046 // Tests that the doubles are within tolerance. 0047 bool compareFloat(double d1, double d2, double tolerance = .0001) 0048 { 0049 return (fabs(d1 - d2) < tolerance); 0050 } 0051 0052 } // namespace 0053 0054 void TestGreatCircle::greatCircleTest_data() 0055 { 0056 QTest::addColumn<double>("AZ1"); 0057 QTest::addColumn<double>("ALT1"); 0058 QTest::addColumn<double>("AZ2"); 0059 QTest::addColumn<double>("ALT2"); 0060 QTest::addColumn<double>("FRACTION"); 0061 QTest::addColumn<double>("AZ_SOLUTION"); 0062 QTest::addColumn<double>("ALT_SOLUTION"); 0063 0064 // These tests are actually longitude/latitude as opposed to az/alt. 0065 QTest::newRow("SF_TO_NYC_half") 0066 << -122.420 << 37.770 << -74.010 << 40.710 << 0.50 << -98.754805 << 41.842196; 0067 QTest::newRow("SF_TO_PARIS_half") 0068 << -122.420 << 37.770 << 2.350 << 48.860 << 0.50 << -69.959876 << 63.476436; 0069 QTest::newRow("SF_TO_PARIS_0") 0070 << -122.420 << 37.770 << 2.350 << 48.860 << 0.0 << -122.420 << 37.770; 0071 QTest::newRow("SF_TO_PARIS_1") 0072 << -122.420 << 37.770 << 2.350 << 48.860 << 1.0 << 2.350 << 48.860; 0073 } 0074 0075 void TestGreatCircle::greatCircleTest() 0076 { 0077 QFETCH(double, AZ1); 0078 QFETCH(double, ALT1); 0079 QFETCH(double, AZ2); 0080 QFETCH(double, ALT2); 0081 QFETCH(double, FRACTION); 0082 QFETCH(double, AZ_SOLUTION); 0083 QFETCH(double, ALT_SOLUTION); 0084 GreatCircle gc(AZ1, ALT1, AZ2, ALT2); 0085 double az, alt; 0086 gc.waypoint(FRACTION, &az, &alt); 0087 QVERIFY(compareFloat(az, AZ_SOLUTION)); 0088 QVERIFY(compareFloat(alt, ALT_SOLUTION)); 0089 } 0090 0091 QTEST_GUILESS_MAIN(TestGreatCircle)