File indexing completed on 2024-05-19 11:37:30

0001 /*
0002     This file is part of the kholidays library.
0003 
0004     SPDX-FileCopyrightText: 2004, 2006-2007 Allen Winter <winter@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "testseasons.h"
0010 #include "astroseasons.h"
0011 using namespace KHolidays;
0012 
0013 #include <QTest>
0014 
0015 QTEST_MAIN(SeasonsTest)
0016 
0017 Q_DECLARE_METATYPE(AstroSeasons::Season)
0018 
0019 void SeasonsTest::test_data()
0020 {
0021     QTest::addColumn<QDate>("date");
0022     QTest::addColumn<AstroSeasons::Season>("season");
0023 
0024     // Test data obtained from https://data.giss.nasa.gov/ar5/srvernal.html
0025     // clang-format off
0026     QTest::newRow("2005-03-20") << QDate(2005,  3, 20) << AstroSeasons::MarchEquinox;
0027     QTest::newRow("2005-06-21") << QDate(2005,  6, 21) << AstroSeasons::JuneSolstice;
0028     QTest::newRow("2005-09-22") << QDate(2005,  9, 22) << AstroSeasons::SeptemberEquinox;
0029     QTest::newRow("2005-12-21") << QDate(2005, 12, 21) << AstroSeasons::DecemberSolstice;
0030     QTest::newRow("2005-01-22") << QDate(2005,  1, 22) << AstroSeasons::None;
0031     QTest::newRow("2005-12-31") << QDate(2005, 12, 31) << AstroSeasons::None;
0032     QTest::newRow("2007-03-21") << QDate(2007,  3, 21) << AstroSeasons::MarchEquinox;
0033     QTest::newRow("2007-06-21") << QDate(2007,  6, 21) << AstroSeasons::JuneSolstice;
0034     QTest::newRow("2007-09-23") << QDate(2007,  9, 23) << AstroSeasons::SeptemberEquinox;
0035     QTest::newRow("2007-12-22") << QDate(2007, 12, 22) << AstroSeasons::DecemberSolstice;
0036     QTest::newRow("2018-03-20") << QDate(2018,  3, 20) << AstroSeasons::MarchEquinox;
0037     QTest::newRow("2018-06-21") << QDate(2018,  6, 21) << AstroSeasons::JuneSolstice;
0038     QTest::newRow("2018-09-23") << QDate(2018,  9, 23) << AstroSeasons::SeptemberEquinox;
0039     QTest::newRow("2018-12-21") << QDate(2018, 12, 21) << AstroSeasons::DecemberSolstice;
0040     QTest::newRow("2020-03-20") << QDate(2020,  3, 20) << AstroSeasons::MarchEquinox;
0041     QTest::newRow("2020-06-20") << QDate(2020,  6, 20) << AstroSeasons::JuneSolstice;
0042     QTest::newRow("2020-09-22") << QDate(2020,  9, 22) << AstroSeasons::SeptemberEquinox;
0043     QTest::newRow("2020-12-21") << QDate(2020, 12, 21) << AstroSeasons::DecemberSolstice;
0044     QTest::newRow("2042-03-20") << QDate(2042,  3, 20) << AstroSeasons::MarchEquinox;
0045     QTest::newRow("2042-06-21") << QDate(2042,  6, 21) << AstroSeasons::JuneSolstice;
0046     QTest::newRow("2042-09-22") << QDate(2042,  9, 22) << AstroSeasons::SeptemberEquinox;
0047     QTest::newRow("2042-12-21") << QDate(2042, 12, 21) << AstroSeasons::DecemberSolstice;
0048     // clang-format on
0049 }
0050 
0051 void SeasonsTest::test()
0052 {
0053     QFETCH(QDate, date);
0054     QFETCH(AstroSeasons::Season, season);
0055 
0056     AstroSeasons as;
0057     QCOMPARE(as.seasonAtDate(date), season);
0058 }
0059 
0060 #include "moc_testseasons.cpp"