Changeset View
Changeset View
Standalone View
Standalone View
tests/TestGeoDataBuilding.cpp
1 | // | 1 | // | ||
---|---|---|---|---|---|
2 | // This file is part of the Marble Virtual Globe. | 2 | // This file is part of the Marble Virtual Globe. | ||
3 | // | 3 | // | ||
4 | // This program is free software licensed under the GNU LGPL. You can | 4 | // This program is free software licensed under the GNU LGPL. You can | ||
5 | // find a copy of this license in LICENSE.txt in the top directory of | 5 | // find a copy of this license in LICENSE.txt in the top directory of | ||
6 | // the source code. | 6 | // the source code. | ||
7 | // | 7 | // | ||
8 | // Copyright 2017 Mohammed Nafees <nafees.technocool@gmail.com> | 8 | // Copyright 2017 Mohammed Nafees <nafees.technocool@gmail.com> | ||
9 | // | 9 | // | ||
10 | 10 | | |||
11 | #include <QTest> | 11 | #include <QTest> | ||
12 | #include <QVector> | 12 | #include "TestUtils.h" | ||
13 | 13 | | |||
14 | #include "GeoDataBuilding.h" | 14 | #include "GeoDataBuilding.h" | ||
15 | #include "GeoDataMultiGeometry.h" | 15 | #include "GeoDataMultiGeometry.h" | ||
16 | #include "GeoDataLinearRing.h" | 16 | #include "GeoDataLinearRing.h" | ||
17 | 17 | | |||
18 | namespace Marble { | 18 | namespace Marble { | ||
19 | 19 | | |||
20 | class TestGeoDataBuilding : public QObject { | 20 | class TestGeoDataBuilding : public QObject { | ||
21 | Q_OBJECT | 21 | Q_OBJECT | ||
22 | 22 | | |||
23 | private Q_SLOTS: | 23 | private Q_SLOTS: | ||
24 | void defaultConstructor(); | 24 | void defaultConstructor(); | ||
25 | void testHeightExtraction(); | ||||
25 | }; | 26 | }; | ||
26 | 27 | | |||
27 | void TestGeoDataBuilding::defaultConstructor() { | 28 | void TestGeoDataBuilding::defaultConstructor() { | ||
28 | GeoDataBuilding building; | 29 | GeoDataBuilding building; | ||
29 | 30 | | |||
30 | QCOMPARE(building.height(), 0.0); | 31 | QCOMPARE(building.height(), 0.0); | ||
31 | QCOMPARE(building.minLevel(), 0); | 32 | QCOMPARE(building.minLevel(), 0); | ||
32 | QCOMPARE(building.maxLevel(), 0); | 33 | QCOMPARE(building.maxLevel(), 0); | ||
Show All 24 Lines | |||||
57 | 58 | | |||
58 | QCOMPARE(building2.height(), 24.5); | 59 | QCOMPARE(building2.height(), 24.5); | ||
59 | QCOMPARE(building2.minLevel(), -2); | 60 | QCOMPARE(building2.minLevel(), -2); | ||
60 | QCOMPARE(building2.maxLevel(), 10); | 61 | QCOMPARE(building2.maxLevel(), 10); | ||
61 | QVERIFY(!building2.nonExistentLevels().isEmpty()); | 62 | QVERIFY(!building2.nonExistentLevels().isEmpty()); | ||
62 | QVERIFY(building2.multiGeometry()->size() > 0); | 63 | QVERIFY(building2.multiGeometry()->size() > 0); | ||
63 | } | 64 | } | ||
64 | 65 | | |||
66 | void TestGeoDataBuilding::testHeightExtraction() | ||||
67 | { | ||||
68 | QString const meters1 = "12 m"; | ||||
nienhueser: Can we have a case where no unit is specified, too? | |||||
69 | QString const meters2 = "12.8 meters"; | ||||
70 | QString const meters3 = "12.56 meter"; | ||||
71 | QString const meters4 = "14.44 metres"; | ||||
72 | QString const meters5 = "23.43 metre"; | ||||
73 | | ||||
74 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters1), 12.0, 0.0001); | ||||
75 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters2), 12.8, 0.0001); | ||||
76 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters3), 12.56, 0.0001); | ||||
77 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters4), 14.44, 0.0001); | ||||
78 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(meters5), 23.43, 0.0001); | ||||
79 | | ||||
80 | QString const feet1 = "55'4\""; // 664 inches | ||||
81 | QString const feet2 = "60.56 feet"; // 726.72 inches | ||||
82 | QString const feet3 = "300\'"; // 3600 inches | ||||
83 | | ||||
84 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(feet1), 16.8656, 0.0001); | ||||
85 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(feet2), 18.4587, 0.0001); | ||||
86 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(feet3), 91.44, 0.0001); | ||||
87 | | ||||
88 | QString const unitless1 = "0.8"; // default in meters | ||||
89 | QString const unitless2 = "12"; // default in meters | ||||
90 | | ||||
91 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(unitless1), 0.8, 0.0001); | ||||
92 | QFUZZYCOMPARE(GeoDataBuilding::parseBuildingHeight(unitless2), 12.0, 0.0001); | ||||
93 | } | ||||
94 | | ||||
65 | } | 95 | } | ||
66 | 96 | | |||
67 | QTEST_MAIN(Marble::TestGeoDataBuilding) | 97 | QTEST_MAIN(Marble::TestGeoDataBuilding) | ||
68 | 98 | | |||
69 | #include "TestGeoDataBuilding.moc" | 99 | #include "TestGeoDataBuilding.moc" |
Can we have a case where no unit is specified, too?