File indexing completed on 2022-10-04 14:00:22

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2017 Mohammed Nafees <nafees.technocool@gmail.com>
0004 //
0005 
0006 #include <QTest>
0007 #include "TestUtils.h"
0008 
0009 #include "GeoDataBuilding.h"
0010 #include "GeoDataMultiGeometry.h"
0011 #include "GeoDataLinearRing.h"
0012 
0013 namespace Marble {
0014 
0015 class TestGeoDataBuilding : public QObject {
0016     Q_OBJECT
0017 
0018 private Q_SLOTS:
0019     void defaultConstructor();
0020     void testHeightExtraction();
0021 };
0022 
0023 void TestGeoDataBuilding::defaultConstructor() {
0024     GeoDataBuilding building;
0025 
0026     QCOMPARE(building.height(), 0.0);
0027     QCOMPARE(building.minLevel(), 0);
0028     QCOMPARE(building.maxLevel(), 0);
0029 
0030     building.setHeight(24.5);
0031     building.setMinLevel(-2);
0032     building.setMaxLevel(10);
0033 
0034     QCOMPARE(building.height(), 24.5);
0035     QCOMPARE(building.minLevel(), -2);
0036     QCOMPARE(building.maxLevel(), 10);
0037 
0038     QVERIFY(building.nonExistentLevels().isEmpty());
0039 
0040     QVector<int> nonExistentLevels;
0041     nonExistentLevels << 4 << 13;
0042     building.setNonExistentLevels(nonExistentLevels);
0043 
0044     QVERIFY(!building.nonExistentLevels().isEmpty());
0045 
0046     QVERIFY(building.multiGeometry()->size() == 0);
0047 
0048     building.multiGeometry()->append(new GeoDataLinearRing);
0049 
0050     QVERIFY(building.multiGeometry()->size() > 0);
0051 
0052     GeoDataBuilding building2(building);
0053 
0054     QCOMPARE(building2.height(), 24.5);
0055     QCOMPARE(building2.minLevel(), -2);
0056     QCOMPARE(building2.maxLevel(), 10);
0057     QVERIFY(!building2.nonExistentLevels().isEmpty());
0058     QVERIFY(building2.multiGeometry()->size() > 0);
0059 }
0060 
0061 void TestGeoDataBuilding::testHeightExtraction()
0062 {
0063     QString const meters1 = "12 m";
0064     QString const meters2 = "12.8 meters";
0065     QString const meters3 = "12.56 meter";
0066     QString const meters4 = "14.44 metres";
0067     QString const meters5 = "23.43 metre";
0068 
0069     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters1), 12.0, 0.0001);
0070     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters2), 12.8, 0.0001);
0071     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters3), 12.56, 0.0001);
0072     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters4), 14.44, 0.0001);
0073     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters5), 23.43, 0.0001);
0074 
0075     QString const feet1 = "55'4\""; // 664 inches
0076     QString const feet2 = "60.56 feet"; // 726.72 inches
0077     QString const feet3 = "300\'"; // 3600 inches
0078 
0079     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(feet1), 16.8656, 0.0001);
0080     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(feet2), 18.4587, 0.0001);
0081     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(feet3), 91.44, 0.0001);
0082 
0083     QString const unitless1 = "0.8"; // default in meters
0084     QString const unitless2 = "12"; // default in meters
0085 
0086     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(unitless1), 0.8, 0.0001);
0087     QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(unitless2), 12.0, 0.0001);
0088 }
0089 
0090 }
0091 
0092 QTEST_MAIN(Marble::TestGeoDataBuilding)
0093 
0094 #include "TestGeoDataBuilding.moc"