Skip to content

Commit 4da4094

Browse files
committed
Add test cases for the new file logic
Its absolutely unhinged, woo!
1 parent 6d7fc27 commit 4da4094

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

BeluxPlugin/SidAllocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ bool SidAllocation::does_activation_match(const std::optional<TimeActivation>& r
267267
}
268268

269269
const auto zoned_now = chrono::zoned_time{ dest_zone, now };
270-
const auto ymw = chrono::year_month_weekday{ chrono::floor<chrono::days>(zoned_now.get_sys_time()) };
271-
const auto time = chrono::hh_mm_ss(zoned_now.get_sys_time() - chrono::floor<chrono::days>(zoned_now.get_sys_time()));
270+
const auto ymw = chrono::year_month_weekday{ chrono::floor<chrono::days>(zoned_now.get_local_time()) };
271+
const auto time = chrono::hh_mm_ss(zoned_now.get_local_time() - chrono::floor<chrono::days>(zoned_now.get_local_time()));
272272
const auto hours = time.hours().count();
273273
const auto minutes = time.minutes().count();
274274

BeluxPluginTest/BeluxPluginTest.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string>
66
#include <chrono>
77

8+
89
using namespace std::chrono;
910

1011
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
@@ -166,12 +167,60 @@ namespace BeluxPluginTest
166167
Assert::AreEqual(std::string("LNO7E"), maybe_sid->sid);
167168
}
168169

169-
TEST_METHOD(RespectsTiemZones)
170+
TEST_METHOD(RespectsTimeZonesPositive)
170171
{
172+
// DENUT7N gets assigned for RWY19, if between 2345 and 0344L, or 25R is not active.
173+
// We will test with 25R active of course
174+
175+
const auto allocator = get_filled_allocator();
176+
177+
// This is local. October 1st is winter time, so at 01:05L it should be active. This is 2305Z, so not active if incorrectly converted.
178+
tm fake_now{};
179+
fake_now.tm_mday = 2;
180+
fake_now.tm_mon = 9; // October, somehow
181+
fake_now.tm_year = 2023 - 1900;
182+
fake_now.tm_hour = 1;
183+
fake_now.tm_min = 5;
184+
fake_now.tm_isdst = -1;
185+
const time_t epoch = mktime(&fake_now);
186+
Assert::IsTrue(epoch > 0);
187+
const auto clock = system_clock::from_time_t(epoch);
188+
189+
const LaraParser parser = get_filled_lara();
190+
const auto active = parser.get_active(fake_now);
191+
192+
const auto maybe_sid = allocator.find("EBBR", "DENUT", "EDDF", 2, "19", clock, active, std::vector<std::string>{"25R"});
193+
Assert::IsTrue(maybe_sid.has_value());
194+
Assert::AreEqual(std::string("DENUT7N"), maybe_sid->sid);
171195
}
172196

173-
TEST_METHOD(RespectsDisallowedRunways)
197+
TEST_METHOD(RespectsTimeZonesNegative)
174198
{
199+
// DENUT7N gets assigned for RWY19, if between 2345 and 0344L, or 25R is not active.
200+
// We will test with 25R active of course
201+
// This also tests that it respects the 25R being disallowed, otherwise we'd get that
202+
// Instead we select DENUT1F, which is F-ictional
203+
204+
const auto allocator = get_filled_allocator();
205+
206+
// This is local. October 1st is winter time, so at 03:50L it should not be active. This is 0150Z, so active if incorrectly converted.
207+
tm fake_now{};
208+
fake_now.tm_mday = 2;
209+
fake_now.tm_mon = 9; // October, somehow
210+
fake_now.tm_year = 2023 - 1900;
211+
fake_now.tm_hour = 3;
212+
fake_now.tm_min = 50;
213+
fake_now.tm_isdst = -1;
214+
const time_t epoch = mktime(&fake_now);
215+
Assert::IsTrue(epoch > 0);
216+
const auto clock = system_clock::from_time_t(epoch);
217+
218+
const LaraParser parser = get_filled_lara();
219+
const auto active = parser.get_active(fake_now);
220+
221+
const auto maybe_sid = allocator.find("EBBR", "DENUT", "EDDF", 2, "19", clock, active, std::vector<std::string>{"25R"});
222+
Assert::IsTrue(maybe_sid.has_value());
223+
Assert::AreNotEqual(std::string("DENUT7N"), maybe_sid->sid);
175224
}
176225
};
177226
}

BeluxPluginTest/res/SID_ALLOCATION.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CIV | |1| | |CIV2L | EBBR | 19 | F060 | |
4141
DENUT| |1| 0345 | 2044 |DENUT8L| EBBR | 19 | F060 | | | | 19
4242
DENUT| |1| 2245L | 0344L |DENUT7N| EBBR | 19 | F060 | | | | 19
4343
DENUT| |1| | |DENUT7N| EBBR | 19 | F060 | | | 25R | 19
44+
DENUT| |1| | |DENUT1F| EBBR | 19 | F060 | | | | FICTIONAL
4445
ELSIK| |1| | |ELSIK2L| EBBR | 19 | F060 | | EBTRANA EBTRANB | | 19
4546
HELEN| |1| 0345 | 2044 |HELEN6L| EBBR | 19 | F060 | | | | 19
4647
HELEN| |1| 2045 | 0344 |HELEN6N| EBBR | 19 | F060 | | | | 19

0 commit comments

Comments
 (0)