File indexing completed on 2024-04-28 04:42:40
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include <kweathercore/hourlyweatherforecast.h> 0009 0010 #include <QTest> 0011 0012 using namespace KWeatherCore; 0013 0014 class HourlyForecastTest : public QObject 0015 { 0016 Q_OBJECT 0017 private Q_SLOTS: 0018 void testJson() 0019 { 0020 HourlyWeatherForecast d1(QDateTime::currentDateTime()); 0021 0022 auto d2 = HourlyWeatherForecast::fromJson(d1.toJson()); 0023 0024 QCOMPARE(d2.toJson(), d1.toJson()); 0025 } 0026 0027 void testWindDirectionCardinal_data() 0028 { 0029 QTest::addColumn<double>("degree"); 0030 QTest::addColumn<WindDirection>("dir"); 0031 0032 QTest::addRow("0") << 0.0 << WindDirection::N; 0033 QTest::addRow("355") << 355.0 << WindDirection::N; 0034 QTest::addRow("360") << 360.0 << WindDirection::N; 0035 QTest::addRow("10") << 10.0 << WindDirection::N; 0036 QTest::addRow("22.4") << 22.4 << WindDirection::N; 0037 QTest::addRow("22.6") << 22.6 << WindDirection::NE; 0038 QTest::addRow("90") << 90.0 << WindDirection::E; 0039 QTest::addRow("135") << 135.0 << WindDirection::SE; 0040 QTest::addRow("280") << 280.0 << WindDirection::W; 0041 } 0042 0043 void testWindDirectionCardinal() 0044 { 0045 QFETCH(double, degree); 0046 QFETCH(WindDirection, dir); 0047 HourlyWeatherForecast f; 0048 f.setWindDirectionDegree(degree); 0049 QCOMPARE(f.windDirectionCardinal(), dir); 0050 } 0051 }; 0052 QTEST_APPLESS_MAIN(HourlyForecastTest) 0053 0054 #include "hourlyweatherforecasttest.moc"