Changeset View
Changeset View
Standalone View
Standalone View
autotests/testseasons.cpp
Show All 21 Lines | |||||
22 | #include "testseasons.h" | 22 | #include "testseasons.h" | ||
23 | #include "astroseasons.h" | 23 | #include "astroseasons.h" | ||
24 | using namespace KHolidays; | 24 | using namespace KHolidays; | ||
25 | 25 | | |||
26 | #include <QTest> | 26 | #include <QTest> | ||
27 | 27 | | |||
28 | QTEST_MAIN(SeasonsTest) | 28 | QTEST_MAIN(SeasonsTest) | ||
29 | 29 | | |||
30 | void SeasonsTest::test2005() | 30 | Q_DECLARE_METATYPE(AstroSeasons::Season) | ||
31 | | ||||
32 | void SeasonsTest::test_data() | ||||
31 | { | 33 | { | ||
32 | AstroSeasons as; | 34 | QTest::addColumn<QDate>("date"); | ||
33 | QVERIFY(as.seasonAtDate(QDate(2005, 3, 22)) == AstroSeasons::MarchEquinox); | 35 | QTest::addColumn<AstroSeasons::Season>("season"); | ||
34 | QVERIFY(as.seasonAtDate(QDate(2005, 6, 22)) == AstroSeasons::JuneSolstice); | 36 | | ||
35 | QVERIFY(as.seasonAtDate(QDate(2005, 9, 22)) == AstroSeasons::SeptemberEquinox); | 37 | // Test data obtained from https://data.giss.nasa.gov/ar5/srvernal.html | ||
36 | QVERIFY(as.seasonAtDate(QDate(2005, 12, 22)) == AstroSeasons::DecemberSolstice); | 38 | QTest::newRow("2005-03-20") << QDate(2005, 3, 20) << AstroSeasons::MarchEquinox; | ||
37 | QVERIFY(as.seasonAtDate(QDate(2005, 1, 22)) == AstroSeasons::None); | 39 | QTest::newRow("2005-06-21") << QDate(2005, 6, 21) << AstroSeasons::JuneSolstice; | ||
38 | QVERIFY(as.seasonAtDate(QDate(2005, 12, 31)) == AstroSeasons::None); | 40 | QTest::newRow("2005-09-22") << QDate(2005, 9, 22) << AstroSeasons::SeptemberEquinox; | ||
41 | QTest::newRow("2005-12-21") << QDate(2005, 12, 21) << AstroSeasons::DecemberSolstice; | ||||
42 | QTest::newRow("2005-01-22") << QDate(2005, 1, 22) << AstroSeasons::None; | ||||
43 | QTest::newRow("2005-12-31") << QDate(2005, 12, 31) << AstroSeasons::None; | ||||
44 | QTest::newRow("2007-03-21") << QDate(2007, 3, 21) << AstroSeasons::MarchEquinox; | ||||
45 | QTest::newRow("2007-06-21") << QDate(2007, 6, 21) << AstroSeasons::JuneSolstice; | ||||
46 | QTest::newRow("2007-09-23") << QDate(2007, 9, 23) << AstroSeasons::SeptemberEquinox; | ||||
47 | QTest::newRow("2007-12-22") << QDate(2007, 12, 22) << AstroSeasons::DecemberSolstice; | ||||
48 | QTest::newRow("2018-03-20") << QDate(2018, 3, 20) << AstroSeasons::MarchEquinox; | ||||
49 | QTest::newRow("2018-06-21") << QDate(2018, 6, 21) << AstroSeasons::JuneSolstice; | ||||
50 | QTest::newRow("2018-09-23") << QDate(2018, 9, 23) << AstroSeasons::SeptemberEquinox; | ||||
51 | QTest::newRow("2018-12-21") << QDate(2018, 12, 21) << AstroSeasons::DecemberSolstice; | ||||
52 | QTest::newRow("2020-03-20") << QDate(2020, 3, 20) << AstroSeasons::MarchEquinox; | ||||
53 | QTest::newRow("2020-06-20") << QDate(2020, 6, 20) << AstroSeasons::JuneSolstice; | ||||
54 | QTest::newRow("2020-09-22") << QDate(2020, 9, 22) << AstroSeasons::SeptemberEquinox; | ||||
55 | QTest::newRow("2020-12-21") << QDate(2020, 12, 21) << AstroSeasons::DecemberSolstice; | ||||
56 | QTest::newRow("2042-03-20") << QDate(2042, 3, 20) << AstroSeasons::MarchEquinox; | ||||
57 | QTest::newRow("2042-06-21") << QDate(2042, 6, 21) << AstroSeasons::JuneSolstice; | ||||
58 | QTest::newRow("2042-09-22") << QDate(2042, 9, 22) << AstroSeasons::SeptemberEquinox; | ||||
59 | QTest::newRow("2042-12-21") << QDate(2042, 12, 21) << AstroSeasons::DecemberSolstice; | ||||
39 | } | 60 | } | ||
40 | 61 | | |||
41 | void SeasonsTest::test2007() | 62 | void SeasonsTest::test() | ||
42 | { | 63 | { | ||
64 | QFETCH(QDate, date); | ||||
65 | QFETCH(AstroSeasons::Season, season); | ||||
66 | | ||||
43 | AstroSeasons as; | 67 | AstroSeasons as; | ||
44 | QVERIFY(as.seasonAtDate(QDate(2007, 3, 22)) == AstroSeasons::MarchEquinox); | 68 | QCOMPARE(as.seasonAtDate(date), season); | ||
45 | QVERIFY(as.seasonAtDate(QDate(2007, 6, 22)) == AstroSeasons::JuneSolstice); | | |||
46 | QVERIFY(as.seasonAtDate(QDate(2007, 9, 22)) == AstroSeasons::SeptemberEquinox); | | |||
47 | QVERIFY(as.seasonAtDate(QDate(2007, 12, 22)) == AstroSeasons::DecemberSolstice); | | |||
48 | QVERIFY(as.seasonAtDate(QDate(2007, 1, 2)) == AstroSeasons::None); | | |||
49 | QVERIFY(as.seasonAtDate(QDate(2007, 11, 30)) == AstroSeasons::None); | | |||
50 | } | 69 | } |