Debian Codegraph @

unittests/Core/season/testSeason.cpp

raw
1 #include "Core/Season.h"
2
3 #include <QTest>
4
5
6 class TestSeason: public QObject
7 {
8 Q_OBJECT
9
10 public:
11 TestSeason(): reference(2024, 8, 20) {
12 }
13
14 private slots:
15 void builtInAllDates() {
16 Season season;
17 season.setName("All Dates");
18 season.setOffsetAndLength(-50, 1, 1, 100, 0, 0);
19 QCOMPARE(season.getStart(reference), QDate(1974, 1, 1));
20 QCOMPARE(season.getEnd(reference), QDate(2073, 12, 31));
21 }
22
23 void builtInThisYear() {
24 Season season;
25 season.setName("This Year");
26 season.setOffsetAndLength(0, 1, 1, 1, 0, 0);
27 QCOMPARE(season.getStart(reference), QDate(2024, 1, 1));
28 QCOMPARE(season.getEnd(reference), QDate(2024, 12, 31));
29 }
30
31 void builtInThisMonth() {
32 Season season;
33 season.setName("This Month");
34 season.setOffsetAndLength(1, 0, 1, 0, 1, 0);
35 QCOMPARE(season.getStart(reference), QDate(2024, 8, 1));
36 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 31));
37 }
38
39 void builtInLastMonth() {
40 Season season;
41 season.setName("Last Month");
42 season.setOffsetAndLength(1, -1, 1, 0, 1, 0);
43 QCOMPARE(season.getStart(reference), QDate(2024, 7, 1));
44 QCOMPARE(season.getEnd(reference), QDate(2024, 7, 31));
45 }
46
47 void builtInThisWeek() {
48 Season season;
49 season.setName("This Week");
50 season.setOffsetAndLength(1, 1, 0, 0, 0, 7);
51 QCOMPARE(season.getStart(reference), QDate(2024, 8, 19));
52 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 25));
53 }
54
55 void builtInLastWeek() {
56 Season season;
57 season.setName("Last Week");
58 season.setOffsetAndLength(1, 1, -1, 0, 0, 7);
59 QCOMPARE(season.getStart(reference), QDate(2024, 8, 12));
60 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 18));
61 }
62
63 void builtInLast24Hours() {
64 Season season;
65 season.setName("Last 24 hours");
66 season.setLengthOnly(0, 0, 2);
67 QCOMPARE(season.getStart(reference), QDate(2024, 8, 19));
68 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
69 }
70
71 void builtInLast7Days() {
72 Season season;
73 season.setName("Last 7 days");
74 season.setLengthOnly(0, 0, 7);
75 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
76 }
77
78 void builtInLast14Days() {
79 Season season;
80 season.setName("Last 14 days");
81 season.setLengthOnly(0, 0, 14);
82 QCOMPARE(season.getStart(reference), QDate(2024, 8, 7));
83 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
84 }
85
86 void builtInLast21Days() {
87 Season season;
88 season.setName("Last 21 days");
89 season.setLengthOnly(0, 0, 21);
90 QCOMPARE(season.getStart(reference), QDate(2024, 7, 31));
91 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
92 }
93
94 void builtInLast28Days() {
95 Season season;
96 season.setName("Last 28 days");
97 season.setLengthOnly(0, 0, 28);
98 QCOMPARE(season.getStart(reference), QDate(2024, 7, 24));
99 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
100 }
101
102 void builtInLast6Weeks() {
103 Season season;
104 season.setName("Last 6 weeks");
105 season.setLengthOnly(0, 0, 42);
106 QCOMPARE(season.getStart(reference), QDate(2024, 7, 10));
107 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
108 }
109
110 void builtInLast2Months() {
111 Season season;
112 season.setName("Last 2 months");
113 season.setLengthOnly(0, 2, 0);
114 QCOMPARE(season.getStart(reference), QDate(2024, 6, 21));
115 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
116 }
117
118 void builtInLast3Months() {
119 Season season;
120 season.setName("Last 3 months");
121 season.setLengthOnly(0, 3, 0);
122 QCOMPARE(season.getStart(reference), QDate(2024, 5, 21));
123 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
124 }
125
126 void builtInLast6Months() {
127 Season season;
128 season.setName("Last 6 months");
129 season.setLengthOnly(0, 6, 0);
130 QCOMPARE(season.getStart(reference), QDate(2024, 2, 21));
131 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
132 }
133
134 void builtInLast12Months() {
135 Season season;
136 season.setName("Last 12 months");
137 season.setLengthOnly(1, 0, 0);
138 QCOMPARE(season.getStart(reference), QDate(2023, 8, 21));
139 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
140 }
141
142 void absStartAbsEnd() {
143 Season season;
144 season.setAbsoluteStart(QDate(2022, 4, 8));
145 season.setAbsoluteEnd(QDate(2023, 3, 7));
146 QCOMPARE(season.getStart(reference), QDate(2022, 4, 8));
147 QCOMPARE(season.getEnd(reference), QDate(2023, 3, 7));
148 }
149
150 void absStartRelEnd() {
151 Season season;
152 season.setAbsoluteStart(QDate(2022, 4, 8));
153 season.setOffsetEnd(1, -5, 1, false);
154 QCOMPARE(season.getStart(reference), QDate(2022, 4, 8));
155 QCOMPARE(season.getEnd(reference), QDate(2024, 3, 20));
156 }
157
158 void absStartDurationAfter() {
159 Season season;
160 season.setAbsoluteStart(QDate(2022, 4, 8));
161 season.setLength(0, 2, 0);
162 QCOMPARE(season.getStart(reference), QDate(2022, 4, 8));
163 QCOMPARE(season.getEnd(reference), QDate(2022, 6, 7));
164 }
165
166 void absStartYtd() {
167 Season season;
168 season.setAbsoluteStart(QDate(2022, 4, 8));
169 season.setYtd();
170 QCOMPARE(season.getStart(reference), QDate(2022, 4, 8));
171 QCOMPARE(season.getEnd(reference), QDate(2022, 8, 20));
172 }
173
174 void absStartYtdOverflow() {
175 Season season;
176 season.setAbsoluteStart(QDate(2022, 9, 8));
177 season.setYtd();
178 QCOMPARE(season.getStart(reference), QDate(2022, 9, 8));
179 QCOMPARE(season.getEnd(reference), QDate(2023, 8, 20));
180 }
181
182 void relStartAbsEnd() {
183 Season season;
184 season.setOffsetStart(-5, 1, 1, false);
185 season.setAbsoluteEnd(QDate(2023, 3, 7));
186 QCOMPARE(season.getStart(reference), QDate(2019, 8, 20));
187 QCOMPARE(season.getEnd(reference), QDate(2023, 3, 7));
188 }
189
190 void relStartRelEndYear() {
191 Season season;
192 season.setOffsetStart(-2, 1, 1, false);
193 season.setOffsetEnd(-1, 1, 1, false);
194 QCOMPARE(season.getStart(reference), QDate(2022, 8, 20));
195 QCOMPARE(season.getEnd(reference), QDate(2023, 8, 20));
196 }
197
198 void relStartRelEndMonthDay() {
199 Season season;
200 season.setOffsetStart(1, -5, 1, false);
201 season.setOffsetEnd(1, 1, -5, false);
202 QCOMPARE(season.getStart(reference), QDate(2024, 3, 20));
203 QCOMPARE(season.getEnd(reference), QDate(2024, 7, 16));
204 }
205
206 void relStartDurationAfter() {
207 Season season;
208 season.setOffsetStart(1, -5, 1, false);
209 season.setLength(0, 2, 0);
210 QCOMPARE(season.getStart(reference), QDate(2024, 3, 20));
211 QCOMPARE(season.getEnd(reference), QDate(2024, 5, 19));
212 }
213
214 void relStartYtd() {
215 Season season;
216 season.setOffsetStart(1, -2, 1, false);
217 season.setYtd();
218 QCOMPARE(season.getStart(reference), QDate(2024, 6, 20));
219 QCOMPARE(season.getEnd(reference), QDate(2024, 8, 20));
220 }
221
222 void relStartYtdOverflow() {
223 Season season;
224 season.setOffsetStart(1, -21, 1, false);
225 season.setYtd();
226 QCOMPARE(season.getStart(reference), QDate(2022, 11, 20));
227 QCOMPARE(season.getEnd(reference), QDate(2023, 8, 20));
228 }
229
230 void durationBeforeAbsEnd() {
231 Season season;
232 season.setAbsoluteEnd(QDate(2023, 3, 7));
233 season.setLength(0, 2, 0);
234 QCOMPARE(season.getStart(reference), QDate(2023, 1, 8));
235 QCOMPARE(season.getEnd(reference), QDate(2023, 3, 7));
236 }
237
238 void durationBeforeRelEnd() {
239 Season season;
240 season.setOffsetEnd(1, -5, 1, false);
241 season.setLength(0, 2, 0);
242 QCOMPARE(season.getStart(reference), QDate(2024, 1, 21));
243 QCOMPARE(season.getEnd(reference), QDate(2024, 3, 20));
244 }
245
246 void isAbsolute() {
247 Season season;
248
249 season.setOffsetEnd(1, -5, 1, false);
250 season.setLength(0, 2, 0);
251 QCOMPARE(season.isAbsolute(), false);
252
253 season.resetTimeRange();
254 season.setAbsoluteStart(QDate(2024, 1, 1));
255 season.setYtd();
256 QCOMPARE(season.isAbsolute(), false);
257
258 season.resetTimeRange();
259 season.setAbsoluteStart(QDate(2024, 1, 1));
260 season.setAbsoluteEnd(QDate(2024, 2, 3));
261 QCOMPARE(season.isAbsolute(), true);
262
263 season.resetTimeRange();
264 season.setAbsoluteStart(QDate(2024, 1, 1));
265 season.setLength(0, 2, 0);
266 QCOMPARE(season.isAbsolute(), true);
267
268 season.resetTimeRange();
269 season.setLength(0, 2, 0);
270 season.setAbsoluteEnd(QDate(2024, 1, 1));
271 QCOMPARE(season.isAbsolute(), true);
272 }
273
274 private:
275 const QDate reference;
276 };
277
278
279 QTEST_MAIN(TestSeason)
280 #include "testSeason.moc"