mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-13 12:42:20 +00:00
Implemented user defined relative date ranges (#4534)
Fixes #4512 * Added additional time range options for user defined seasons * Relative start (e.g. 3 months ago) * Duration after start / Duration before end (e.g. 2 months) * Year to Date end, defining the end as the closest day with todays day and month after start * Refactored Season.h/cpp and SeasonParser.h/cpp for better testability * Kept Season, Phase, SeasonEvent, SeasonOffset, SeasonLength in Season.h/cpp * Moved all UI related classes to SeasonDialogs.h/cpp * Renamed SeasonParser.h/cpp to Seasons.h/cpp, moved class Seasons there * Replaced deprecated Qt classes * Replaced QRegExp by QRegularExpression in SeasonParser * Rewrote parsing seasons.xml to use QXmlStreamReader instead of QXmlSimpleReader * Unittesting * Added a simple way to implement and execute (make check) unittests in Golden Cheetahs source tree based on Qt Test (https://doc.qt.io/qt-6/qttest-index.html), tested on Linux and Windows * Implemented unittests for classes (mostly before refactoring) * Season * SeasonParser * SeasonOffset
This commit is contained in:
committed by
GitHub
parent
60f9033617
commit
9242f724db
7
unittests/season/season.pro
Normal file
7
unittests/season/season.pro
Normal file
@@ -0,0 +1,7 @@
|
||||
QT += testlib widgets
|
||||
|
||||
SOURCES = testSeason.cpp
|
||||
GC_OBJS = Season \
|
||||
Utils
|
||||
|
||||
include(../unittests.pri)
|
||||
280
unittests/season/testSeason.cpp
Normal file
280
unittests/season/testSeason.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
#include "Core/Season.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
|
||||
class TestSeason: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestSeason(): reference(2024, 8, 20) {
|
||||
}
|
||||
|
||||
private slots:
|
||||
void builtInAllDates() {
|
||||
Season season;
|
||||
season.setName("All Dates");
|
||||
season.setOffsetAndLength(-50, 1, 1, 100, 0, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(1974, 1, 1));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2073, 12, 31));
|
||||
}
|
||||
|
||||
void builtInThisYear() {
|
||||
Season season;
|
||||
season.setName("This Year");
|
||||
season.setOffsetAndLength(0, 1, 1, 1, 0, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 1, 1));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 12, 31));
|
||||
}
|
||||
|
||||
void builtInThisMonth() {
|
||||
Season season;
|
||||
season.setName("This Month");
|
||||
season.setOffsetAndLength(1, 0, 1, 0, 1, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 8, 1));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 31));
|
||||
}
|
||||
|
||||
void builtInLastMonth() {
|
||||
Season season;
|
||||
season.setName("Last Month");
|
||||
season.setOffsetAndLength(1, -1, 1, 0, 1, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 7, 1));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 7, 31));
|
||||
}
|
||||
|
||||
void builtInThisWeek() {
|
||||
Season season;
|
||||
season.setName("This Week");
|
||||
season.setOffsetAndLength(1, 1, 0, 0, 0, 7);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 8, 19));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 25));
|
||||
}
|
||||
|
||||
void builtInLastWeek() {
|
||||
Season season;
|
||||
season.setName("Last Week");
|
||||
season.setOffsetAndLength(1, 1, -1, 0, 0, 7);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 8, 12));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 18));
|
||||
}
|
||||
|
||||
void builtInLast24Hours() {
|
||||
Season season;
|
||||
season.setName("Last 24 hours");
|
||||
season.setLengthOnly(0, 0, 2);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 8, 19));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast7Days() {
|
||||
Season season;
|
||||
season.setName("Last 7 days");
|
||||
season.setLengthOnly(0, 0, 7);
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast14Days() {
|
||||
Season season;
|
||||
season.setName("Last 14 days");
|
||||
season.setLengthOnly(0, 0, 14);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 8, 7));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast21Days() {
|
||||
Season season;
|
||||
season.setName("Last 21 days");
|
||||
season.setLengthOnly(0, 0, 21);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 7, 31));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast28Days() {
|
||||
Season season;
|
||||
season.setName("Last 28 days");
|
||||
season.setLengthOnly(0, 0, 28);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 7, 24));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast6Weeks() {
|
||||
Season season;
|
||||
season.setName("Last 6 weeks");
|
||||
season.setLengthOnly(0, 0, 42);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 7, 10));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast2Months() {
|
||||
Season season;
|
||||
season.setName("Last 2 months");
|
||||
season.setLengthOnly(0, 2, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 6, 21));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast3Months() {
|
||||
Season season;
|
||||
season.setName("Last 3 months");
|
||||
season.setLengthOnly(0, 3, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 5, 21));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast6Months() {
|
||||
Season season;
|
||||
season.setName("Last 6 months");
|
||||
season.setLengthOnly(0, 6, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 2, 21));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void builtInLast12Months() {
|
||||
Season season;
|
||||
season.setName("Last 12 months");
|
||||
season.setLengthOnly(1, 0, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2023, 8, 21));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void absStartAbsEnd() {
|
||||
Season season;
|
||||
season.setAbsoluteStart(QDate(2022, 4, 8));
|
||||
season.setAbsoluteEnd(QDate(2023, 3, 7));
|
||||
QCOMPARE(season.getStart(reference), QDate(2022, 4, 8));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2023, 3, 7));
|
||||
}
|
||||
|
||||
void absStartRelEnd() {
|
||||
Season season;
|
||||
season.setAbsoluteStart(QDate(2022, 4, 8));
|
||||
season.setOffsetEnd(1, -5, 1, false);
|
||||
QCOMPARE(season.getStart(reference), QDate(2022, 4, 8));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 3, 20));
|
||||
}
|
||||
|
||||
void absStartDurationAfter() {
|
||||
Season season;
|
||||
season.setAbsoluteStart(QDate(2022, 4, 8));
|
||||
season.setLength(0, 2, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2022, 4, 8));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2022, 6, 7));
|
||||
}
|
||||
|
||||
void absStartYtd() {
|
||||
Season season;
|
||||
season.setAbsoluteStart(QDate(2022, 4, 8));
|
||||
season.setYtd();
|
||||
QCOMPARE(season.getStart(reference), QDate(2022, 4, 8));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2022, 8, 20));
|
||||
}
|
||||
|
||||
void absStartYtdOverflow() {
|
||||
Season season;
|
||||
season.setAbsoluteStart(QDate(2022, 9, 8));
|
||||
season.setYtd();
|
||||
QCOMPARE(season.getStart(reference), QDate(2022, 9, 8));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2023, 8, 20));
|
||||
}
|
||||
|
||||
void relStartAbsEnd() {
|
||||
Season season;
|
||||
season.setOffsetStart(-5, 1, 1, false);
|
||||
season.setAbsoluteEnd(QDate(2023, 3, 7));
|
||||
QCOMPARE(season.getStart(reference), QDate(2019, 8, 20));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2023, 3, 7));
|
||||
}
|
||||
|
||||
void relStartRelEndYear() {
|
||||
Season season;
|
||||
season.setOffsetStart(-2, 1, 1, false);
|
||||
season.setOffsetEnd(-1, 1, 1, false);
|
||||
QCOMPARE(season.getStart(reference), QDate(2022, 8, 20));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2023, 8, 20));
|
||||
}
|
||||
|
||||
void relStartRelEndMonthDay() {
|
||||
Season season;
|
||||
season.setOffsetStart(1, -5, 1, false);
|
||||
season.setOffsetEnd(1, 1, -5, false);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 3, 20));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 7, 16));
|
||||
}
|
||||
|
||||
void relStartDurationAfter() {
|
||||
Season season;
|
||||
season.setOffsetStart(1, -5, 1, false);
|
||||
season.setLength(0, 2, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 3, 20));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 5, 19));
|
||||
}
|
||||
|
||||
void relStartYtd() {
|
||||
Season season;
|
||||
season.setOffsetStart(1, -2, 1, false);
|
||||
season.setYtd();
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 6, 20));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
|
||||
}
|
||||
|
||||
void relStartYtdOverflow() {
|
||||
Season season;
|
||||
season.setOffsetStart(1, -21, 1, false);
|
||||
season.setYtd();
|
||||
QCOMPARE(season.getStart(reference), QDate(2022, 11, 20));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2023, 8, 20));
|
||||
}
|
||||
|
||||
void durationBeforeAbsEnd() {
|
||||
Season season;
|
||||
season.setAbsoluteEnd(QDate(2023, 3, 7));
|
||||
season.setLength(0, 2, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2023, 1, 8));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2023, 3, 7));
|
||||
}
|
||||
|
||||
void durationBeforeRelEnd() {
|
||||
Season season;
|
||||
season.setOffsetEnd(1, -5, 1, false);
|
||||
season.setLength(0, 2, 0);
|
||||
QCOMPARE(season.getStart(reference), QDate(2024, 1, 21));
|
||||
QCOMPARE(season.getEnd(reference), QDate(2024, 3, 20));
|
||||
}
|
||||
|
||||
void isAbsolute() {
|
||||
Season season;
|
||||
|
||||
season.setOffsetEnd(1, -5, 1, false);
|
||||
season.setLength(0, 2, 0);
|
||||
QCOMPARE(season.isAbsolute(), false);
|
||||
|
||||
season.resetTimeRange();
|
||||
season.setAbsoluteStart(QDate(2024, 1, 1));
|
||||
season.setYtd();
|
||||
QCOMPARE(season.isAbsolute(), false);
|
||||
|
||||
season.resetTimeRange();
|
||||
season.setAbsoluteStart(QDate(2024, 1, 1));
|
||||
season.setAbsoluteEnd(QDate(2024, 2, 3));
|
||||
QCOMPARE(season.isAbsolute(), true);
|
||||
|
||||
season.resetTimeRange();
|
||||
season.setAbsoluteStart(QDate(2024, 1, 1));
|
||||
season.setLength(0, 2, 0);
|
||||
QCOMPARE(season.isAbsolute(), true);
|
||||
|
||||
season.resetTimeRange();
|
||||
season.setLength(0, 2, 0);
|
||||
season.setAbsoluteEnd(QDate(2024, 1, 1));
|
||||
QCOMPARE(season.isAbsolute(), true);
|
||||
}
|
||||
|
||||
private:
|
||||
const QDate reference;
|
||||
};
|
||||
|
||||
|
||||
QTEST_MAIN(TestSeason)
|
||||
#include "testSeason.moc"
|
||||
6
unittests/seasonOffset/seasonOffset.pro
Normal file
6
unittests/seasonOffset/seasonOffset.pro
Normal file
@@ -0,0 +1,6 @@
|
||||
QT += testlib widgets
|
||||
|
||||
SOURCES = testSeasonOffset.cpp
|
||||
GC_OBJS = Season
|
||||
|
||||
include(../unittests.pri)
|
||||
52
unittests/seasonOffset/testSeasonOffset.cpp
Normal file
52
unittests/seasonOffset/testSeasonOffset.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "Core/Season.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
|
||||
class TestSeasonOffset: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void isValidFalse() {
|
||||
SeasonOffset offset;
|
||||
QCOMPARE(offset.isValid(), false);
|
||||
}
|
||||
|
||||
void isValidTrue() {
|
||||
SeasonOffset offset(-1, 1, 1);
|
||||
QCOMPARE(offset.isValid(), true);
|
||||
}
|
||||
|
||||
void significantItemInvalid() {
|
||||
SeasonOffset offset;
|
||||
std::pair<SeasonOffset::SeasonOffsetType, int> item = offset.getSignificantItem();
|
||||
QCOMPARE(item.first, SeasonOffset::invalid);
|
||||
QCOMPARE(item.second, 0);
|
||||
}
|
||||
|
||||
void significantItemYear() {
|
||||
SeasonOffset offset(-2, 1, 1);
|
||||
std::pair<SeasonOffset::SeasonOffsetType, int> item = offset.getSignificantItem();
|
||||
QCOMPARE(item.first, SeasonOffset::year);
|
||||
QCOMPARE(item.second, -2);
|
||||
}
|
||||
|
||||
void significantItemMonth() {
|
||||
SeasonOffset offset(1, -2, 1);
|
||||
std::pair<SeasonOffset::SeasonOffsetType, int> item = offset.getSignificantItem();
|
||||
QCOMPARE(item.first, SeasonOffset::month);
|
||||
QCOMPARE(item.second, -2);
|
||||
}
|
||||
|
||||
void significantItemWeek() {
|
||||
SeasonOffset offset(1, 1, -2);
|
||||
std::pair<SeasonOffset::SeasonOffsetType, int> item = offset.getSignificantItem();
|
||||
QCOMPARE(item.first, SeasonOffset::week);
|
||||
QCOMPARE(item.second, -2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QTEST_MAIN(TestSeasonOffset)
|
||||
#include "testSeasonOffset.moc"
|
||||
9
unittests/seasonParser/seasonParser.pro
Normal file
9
unittests/seasonParser/seasonParser.pro
Normal file
@@ -0,0 +1,9 @@
|
||||
QT += testlib widgets xml
|
||||
|
||||
SOURCES = testSeasonParser.cpp
|
||||
GC_OBJS = Seasons \
|
||||
moc_Seasons \
|
||||
Season \
|
||||
Utils
|
||||
|
||||
include(../unittests.pri)
|
||||
93
unittests/seasonParser/seasons.xml
Normal file
93
unittests/seasonParser/seasons.xml
Normal file
@@ -0,0 +1,93 @@
|
||||
<seasons>
|
||||
<season>
|
||||
<name>3-0 months ago</name>
|
||||
<type>0</type>
|
||||
<id>{728c23b7-d576-482c-a16a-d28c2ea9d76f}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
<startoffset>1-3</startoffset>
|
||||
<endoffset>2-0</endoffset>
|
||||
</season>
|
||||
<season>
|
||||
<name>6-3 months ago</name>
|
||||
<type>0</type>
|
||||
<id>{80348210-8dba-413d-b016-31db8813dffa}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
<startoffset>1-6</startoffset>
|
||||
<length>0-3-0</length>
|
||||
</season>
|
||||
<season>
|
||||
<name>2023 - YTD</name>
|
||||
<type>0</type>
|
||||
<id>{e41cbecf-9dac-41db-bae1-df45877a09ae}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
<startdate>2023-01-01</startdate>
|
||||
<ytd/>
|
||||
</season>
|
||||
<season>
|
||||
<name>2023</name>
|
||||
<type>0</type>
|
||||
<id>{ed5613a6-875a-483b-a59d-dec36b79fa21}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
<startdate>2023-01-01</startdate>
|
||||
<length>1-0-0</length>
|
||||
</season>
|
||||
<season>
|
||||
<phase>
|
||||
<name>Phase</name>
|
||||
<startdate>2024-01-25</startdate>
|
||||
<enddate>2024-01-31</enddate>
|
||||
<type>100</type>
|
||||
<id>{a3d28e7c-bf42-4a04-8928-c18671c698bc}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
</phase>
|
||||
<phase>
|
||||
<name>Prep</name>
|
||||
<startdate>2024-02-01</startdate>
|
||||
<enddate>2024-02-10</enddate>
|
||||
<type>101</type>
|
||||
<id>{86489889-ba6e-4006-a7ea-2f9bb7be0620}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
</phase>
|
||||
<phase>
|
||||
<name>Base</name>
|
||||
<startdate>2024-03-01</startdate>
|
||||
<enddate>2024-03-31</enddate>
|
||||
<type>102</type>
|
||||
<id>{f7147da0-de38-41de-9bee-e50562f1dd5f}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
</phase>
|
||||
<phase>
|
||||
<name>Build</name>
|
||||
<startdate>2024-04-01</startdate>
|
||||
<enddate>2024-04-30</enddate>
|
||||
<type>103</type>
|
||||
<id>{98c59d49-65a8-4555-b7c2-8622f24d6091}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
</phase>
|
||||
<phase>
|
||||
<name>Camp</name>
|
||||
<startdate>2024-05-01</startdate>
|
||||
<enddate>2024-05-31</enddate>
|
||||
<type>120</type>
|
||||
<id>{13fc11c3-4dd1-49df-b927-5d5e33074ee4}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
</phase>
|
||||
<name>2024</name>
|
||||
<type>0</type>
|
||||
<id>{ea549d73-7d8b-4df4-a16e-0ce50f92d131}</id>
|
||||
<seed>0</seed>
|
||||
<low>-50</low>
|
||||
<startdate>2024-01-01</startdate>
|
||||
<enddate>2024-12-31</enddate>
|
||||
<event date="2024-10-19" priority="1" description="Description" id="">"Event"</event>
|
||||
</season>
|
||||
</seasons>
|
||||
140
unittests/seasonParser/testSeasonParser.cpp
Normal file
140
unittests/seasonParser/testSeasonParser.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
#include "Core/Seasons.h"
|
||||
#include "Core/Season.h"
|
||||
|
||||
#include <QTest>
|
||||
#include <QFile>
|
||||
#include <QList>
|
||||
|
||||
|
||||
class TestSeasonParser: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void readSeasons() {
|
||||
QFile file("seasons.xml");
|
||||
QList<Season> seasons = SeasonParser::readSeasons(&file);
|
||||
|
||||
QCOMPARE(seasons.size(), 5);
|
||||
|
||||
int sx = 0;
|
||||
|
||||
QCOMPARE(seasons[sx].getName(), "3-0 months ago");
|
||||
QCOMPARE(seasons[sx].getType(), Season::season);
|
||||
QCOMPARE(seasons[sx].id().toString(), "{728c23b7-d576-482c-a16a-d28c2ea9d76f}");
|
||||
QCOMPARE(seasons[sx].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].getAbsoluteStart(), QDate());
|
||||
QCOMPARE(seasons[sx].getAbsoluteEnd(), QDate());
|
||||
QCOMPARE(seasons[sx].getOffsetStart(), SeasonOffset(1, -3, 1, false));
|
||||
QCOMPARE(seasons[sx].getOffsetEnd(), SeasonOffset(1, 1, 0, false));
|
||||
QCOMPARE(seasons[sx].isYtd(), false);
|
||||
QCOMPARE(seasons[sx].getLength(), SeasonLength());
|
||||
QCOMPARE(seasons[sx].events.size(), 0);
|
||||
QCOMPARE(seasons[sx].phases.size(), 0);
|
||||
|
||||
++sx;
|
||||
QCOMPARE(seasons[sx].getName(), "6-3 months ago");
|
||||
QCOMPARE(seasons[sx].getType(), Season::season);
|
||||
QCOMPARE(seasons[sx].id().toString(), "{80348210-8dba-413d-b016-31db8813dffa}");
|
||||
QCOMPARE(seasons[sx].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].getAbsoluteStart(), QDate());
|
||||
QCOMPARE(seasons[sx].getAbsoluteEnd(), QDate());
|
||||
QCOMPARE(seasons[sx].getOffsetStart(), SeasonOffset(1, -6, 1, false));
|
||||
QCOMPARE(seasons[sx].getOffsetEnd(), SeasonOffset());
|
||||
QCOMPARE(seasons[sx].isYtd(), false);
|
||||
QCOMPARE(seasons[sx].getLength(), SeasonLength(0, 3, 0));
|
||||
QCOMPARE(seasons[sx].events.size(), 0);
|
||||
QCOMPARE(seasons[sx].phases.size(), 0);
|
||||
|
||||
++sx;
|
||||
QCOMPARE(seasons[sx].getName(), "2023 - YTD");
|
||||
QCOMPARE(seasons[sx].getType(), Season::season);
|
||||
QCOMPARE(seasons[sx].id().toString(), "{e41cbecf-9dac-41db-bae1-df45877a09ae}");
|
||||
QCOMPARE(seasons[sx].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].getAbsoluteStart(), QDate(2023, 1, 1));
|
||||
QCOMPARE(seasons[sx].getAbsoluteEnd(), QDate());
|
||||
QCOMPARE(seasons[sx].getOffsetStart(), SeasonOffset());
|
||||
QCOMPARE(seasons[sx].getOffsetEnd(), SeasonOffset());
|
||||
QCOMPARE(seasons[sx].isYtd(), true);
|
||||
QCOMPARE(seasons[sx].getLength(), SeasonLength());
|
||||
QCOMPARE(seasons[sx].events.size(), 0);
|
||||
QCOMPARE(seasons[sx].phases.size(), 0);
|
||||
|
||||
++sx;
|
||||
QCOMPARE(seasons[sx].getName(), "2023");
|
||||
QCOMPARE(seasons[sx].getType(), Season::season);
|
||||
QCOMPARE(seasons[sx].id().toString(), "{ed5613a6-875a-483b-a59d-dec36b79fa21}");
|
||||
QCOMPARE(seasons[sx].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].getAbsoluteStart(), QDate(2023, 1, 1));
|
||||
QCOMPARE(seasons[sx].getAbsoluteEnd(), QDate());
|
||||
QCOMPARE(seasons[sx].getOffsetStart(), SeasonOffset());
|
||||
QCOMPARE(seasons[sx].getOffsetEnd(), SeasonOffset());
|
||||
QCOMPARE(seasons[sx].isYtd(), false);
|
||||
QCOMPARE(seasons[sx].getLength(), SeasonLength(1, 0, 0));
|
||||
QCOMPARE(seasons[sx].events.size(), 0);
|
||||
QCOMPARE(seasons[sx].phases.size(), 0);
|
||||
|
||||
++sx;
|
||||
QCOMPARE(seasons[sx].getName(), "2024");
|
||||
QCOMPARE(seasons[sx].getType(), Season::season);
|
||||
QCOMPARE(seasons[sx].id().toString(), "{ea549d73-7d8b-4df4-a16e-0ce50f92d131}");
|
||||
QCOMPARE(seasons[sx].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].getAbsoluteStart(), QDate(2024, 1, 1));
|
||||
QCOMPARE(seasons[sx].getAbsoluteEnd(), QDate(2024, 12, 31));
|
||||
QCOMPARE(seasons[sx].getOffsetStart(), SeasonOffset());
|
||||
QCOMPARE(seasons[sx].getOffsetEnd(), SeasonOffset());
|
||||
QCOMPARE(seasons[sx].isYtd(), false);
|
||||
QCOMPARE(seasons[sx].getLength(), SeasonLength());
|
||||
QCOMPARE(seasons[sx].events.size(), 1);
|
||||
QCOMPARE(seasons[sx].events[0].name, "Event");
|
||||
QCOMPARE(seasons[sx].events[0].date, QDate(2024, 10, 19));
|
||||
QCOMPARE(seasons[sx].events[0].priority, 1);
|
||||
QCOMPARE(seasons[sx].events[0].description, "Description");
|
||||
QCOMPARE(seasons[sx].events[0].id, "");
|
||||
QCOMPARE(seasons[sx].phases.size(), 5);
|
||||
QCOMPARE(seasons[sx].phases[0].getName(), "Phase");
|
||||
QCOMPARE(seasons[sx].phases[0].getAbsoluteStart(), QDate(2024, 1, 25));
|
||||
QCOMPARE(seasons[sx].phases[0].getAbsoluteEnd(), QDate(2024, 1, 31));
|
||||
QCOMPARE(seasons[sx].phases[0].getType(), Phase::phase);
|
||||
QCOMPARE(seasons[sx].phases[0].id().toString(), "{a3d28e7c-bf42-4a04-8928-c18671c698bc}");
|
||||
QCOMPARE(seasons[sx].phases[0].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].phases[0].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].phases[1].getName(), "Prep");
|
||||
QCOMPARE(seasons[sx].phases[1].getAbsoluteStart(), QDate(2024, 2, 1));
|
||||
QCOMPARE(seasons[sx].phases[1].getAbsoluteEnd(), QDate(2024, 2, 10));
|
||||
QCOMPARE(seasons[sx].phases[1].getType(), Phase::prep);
|
||||
QCOMPARE(seasons[sx].phases[1].id().toString(), "{86489889-ba6e-4006-a7ea-2f9bb7be0620}");
|
||||
QCOMPARE(seasons[sx].phases[1].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].phases[1].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].phases[2].getName(), "Base");
|
||||
QCOMPARE(seasons[sx].phases[2].getAbsoluteStart(), QDate(2024, 3, 1));
|
||||
QCOMPARE(seasons[sx].phases[2].getAbsoluteEnd(), QDate(2024, 3, 31));
|
||||
QCOMPARE(seasons[sx].phases[2].getType(), Phase::base);
|
||||
QCOMPARE(seasons[sx].phases[2].id().toString(), "{f7147da0-de38-41de-9bee-e50562f1dd5f}");
|
||||
QCOMPARE(seasons[sx].phases[2].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].phases[2].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].phases[3].getName(), "Build");
|
||||
QCOMPARE(seasons[sx].phases[3].getAbsoluteStart(), QDate(2024, 4, 1));
|
||||
QCOMPARE(seasons[sx].phases[3].getAbsoluteEnd(), QDate(2024, 4, 30));
|
||||
QCOMPARE(seasons[sx].phases[3].getType(), Phase::build);
|
||||
QCOMPARE(seasons[sx].phases[3].id().toString(), "{98c59d49-65a8-4555-b7c2-8622f24d6091}");
|
||||
QCOMPARE(seasons[sx].phases[3].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].phases[3].getLow(), -50);
|
||||
QCOMPARE(seasons[sx].phases[4].getName(), "Camp");
|
||||
QCOMPARE(seasons[sx].phases[4].getAbsoluteStart(), QDate(2024, 5, 1));
|
||||
QCOMPARE(seasons[sx].phases[4].getAbsoluteEnd(), QDate(2024, 5, 31));
|
||||
QCOMPARE(seasons[sx].phases[4].getType(), Phase::camp);
|
||||
QCOMPARE(seasons[sx].phases[4].id().toString(), "{13fc11c3-4dd1-49df-b927-5d5e33074ee4}");
|
||||
QCOMPARE(seasons[sx].phases[4].getSeed(), 0);
|
||||
QCOMPARE(seasons[sx].phases[4].getLow(), -50);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
QTEST_MAIN(TestSeasonParser)
|
||||
#include "testSeasonParser.moc"
|
||||
23
unittests/unittests.pri.in
Normal file
23
unittests/unittests.pri.in
Normal file
@@ -0,0 +1,23 @@
|
||||
GC_UNITTESTS = active
|
||||
|
||||
|
||||
########################################
|
||||
|
||||
include(../src/gcconfig.pri)
|
||||
|
||||
GC_SRC_DIR = ../../src
|
||||
GC_OBJECTS_DIR = $$GC_SRC_DIR/$(OBJECTS_DIR)
|
||||
INCLUDEPATH += $$GC_SRC_DIR
|
||||
win32 {
|
||||
PLATFORM_EXT = obj
|
||||
} else {
|
||||
PLATFORM_EXT = o
|
||||
}
|
||||
|
||||
CONFIG += testcase
|
||||
CONFIG += no_testcase_installs
|
||||
CONFIG += c++11
|
||||
|
||||
for(obj, GC_OBJS) {
|
||||
LIBS += $${GC_OBJECTS_DIR}/$${obj}.$${PLATFORM_EXT}
|
||||
}
|
||||
14
unittests/unittests.pro
Normal file
14
unittests/unittests.pro
Normal file
@@ -0,0 +1,14 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
exists(unittests.pri) {
|
||||
include(unittests.pri)
|
||||
}
|
||||
|
||||
equals(GC_UNITTESTS, active) {
|
||||
SUBDIRS += seasonOffset \
|
||||
season \
|
||||
seasonParser
|
||||
CONFIG += ordered
|
||||
} else {
|
||||
message("Unittests are disabled; to enable copy unittests/unittests.pri.in to unittests/unittests.pri")
|
||||
}
|
||||
Reference in New Issue
Block a user