mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-20 18:23:51 +00:00
[routing] Enable access conditional.
Signed-off-by: Viktor Govako <viktor.govako@gmail.com> (cherry picked from commit 6a2f2662b334345dc8789e970f358cec3ed69c85)
This commit is contained in:
committed by
Konstantin Pastbin
parent
3352fc13c1
commit
ffcb694961
@@ -853,18 +853,17 @@ void EditableMapObject::LogDiffInJournal(EditableMapObject const & unedited_emo)
|
||||
LOG(LDEBUG, ("Executing LogDiffInJournal"));
|
||||
|
||||
// Name
|
||||
for (StringUtf8Multilang::Lang language : StringUtf8Multilang::GetSupportedLanguages())
|
||||
for (auto const & language : StringUtf8Multilang::GetSupportedLanguages())
|
||||
{
|
||||
int8_t langCode = StringUtf8Multilang::GetLangIndex(language.m_code);
|
||||
std::string_view new_name;
|
||||
std::string_view old_name;
|
||||
m_name.GetString(langCode, new_name);
|
||||
unedited_emo.GetNameMultilang().GetString(langCode, old_name);
|
||||
int8_t const langCode = StringUtf8Multilang::GetLangIndex(language.m_code);
|
||||
std::string_view new_name, old_name;
|
||||
UNUSED_VALUE(m_name.GetString(langCode, new_name));
|
||||
UNUSED_VALUE(unedited_emo.GetNameMultilang().GetString(langCode, old_name));
|
||||
|
||||
if (new_name != old_name)
|
||||
{
|
||||
std::string osmLangName = StringUtf8Multilang::GetOSMTagByCode(langCode);
|
||||
m_journal.AddTagChange(std::move(osmLangName), std::string(old_name), std::string(new_name));
|
||||
m_journal.AddTagChange(StringUtf8Multilang::GetOSMTagByCode(langCode), std::string(old_name),
|
||||
std::string(new_name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ project(platform_tests_support)
|
||||
|
||||
set(SRC
|
||||
async_gui_thread.hpp
|
||||
helpers.cpp
|
||||
helpers.hpp
|
||||
scoped_dir.cpp
|
||||
scoped_dir.hpp
|
||||
|
||||
45
libs/platform/platform_tests_support/helpers.cpp
Normal file
45
libs/platform/platform_tests_support/helpers.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "helpers.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace platform::tests_support
|
||||
{
|
||||
time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t hours, uint8_t minutes)
|
||||
{
|
||||
std::tm t{};
|
||||
t.tm_year = year - 1900;
|
||||
t.tm_mon = static_cast<int>(month) - 1;
|
||||
t.tm_mday = monthDay;
|
||||
t.tm_hour = hours;
|
||||
t.tm_min = minutes;
|
||||
return std::mktime(&t);
|
||||
}
|
||||
|
||||
time_t GetUnixtimeByWeekday(uint16_t year, Month month, Weekday weekday, uint8_t hours, uint8_t minutes)
|
||||
{
|
||||
int monthDay = 1;
|
||||
auto createUnixtime = [&]()
|
||||
{
|
||||
std::tm t{};
|
||||
t.tm_year = year - 1900;
|
||||
t.tm_mon = static_cast<int>(month) - 1;
|
||||
t.tm_mday = monthDay;
|
||||
t.tm_wday = static_cast<int>(weekday) - 1;
|
||||
t.tm_hour = hours;
|
||||
t.tm_min = minutes;
|
||||
return std::mktime(&t);
|
||||
};
|
||||
|
||||
for (; monthDay < 32; ++monthDay)
|
||||
{
|
||||
auto const unixtime = createUnixtime();
|
||||
auto const timeOut = std::localtime(&unixtime);
|
||||
if (timeOut->tm_wday == static_cast<int>(weekday) - 1)
|
||||
return unixtime;
|
||||
}
|
||||
|
||||
UNREACHABLE();
|
||||
}
|
||||
} // namespace platform::tests_support
|
||||
@@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "3party/opening_hours/opening_hours.hpp"
|
||||
|
||||
#if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX)
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
namespace platform
|
||||
{
|
||||
namespace tests_support
|
||||
#include <cstdint>
|
||||
|
||||
namespace platform::tests_support
|
||||
{
|
||||
inline void ChangeMaxNumberOfOpenFiles(size_t n)
|
||||
{
|
||||
@@ -17,5 +19,10 @@ inline void ChangeMaxNumberOfOpenFiles(size_t n)
|
||||
setrlimit(RLIMIT_NOFILE, &rlp);
|
||||
#endif
|
||||
}
|
||||
} // namespace tests_support
|
||||
} // namespace platform
|
||||
|
||||
using Month = osmoh::MonthDay::Month;
|
||||
using Weekday = osmoh::Weekday;
|
||||
|
||||
time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t hours, uint8_t minutes);
|
||||
time_t GetUnixtimeByWeekday(uint16_t year, Month month, Weekday weekday, uint8_t hours, uint8_t minutes);
|
||||
} // namespace platform::tests_support
|
||||
|
||||
@@ -30,8 +30,8 @@ class IndexGraphLoaderImpl final : public IndexGraphLoader
|
||||
public:
|
||||
IndexGraphLoaderImpl(VehicleType vehicleType, bool loadAltitudes,
|
||||
shared_ptr<VehicleModelFactoryInterface> vehicleModelFactory,
|
||||
shared_ptr<EdgeEstimator> estimator, MwmDataSource & dataSource,
|
||||
RoutingOptions routingOptions = RoutingOptions())
|
||||
shared_ptr<EdgeEstimator> estimator, MwmDataSource & dataSource, RoutingOptions routingOptions,
|
||||
TimeGetterT timeGetter)
|
||||
: m_vehicleType(vehicleType)
|
||||
, m_loadAltitudes(loadAltitudes)
|
||||
, m_dataSource(dataSource)
|
||||
@@ -41,6 +41,9 @@ public:
|
||||
{
|
||||
CHECK(m_vehicleModelFactory, ());
|
||||
CHECK(m_estimator, ());
|
||||
|
||||
if (timeGetter)
|
||||
m_currentTimeGetter = std::move(timeGetter);
|
||||
}
|
||||
|
||||
// IndexGraphLoader overrides:
|
||||
@@ -249,10 +252,10 @@ bool ReadRoadPenaltyFromMwm(MwmValue const & mwmValue, VehicleType vehicleType,
|
||||
unique_ptr<IndexGraphLoader> IndexGraphLoader::Create(VehicleType vehicleType, bool loadAltitudes,
|
||||
shared_ptr<VehicleModelFactoryInterface> vehicleModelFactory,
|
||||
shared_ptr<EdgeEstimator> estimator, MwmDataSource & dataSource,
|
||||
RoutingOptions routingOptions)
|
||||
RoutingOptions routingOptions, TimeGetterT timeGetter)
|
||||
{
|
||||
return make_unique<IndexGraphLoaderImpl>(vehicleType, loadAltitudes, vehicleModelFactory, estimator, dataSource,
|
||||
routingOptions);
|
||||
routingOptions, std::move(timeGetter));
|
||||
}
|
||||
|
||||
void DeserializeIndexGraph(MwmValue const & mwmValue, VehicleType vehicleType, IndexGraph & graph)
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
static std::unique_ptr<IndexGraphLoader> Create(VehicleType vehicleType, bool loadAltitudes,
|
||||
std::shared_ptr<VehicleModelFactoryInterface> vehicleModelFactory,
|
||||
std::shared_ptr<EdgeEstimator> estimator, MwmDataSource & dataSource,
|
||||
RoutingOptions routingOptions = RoutingOptions());
|
||||
RoutingOptions routingOptions = {}, TimeGetterT timeGetter = {});
|
||||
};
|
||||
|
||||
void DeserializeIndexGraph(MwmValue const & mwmValue, VehicleType vehicleType, IndexGraph & graph);
|
||||
|
||||
@@ -1073,9 +1073,9 @@ unique_ptr<WorldGraph> IndexRouter::MakeWorldGraph()
|
||||
m_numMwmIds, m_numMwmTree, m_vehicleType == VehicleType::Transit ? VehicleType::Pedestrian : m_vehicleType,
|
||||
m_countryRectFn, m_dataSource);
|
||||
|
||||
auto indexGraphLoader =
|
||||
IndexGraphLoader::Create(m_vehicleType == VehicleType::Transit ? VehicleType::Pedestrian : m_vehicleType,
|
||||
m_loadAltitudes, m_vehicleModelFactory, m_estimator, m_dataSource, routingOptions);
|
||||
auto indexGraphLoader = IndexGraphLoader::Create(
|
||||
m_vehicleType == VehicleType::Transit ? VehicleType::Pedestrian : m_vehicleType, m_loadAltitudes,
|
||||
m_vehicleModelFactory, m_estimator, m_dataSource, routingOptions, m_currentTimeGetter);
|
||||
|
||||
if (m_vehicleType != VehicleType::Transit)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "geometry/point2d.hpp"
|
||||
#include "geometry/tree4d.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -90,6 +89,12 @@ public:
|
||||
|
||||
VehicleType GetVehicleType() const { return m_vehicleType; }
|
||||
|
||||
template <class T>
|
||||
void SetCurrentTimeGetter(T && getter)
|
||||
{
|
||||
m_currentTimeGetter = std::forward<T>(getter);
|
||||
}
|
||||
|
||||
private:
|
||||
RouterResultCode CalculateSubrouteJointsMode(IndexGraphStarter & starter, RouterDelegate const & delegate,
|
||||
std::shared_ptr<AStarProgress> const & progress,
|
||||
@@ -282,5 +287,7 @@ private:
|
||||
GuidesConnections m_guides;
|
||||
|
||||
CountryParentNameGetterFn m_countryParentNameGetterFn;
|
||||
|
||||
TimeGetterT m_currentTimeGetter;
|
||||
};
|
||||
} // namespace routing
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "coding/writer.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/scope_guard.hpp"
|
||||
#include "base/stl_helpers.hpp"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "coding/bit_streams.hpp"
|
||||
#include "coding/varint.hpp"
|
||||
|
||||
#include "base/checked_cast.hpp"
|
||||
#include "base/stl_helpers.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "3party/opening_hours/opening_hours.hpp"
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
#include "routing_common/num_mwm_id.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include "coding/bit_streams.hpp"
|
||||
#include "coding/reader.hpp"
|
||||
#include "coding/varint.hpp"
|
||||
@@ -64,13 +62,7 @@ public:
|
||||
case Header::WithoutAccessConditional: DeserializeAccess(src, vehicleType, roadAccess); break;
|
||||
case Header::WithAccessConditional:
|
||||
DeserializeAccess(src, vehicleType, roadAccess);
|
||||
|
||||
/// @todo By VNG: WTF?
|
||||
// access:conditional should be switch off for release 10.0 and probably for the next one.
|
||||
// It means that they should be switch off for cross_mwm section generation and for runtime.
|
||||
// To switch on access:conditional the line below should be uncommented.
|
||||
// Also tests in routing/routing_tests/road_access_test.cpp should be uncommented.
|
||||
// DeserializeAccessConditional(src, vehicleType, roadAccess);
|
||||
DeserializeAccessConditional(src, vehicleType, roadAccess);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ set(SRC
|
||||
omim_add_test(${PROJECT_NAME} ${SRC} REQUIRE_SERVER)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
platform_tests_support
|
||||
tracking
|
||||
routing
|
||||
map
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "routing/routing_integration_tests/routing_test_tools.hpp"
|
||||
|
||||
#include "platform/platform_tests_support/helpers.hpp"
|
||||
|
||||
#include "geometry/mercator.hpp"
|
||||
|
||||
namespace pedestrian_route_test
|
||||
@@ -277,11 +279,24 @@ UNIT_TEST(RussiaSaintPetersburgMoyka93ToMarsovoPole)
|
||||
mercator::FromLatLon(59.9436, 30.3318), 2755);
|
||||
}
|
||||
|
||||
UNIT_TEST(RussiaSaintPetersburgMoyka93ToAvrora)
|
||||
// Good test to check access:conditional (through bridges)
|
||||
UNIT_TEST(Russia_SaintPetersburg_Bridge_Access_Conditional)
|
||||
{
|
||||
integration::CalculateRouteAndTestRouteLength(integration::GetVehicleComponents(VehicleType::Pedestrian),
|
||||
mercator::FromLatLon(59.9241, 30.323), {0., 0.},
|
||||
mercator::FromLatLon(59.9554, 30.3378), 4614.66);
|
||||
using namespace platform::tests_support;
|
||||
|
||||
auto const from = mercator::FromLatLon(59.9241, 30.323);
|
||||
auto const to = mercator::FromLatLon(59.9556857, 30.33764);
|
||||
|
||||
auto components = CreateAllMapsComponents(VehicleType::Pedestrian, {});
|
||||
time_t currentTime;
|
||||
components->SetCurrentTimeGetter([¤tTime] { return currentTime; });
|
||||
|
||||
currentTime = GetUnixtimeByDate(2025, Month::Oct, 27, 12, 00);
|
||||
integration::CalculateRouteAndTestRouteLength(*components, from, {0., 0.}, to, 4655.73);
|
||||
|
||||
// no @ (Apr-Nov 01:20-04:50)
|
||||
currentTime = GetUnixtimeByDate(2025, Month::Oct, 27, 03, 00);
|
||||
integration::CalculateRouteAndTestRouteLength(*components, from, {0., 0.}, to, 7051.32);
|
||||
}
|
||||
|
||||
UNIT_TEST(RussiaSaintPetersburgPetrPaulChurchToDolphins)
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "routing/routing_integration_tests/routing_test_tools.hpp"
|
||||
|
||||
#include "platform/platform_tests_support/helpers.hpp"
|
||||
|
||||
#include "geometry/mercator.hpp"
|
||||
|
||||
#include <limits>
|
||||
@@ -915,4 +917,48 @@ UNIT_TEST(Germany_Avoid_Agricultural)
|
||||
FromLatLon(47.6580109, 11.0432625), 1096.11);
|
||||
}
|
||||
|
||||
// https://github.com/organicmaps/organicmaps/issues/3731
|
||||
/* Not valid mapping, should be:
|
||||
* motor_vehicle = no
|
||||
* motor_vehicle:conditional = yes @ (23:00-11:00)
|
||||
UNIT_TEST(Turkey_MotorVehicle_Conditional_Yes)
|
||||
{
|
||||
using namespace platform::tests_support;
|
||||
|
||||
auto const from = FromLatLon(41.0588601, 28.9133974);
|
||||
auto const to = FromLatLon(41.0641461, 28.9144856);
|
||||
|
||||
auto components = CreateAllMapsComponents(VehicleType::Car, {});
|
||||
time_t currentTime;
|
||||
components->SetCurrentTimeGetter([¤tTime] { return currentTime; });
|
||||
|
||||
currentTime = GetUnixtimeByDate(2025, Month::Oct, 28, 00, 05);
|
||||
CalculateRouteAndTestRouteLength(*components, from, {0., 0.}, to, 607);
|
||||
|
||||
currentTime = GetUnixtimeByDate(2025, Month::Oct, 27, 12, 00);
|
||||
CalculateRouteAndTestRouteLength(*components, from, {0., 0.}, to, 726);
|
||||
}
|
||||
*/
|
||||
|
||||
// https://github.com/organicmaps/organicmaps/issues/5280
|
||||
UNIT_TEST(Colombia_MotorVehicle_Conditional_No)
|
||||
{
|
||||
using namespace platform::tests_support;
|
||||
|
||||
auto const from = FromLatLon(4.70915, -74.06130);
|
||||
auto const to = FromLatLon(4.70001, -74.07174);
|
||||
|
||||
auto components = CreateAllMapsComponents(VehicleType::Car, {});
|
||||
time_t currentTime;
|
||||
components->SetCurrentTimeGetter([¤tTime] { return currentTime; });
|
||||
|
||||
currentTime = GetUnixtimeByWeekday(2025, Month::Oct, Weekday::Monday, 9, 30);
|
||||
CalculateRouteAndTestRouteLength(*components, from, {0., 0.}, to, 1959.77);
|
||||
|
||||
// Sunday
|
||||
// no @ (Su,PH 07:00-14:00)
|
||||
currentTime = GetUnixtimeByWeekday(2025, Month::Oct, Weekday::Sunday, 9, 30);
|
||||
CalculateRouteAndTestRouteLength(*components, from, {0., 0.}, to, 2803.13);
|
||||
}
|
||||
|
||||
} // namespace route_test
|
||||
|
||||
@@ -90,6 +90,12 @@ public:
|
||||
|
||||
IRouter & GetRouter() const override { return *m_indexRouter; }
|
||||
|
||||
template <class T>
|
||||
void SetCurrentTimeGetter(T && getter)
|
||||
{
|
||||
m_indexRouter->SetCurrentTimeGetter(std::forward<T>(getter));
|
||||
}
|
||||
|
||||
private:
|
||||
traffic::TrafficCache m_trafficCache;
|
||||
std::unique_ptr<IndexRouter> m_indexRouter;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "routing/base/routing_result.hpp"
|
||||
#include "routing/geometry.hpp"
|
||||
#include "routing/routing_helpers.hpp"
|
||||
#include "routing/transit_world_graph.hpp"
|
||||
|
||||
#include "transit/transit_version.hpp"
|
||||
|
||||
@@ -13,8 +14,6 @@
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "3party/opening_hours/opening_hours.hpp"
|
||||
|
||||
namespace routing_test
|
||||
{
|
||||
using namespace std;
|
||||
@@ -599,51 +598,10 @@ FakeEnding MakeFakeEnding(uint32_t featureId, uint32_t segmentIdx, m2::PointD co
|
||||
{
|
||||
return MakeFakeEnding({Segment(kTestNumMwmId, featureId, segmentIdx, true /* forward */)}, point, graph);
|
||||
}
|
||||
|
||||
unique_ptr<IndexGraphStarter> MakeStarter(FakeEnding const & start, FakeEnding const & finish, WorldGraph & graph)
|
||||
{
|
||||
return make_unique<IndexGraphStarter>(start, finish, 0 /* fakeNumerationStart */, false /* strictForward */, graph);
|
||||
}
|
||||
|
||||
time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t hours, uint8_t minutes)
|
||||
{
|
||||
std::tm t{};
|
||||
t.tm_year = year - 1900;
|
||||
t.tm_mon = static_cast<int>(month) - 1;
|
||||
t.tm_mday = monthDay;
|
||||
t.tm_hour = hours;
|
||||
t.tm_min = minutes;
|
||||
|
||||
time_t moment = mktime(&t);
|
||||
return moment;
|
||||
}
|
||||
|
||||
time_t GetUnixtimeByDate(uint16_t year, Month month, Weekday weekday, uint8_t hours, uint8_t minutes)
|
||||
{
|
||||
int monthDay = 1;
|
||||
auto createUnixtime = [&]()
|
||||
{
|
||||
std::tm t{};
|
||||
t.tm_year = year - 1900;
|
||||
t.tm_mon = static_cast<int>(month) - 1;
|
||||
t.tm_mday = monthDay;
|
||||
t.tm_wday = static_cast<int>(weekday) - 1;
|
||||
t.tm_hour = hours;
|
||||
t.tm_min = minutes;
|
||||
|
||||
return mktime(&t);
|
||||
};
|
||||
|
||||
int wday = -1;
|
||||
for (;;)
|
||||
{
|
||||
auto unixtime = createUnixtime();
|
||||
auto timeOut = localtime(&unixtime);
|
||||
wday = timeOut->tm_wday;
|
||||
if (wday == static_cast<int>(weekday) - 1)
|
||||
break;
|
||||
++monthDay;
|
||||
}
|
||||
|
||||
return createUnixtime();
|
||||
}
|
||||
} // namespace routing_test
|
||||
|
||||
@@ -10,17 +10,10 @@
|
||||
#include "routing/index_graph_starter.hpp"
|
||||
#include "routing/restrictions_serialization.hpp"
|
||||
#include "routing/road_access.hpp"
|
||||
#include "routing/road_point.hpp"
|
||||
#include "routing/route.hpp"
|
||||
#include "routing/segment.hpp"
|
||||
#include "routing/single_vehicle_world_graph.hpp"
|
||||
#include "routing/speed_camera_ser_des.hpp"
|
||||
#include "routing/transit_graph_loader.hpp"
|
||||
#include "routing/transit_world_graph.hpp"
|
||||
|
||||
#include "traffic/traffic_info.hpp"
|
||||
|
||||
#include "transit/transit_types.hpp"
|
||||
|
||||
#include "routing_common/num_mwm_id.hpp"
|
||||
|
||||
@@ -28,13 +21,9 @@
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace routing_test
|
||||
@@ -312,10 +301,4 @@ void TestTopologyGraph(TestIndexGraphTopology const & graph, TestIndexGraphTopol
|
||||
FakeEnding MakeFakeEnding(uint32_t featureId, uint32_t segmentIdx, m2::PointD const & point, WorldGraph & graph);
|
||||
|
||||
std::unique_ptr<IndexGraphStarter> MakeStarter(FakeEnding const & start, FakeEnding const & finish, WorldGraph & graph);
|
||||
|
||||
using Month = osmoh::MonthDay::Month;
|
||||
using Weekday = osmoh::Weekday;
|
||||
|
||||
time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t hours, uint8_t minutes);
|
||||
time_t GetUnixtimeByDate(uint16_t year, Month month, Weekday weekday, uint8_t hours, uint8_t minutes);
|
||||
} // namespace routing_test
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#include "testing/testing.hpp"
|
||||
|
||||
#include "routing/opening_hours_serdes.hpp"
|
||||
#include "routing/routing_tests/index_graph_tools.hpp"
|
||||
|
||||
#include "platform/platform_tests_support/helpers.hpp"
|
||||
|
||||
#include "coding/bit_streams.hpp"
|
||||
#include "coding/reader.hpp"
|
||||
#include "coding/writer.hpp"
|
||||
|
||||
#include "base/string_utils.hpp"
|
||||
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -17,7 +16,7 @@
|
||||
namespace opening_hours_serdes_tests
|
||||
{
|
||||
using namespace routing;
|
||||
using namespace routing_test;
|
||||
using namespace platform::tests_support;
|
||||
|
||||
using Buffer = std::vector<uint8_t>;
|
||||
|
||||
@@ -315,8 +314,8 @@ UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_Off_SerDes_1_AndUsage)
|
||||
TestWeekday(rule, Weekday::Monday, Weekday::None);
|
||||
TestModifier(rule, osmoh::RuleSequence::Modifier::Closed);
|
||||
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Thursday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByDate(2020, Month::Feb, Weekday::Monday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Thursday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Monday, 17 /* hh */, 30 /* mm */)), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_Off_SerDes_2)
|
||||
@@ -416,11 +415,11 @@ UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_TimeIsOver00)
|
||||
auto oh = Deserialize();
|
||||
TEST_EQUAL(oh.GetRule().size(), 1, ());
|
||||
|
||||
TEST(!oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Monday, 13 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Monday, 19 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Monday, 22 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Tuesday, 02 /* hh */, 30 /* mm */)), ());
|
||||
TEST(!oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Tuesday, 06 /* hh */, 30 /* mm */)), ());
|
||||
TEST(!oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Monday, 13 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Monday, 19 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Monday, 22 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Tuesday, 02 /* hh */, 30 /* mm */)), ());
|
||||
TEST(!oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Tuesday, 06 /* hh */, 30 /* mm */)), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_DefaultOpen)
|
||||
@@ -437,8 +436,8 @@ UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_DefaultOpen)
|
||||
auto const & rule = oh.GetRule().back();
|
||||
TestWeekday(rule, Weekday::Monday, Weekday::Saturday);
|
||||
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Monday, 13 /* hh */, 30 /* mm */)), ());
|
||||
TEST(!oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Sunday, 13 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Monday, 13 /* hh */, 30 /* mm */)), ());
|
||||
TEST(!oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Sunday, 13 /* hh */, 30 /* mm */)), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_SkipRuleOldYear)
|
||||
@@ -474,12 +473,12 @@ UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_10_plus)
|
||||
TestWeekday(rule, Weekday::Friday, Weekday::None);
|
||||
TestTime(rule, 10, 0, 0, 0);
|
||||
|
||||
TEST(!oh.IsOpen(GetUnixtimeByDate(2020, Month::Mar, Weekday::Friday, 9 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Mar, Weekday::Friday, 10 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Mar, Weekday::Friday, 15 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Mar, Weekday::Friday, 20 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Mar, Weekday::Friday, 23 /* hh */, 30 /* mm */)), ());
|
||||
TEST(!oh.IsOpen(GetUnixtimeByDate(2020, Month::Mar, Weekday::Saturday, 00 /* hh */, 30 /* mm */)), ());
|
||||
TEST(!oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Mar, Weekday::Friday, 9 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Mar, Weekday::Friday, 10 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Mar, Weekday::Friday, 15 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Mar, Weekday::Friday, 20 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Mar, Weekday::Friday, 23 /* hh */, 30 /* mm */)), ());
|
||||
TEST(!oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Mar, Weekday::Saturday, 00 /* hh */, 30 /* mm */)), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_24_7)
|
||||
@@ -714,8 +713,8 @@ UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_Hours_Usage_1)
|
||||
|
||||
auto const oh = Deserialize();
|
||||
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Thursday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByDate(2020, Month::Feb, Weekday::Monday, 07 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Thursday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Monday, 07 /* hh */, 30 /* mm */)), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_Weekday_Usage_1)
|
||||
@@ -727,8 +726,8 @@ UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_Weekday_Usage_1)
|
||||
|
||||
auto const oh = Deserialize();
|
||||
|
||||
TEST(oh.IsClosed(GetUnixtimeByDate(2020, Month::Feb, Weekday::Thursday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Wednesday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Thursday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Wednesday, 17 /* hh */, 30 /* mm */)), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_Weekday_Usage_2)
|
||||
@@ -740,10 +739,10 @@ UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_Weekday_Usage_2)
|
||||
|
||||
auto const oh = Deserialize();
|
||||
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2020, Month::Feb, Weekday::Monday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByDate(2020, Month::Feb, Weekday::Thursday, 15 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByDate(2023, Month::Apr, Weekday::Saturday, 13 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByDate(2023, Month::Apr, Weekday::Saturday, 8 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Monday, 17 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByWeekday(2020, Month::Feb, Weekday::Thursday, 15 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsOpen(GetUnixtimeByWeekday(2023, Month::Apr, Weekday::Saturday, 13 /* hh */, 30 /* mm */)), ());
|
||||
TEST(oh.IsClosed(GetUnixtimeByWeekday(2023, Month::Apr, Weekday::Saturday, 8 /* hh */, 30 /* mm */)), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_Weekday_Usage_3)
|
||||
|
||||
@@ -5,20 +5,19 @@
|
||||
|
||||
#include "routing/routing_tests/index_graph_tools.hpp"
|
||||
|
||||
#include "platform/platform_tests_support/helpers.hpp"
|
||||
|
||||
#include "coding/reader.hpp"
|
||||
#include "coding/writer.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "3party/opening_hours/opening_hours.hpp"
|
||||
|
||||
namespace road_access_test
|
||||
{
|
||||
using namespace routing;
|
||||
using namespace routing_test;
|
||||
using namespace platform::tests_support;
|
||||
using namespace std;
|
||||
|
||||
using TestEdge = TestIndexGraphTopology::Edge;
|
||||
@@ -53,77 +52,64 @@ void FillRoadAccessBySample_2(RoadAccess & roadAccess)
|
||||
roadAccess.SetAccess(std::move(wayToAccess), std::move(pointToAccess));
|
||||
}
|
||||
|
||||
// void FillRoadAccessBySampleConditional_1(RoadAccess & roadAccess)
|
||||
//{
|
||||
// std::vector<std::string> const openingHoursStrings = {
|
||||
// "Mo-Su", "10:00-18:00", "Mo-Fr 10:00-14:00", "09:00-13:00", "Apr - May", "2010 - 2100"};
|
||||
//
|
||||
// std::vector<osmoh::OpeningHours> openingHours;
|
||||
// for (auto const & oh : openingHoursStrings)
|
||||
// {
|
||||
// openingHours.emplace_back(oh);
|
||||
// TEST(openingHours.back().IsValid(), ());
|
||||
// }
|
||||
//
|
||||
// RoadAccess::Conditional conditional_1;
|
||||
// conditional_1.Insert(RoadAccess::Type::No, std::move(openingHours[0]));
|
||||
// conditional_1.Insert(RoadAccess::Type::Private, std::move(openingHours[1]));
|
||||
//
|
||||
// RoadAccess::Conditional conditional_2;
|
||||
// conditional_2.Insert(RoadAccess::Type::Destination, std::move(openingHours[2]));
|
||||
//
|
||||
// RoadAccess::Conditional conditional_3;
|
||||
// conditional_3.Insert(RoadAccess::Type::No, std::move(openingHours[4]));
|
||||
// conditional_3.Insert(RoadAccess::Type::Destination, std::move(openingHours[3]));
|
||||
//
|
||||
// RoadAccess::Conditional conditional_4;
|
||||
// conditional_4.Insert(RoadAccess::Type::Destination, std::move(openingHours[5]));
|
||||
//
|
||||
// RoadAccess::WayToAccessConditional wayToAccessConditional = {{1 /* featureId */, conditional_1},
|
||||
// {2 /* featureId */, conditional_2}};
|
||||
//
|
||||
// RoadAccess::PointToAccessConditional pointToAccessConditional = {
|
||||
// {RoadPoint(3 /* featureId */, 0 /* pointId */), conditional_3},
|
||||
// {RoadPoint(4 /* featureId */, 7 /* pointId */), conditional_4}};
|
||||
//
|
||||
// roadAccess.SetAccessConditional(std::move(wayToAccessConditional), std::move(pointToAccessConditional));
|
||||
// }
|
||||
//
|
||||
// void FillRoadAccessBySampleConditional_2(RoadAccess & roadAccess)
|
||||
//{
|
||||
// std::vector<std::string> const openingHoursStrings = {
|
||||
// "Mo", "Apr-May 03:00-04:25", "Mo-Sa 12:00-13:00", "2010-2098", "Nov-Apr", "19:00-21:00"};
|
||||
//
|
||||
// std::vector<osmoh::OpeningHours> openingHours;
|
||||
// for (auto const & oh : openingHoursStrings)
|
||||
// {
|
||||
// openingHours.emplace_back(oh);
|
||||
// TEST(openingHours.back().IsValid(), (oh));
|
||||
// }
|
||||
//
|
||||
// RoadAccess::Conditional conditional_1;
|
||||
// conditional_1.Insert(RoadAccess::Type::Private, std::move(openingHours[0]));
|
||||
//
|
||||
// RoadAccess::Conditional conditional_2;
|
||||
// conditional_2.Insert(RoadAccess::Type::No, std::move(openingHours[1]));
|
||||
// conditional_2.Insert(RoadAccess::Type::Private, std::move(openingHours[2]));
|
||||
//
|
||||
// RoadAccess::Conditional conditional_3;
|
||||
// conditional_3.Insert(RoadAccess::Type::Destination, std::move(openingHours[3]));
|
||||
//
|
||||
// RoadAccess::Conditional conditional_4;
|
||||
// conditional_4.Insert(RoadAccess::Type::No, std::move(openingHours[4]));
|
||||
// conditional_4.Insert(RoadAccess::Type::No, std::move(openingHours[5]));
|
||||
//
|
||||
// RoadAccess::WayToAccessConditional wayToAccessConditional = {{1 /* featureId */, conditional_1},
|
||||
// {2 /* featureId */, conditional_2}};
|
||||
//
|
||||
// RoadAccess::PointToAccessConditional pointToAccessConditional = {
|
||||
// {RoadPoint(3 /* featureId */, 10 /* pointId */), conditional_3},
|
||||
// {RoadPoint(4 /* featureId */, 2 /* pointId */), conditional_4}};
|
||||
//
|
||||
// roadAccess.SetAccessConditional(std::move(wayToAccessConditional), std::move(pointToAccessConditional));
|
||||
// }
|
||||
osmoh::OpeningHours ToOH(std::string const & s)
|
||||
{
|
||||
osmoh::OpeningHours res(s);
|
||||
TEST(res.IsValid(), (s));
|
||||
return res;
|
||||
}
|
||||
|
||||
void FillRoadAccessBySampleConditional_1(RoadAccess & roadAccess)
|
||||
{
|
||||
RoadAccess::Conditional conditional_1;
|
||||
conditional_1.Insert(RoadAccess::Type::No, ToOH("Mo-Su"));
|
||||
conditional_1.Insert(RoadAccess::Type::Private, ToOH("10:00-18:00"));
|
||||
|
||||
RoadAccess::Conditional conditional_2;
|
||||
conditional_2.Insert(RoadAccess::Type::Destination, ToOH("Mo-Fr 10:00-14:00"));
|
||||
|
||||
RoadAccess::Conditional conditional_3;
|
||||
conditional_3.Insert(RoadAccess::Type::No, ToOH("Apr - May"));
|
||||
conditional_3.Insert(RoadAccess::Type::Destination, ToOH("09:00-13:00"));
|
||||
|
||||
RoadAccess::Conditional conditional_4;
|
||||
conditional_4.Insert(RoadAccess::Type::Destination, ToOH("2010 - 2100"));
|
||||
|
||||
RoadAccess::WayToAccessConditional wayToAccessConditional = {{1 /* featureId */, conditional_1},
|
||||
{2 /* featureId */, conditional_2}};
|
||||
|
||||
RoadAccess::PointToAccessConditional pointToAccessConditional = {
|
||||
{RoadPoint(3 /* featureId */, 0 /* pointId */), conditional_3},
|
||||
{RoadPoint(4 /* featureId */, 7 /* pointId */), conditional_4}};
|
||||
|
||||
roadAccess.SetAccessConditional(std::move(wayToAccessConditional), std::move(pointToAccessConditional));
|
||||
}
|
||||
|
||||
void FillRoadAccessBySampleConditional_2(RoadAccess & roadAccess)
|
||||
{
|
||||
RoadAccess::Conditional conditional_1;
|
||||
conditional_1.Insert(RoadAccess::Type::Private, ToOH("Mo"));
|
||||
|
||||
RoadAccess::Conditional conditional_2;
|
||||
conditional_2.Insert(RoadAccess::Type::No, ToOH("Apr-May 03:00-04:25"));
|
||||
conditional_2.Insert(RoadAccess::Type::Private, ToOH("Mo-Sa 12:00-13:00"));
|
||||
|
||||
RoadAccess::Conditional conditional_3;
|
||||
conditional_3.Insert(RoadAccess::Type::Destination, ToOH("2010-2098"));
|
||||
|
||||
RoadAccess::Conditional conditional_4;
|
||||
conditional_4.Insert(RoadAccess::Type::No, ToOH("Nov-Apr"));
|
||||
conditional_4.Insert(RoadAccess::Type::No, ToOH("19:00-21:00"));
|
||||
|
||||
RoadAccess::WayToAccessConditional wayToAccessConditional = {{1 /* featureId */, conditional_1},
|
||||
{2 /* featureId */, conditional_2}};
|
||||
|
||||
RoadAccess::PointToAccessConditional pointToAccessConditional = {
|
||||
{RoadPoint(3 /* featureId */, 10 /* pointId */), conditional_3},
|
||||
{RoadPoint(4 /* featureId */, 2 /* pointId */), conditional_4}};
|
||||
|
||||
roadAccess.SetAccessConditional(std::move(wayToAccessConditional), std::move(pointToAccessConditional));
|
||||
}
|
||||
|
||||
class RoadAccessSerDesTest
|
||||
{
|
||||
@@ -167,61 +153,58 @@ UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes)
|
||||
TestDeserialize(VehicleType::Pedestrian, roadAccessPedestrian);
|
||||
}
|
||||
|
||||
// @TODO Tests below and functions FillRoadAccessBySampleConditional_1 and
|
||||
// FillRoadAccessBySampleConditional_2 should be uncommented when access:conditional is
|
||||
// switched on.
|
||||
// UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_One_Vehicle)
|
||||
//{
|
||||
// auto constexpr kVehicleTypeCount = static_cast<size_t>(VehicleType::Count);
|
||||
// for (size_t vehicleTypeId = 0; vehicleTypeId < kVehicleTypeCount; ++vehicleTypeId)
|
||||
// {
|
||||
// RoadAccess roadAccess;
|
||||
// FillRoadAccessBySampleConditional_1(roadAccess);
|
||||
//
|
||||
// RoadAccessSerializer::RoadAccessByVehicleType roadAccessAllTypes;
|
||||
// roadAccessAllTypes[vehicleTypeId] = roadAccess;
|
||||
//
|
||||
// Serialize(roadAccessAllTypes);
|
||||
// TestDeserialize(static_cast<VehicleType>(vehicleTypeId), roadAccess);
|
||||
// ClearBuffer();
|
||||
// }
|
||||
//}
|
||||
//
|
||||
// UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_Several_Vehicles)
|
||||
//{
|
||||
// RoadAccess roadAccessCar;
|
||||
// FillRoadAccessBySampleConditional_1(roadAccessCar);
|
||||
//
|
||||
// RoadAccess roadAccessPedestrian;
|
||||
// FillRoadAccessBySampleConditional_2(roadAccessPedestrian);
|
||||
//
|
||||
// RoadAccessSerializer::RoadAccessByVehicleType roadAccessAllTypes;
|
||||
// roadAccessAllTypes[static_cast<size_t>(VehicleType::Car)] = roadAccessCar;
|
||||
// roadAccessAllTypes[static_cast<size_t>(VehicleType::Pedestrian)] = roadAccessPedestrian;
|
||||
//
|
||||
// Serialize(roadAccessAllTypes);
|
||||
// TestDeserialize(VehicleType::Car, roadAccessCar);
|
||||
// TestDeserialize(VehicleType::Pedestrian, roadAccessPedestrian);
|
||||
//}
|
||||
//
|
||||
// UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_Mixed_Several_Vehicles)
|
||||
//{
|
||||
// RoadAccess roadAccessCar;
|
||||
// FillRoadAccessBySampleConditional_1(roadAccessCar);
|
||||
// FillRoadAccessBySample_1(roadAccessCar);
|
||||
//
|
||||
// RoadAccess roadAccessPedestrian;
|
||||
// FillRoadAccessBySampleConditional_2(roadAccessPedestrian);
|
||||
// FillRoadAccessBySample_2(roadAccessPedestrian);
|
||||
//
|
||||
// RoadAccessSerializer::RoadAccessByVehicleType roadAccessAllTypes;
|
||||
// roadAccessAllTypes[static_cast<size_t>(VehicleType::Car)] = roadAccessCar;
|
||||
// roadAccessAllTypes[static_cast<size_t>(VehicleType::Pedestrian)] = roadAccessPedestrian;
|
||||
//
|
||||
// Serialize(roadAccessAllTypes);
|
||||
// TestDeserialize(VehicleType::Car, roadAccessCar);
|
||||
// TestDeserialize(VehicleType::Pedestrian, roadAccessPedestrian);
|
||||
//}
|
||||
UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_One_Vehicle)
|
||||
{
|
||||
auto constexpr kVehicleTypeCount = static_cast<size_t>(VehicleType::Count);
|
||||
for (size_t vehicleTypeId = 0; vehicleTypeId < kVehicleTypeCount; ++vehicleTypeId)
|
||||
{
|
||||
RoadAccess roadAccess;
|
||||
FillRoadAccessBySampleConditional_1(roadAccess);
|
||||
|
||||
RoadAccessSerializer::RoadAccessByVehicleType roadAccessAllTypes;
|
||||
roadAccessAllTypes[vehicleTypeId] = roadAccess;
|
||||
|
||||
Serialize(roadAccessAllTypes);
|
||||
TestDeserialize(static_cast<VehicleType>(vehicleTypeId), roadAccess);
|
||||
ClearBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_Several_Vehicles)
|
||||
{
|
||||
RoadAccess roadAccessCar;
|
||||
FillRoadAccessBySampleConditional_1(roadAccessCar);
|
||||
|
||||
RoadAccess roadAccessPedestrian;
|
||||
FillRoadAccessBySampleConditional_2(roadAccessPedestrian);
|
||||
|
||||
RoadAccessSerializer::RoadAccessByVehicleType roadAccessAllTypes;
|
||||
roadAccessAllTypes[static_cast<size_t>(VehicleType::Car)] = roadAccessCar;
|
||||
roadAccessAllTypes[static_cast<size_t>(VehicleType::Pedestrian)] = roadAccessPedestrian;
|
||||
|
||||
Serialize(roadAccessAllTypes);
|
||||
TestDeserialize(VehicleType::Car, roadAccessCar);
|
||||
TestDeserialize(VehicleType::Pedestrian, roadAccessPedestrian);
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_Mixed_Several_Vehicles)
|
||||
{
|
||||
RoadAccess roadAccessCar;
|
||||
FillRoadAccessBySampleConditional_1(roadAccessCar);
|
||||
FillRoadAccessBySample_1(roadAccessCar);
|
||||
|
||||
RoadAccess roadAccessPedestrian;
|
||||
FillRoadAccessBySampleConditional_2(roadAccessPedestrian);
|
||||
FillRoadAccessBySample_2(roadAccessPedestrian);
|
||||
|
||||
RoadAccessSerializer::RoadAccessByVehicleType roadAccessAllTypes;
|
||||
roadAccessAllTypes[static_cast<size_t>(VehicleType::Car)] = roadAccessCar;
|
||||
roadAccessAllTypes[static_cast<size_t>(VehicleType::Pedestrian)] = roadAccessPedestrian;
|
||||
|
||||
Serialize(roadAccessAllTypes);
|
||||
TestDeserialize(VehicleType::Car, roadAccessCar);
|
||||
TestDeserialize(VehicleType::Pedestrian, roadAccessPedestrian);
|
||||
}
|
||||
|
||||
UNIT_TEST(RoadAccess_WayBlocked)
|
||||
{
|
||||
@@ -423,7 +406,7 @@ UNIT_TEST(RoadAccess_WayBlockedAvoidConditional)
|
||||
graph.SetEdgeAccessConditional(0, 1, RoadAccess::Type::No, "Mo-Fr 10:00 - 19:00");
|
||||
|
||||
auto const mondayAlmostTenHours = []()
|
||||
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 50 /* mm */); };
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 50 /* mm */); };
|
||||
|
||||
// In this time we probably will able to pass 0->1 edge, but we are not sure, so we should avoid
|
||||
// such edges.
|
||||
@@ -441,7 +424,7 @@ UNIT_TEST(RoadAccess_WayBlockedAvoidConditional)
|
||||
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
|
||||
|
||||
auto const mondayTwelveHours = []()
|
||||
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 12 /* hh */, 00 /* mm */); };
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Apr, Weekday::Monday, 12 /* hh */, 00 /* mm */); };
|
||||
|
||||
// But if we sure that in this time edge: 0->1 will be blocked, we definitely should not pass
|
||||
// 0->1. In this case no way will be found.
|
||||
@@ -518,7 +501,8 @@ UNIT_TEST(RoadAccess_WayBlockedConditional_Yes_No)
|
||||
graph.SetEdgeAccessConditional(1, 2, RoadAccess::Type::No, "Mo-Fr");
|
||||
graph.SetEdgeAccessConditional(1, 2, RoadAccess::Type::Yes, "Sa-Su");
|
||||
|
||||
auto const tuesday = []() { return GetUnixtimeByDate(2020, Month::Apr, Weekday::Tuesday, 10 /* hh */, 00 /* mm */); };
|
||||
auto const tuesday = []()
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Apr, Weekday::Tuesday, 10 /* hh */, 00 /* mm */); };
|
||||
|
||||
// Way is blocked from Monday to Friday
|
||||
graph.SetCurrentTimeGetter(tuesday);
|
||||
@@ -527,7 +511,7 @@ UNIT_TEST(RoadAccess_WayBlockedConditional_Yes_No)
|
||||
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight, expectedEdges);
|
||||
|
||||
auto const saturday = []()
|
||||
{ return GetUnixtimeByDate(2020, Month::Nov, Weekday::Saturday, 10 /* hh */, 00 /* mm */); };
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Nov, Weekday::Saturday, 10 /* hh */, 00 /* mm */); };
|
||||
|
||||
// And open from Saturday to Sunday
|
||||
graph.SetCurrentTimeGetter(saturday);
|
||||
@@ -593,7 +577,7 @@ UNIT_TEST(RoadAccess_WayBlockedAvoidPrivateConditional)
|
||||
graph.SetEdgeAccessConditional(0, 1, RoadAccess::Type::Private, "Mo-Fr 19:00 - 23:00");
|
||||
|
||||
auto const mondayAlmostTwentyHalfHours = []()
|
||||
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 20 /* hh */, 30 /* mm */); };
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Apr, Weekday::Monday, 20 /* hh */, 30 /* mm */); };
|
||||
|
||||
// We should avoid ways with private accesses. At 20:30 edge: 0->1 definitely has private access,
|
||||
// thus the answer is: 0->2->3.
|
||||
@@ -633,7 +617,8 @@ UNIT_TEST(RoadAccess_WayBlockedAlwaysNoExceptMonday)
|
||||
// Except Monday, access yes in this day.
|
||||
graph.SetEdgeAccessConditional(1, 2, RoadAccess::Type::Yes, "Mo");
|
||||
|
||||
auto const monday = []() { return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 10 /* hh */, 00 /* mm */); };
|
||||
auto const monday = []()
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Apr, Weekday::Monday, 10 /* hh */, 00 /* mm */); };
|
||||
|
||||
graph.SetCurrentTimeGetter(monday);
|
||||
expectedWeight = 3.0;
|
||||
@@ -661,7 +646,7 @@ UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
|
||||
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
|
||||
|
||||
auto const startAt_11_50 = []()
|
||||
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 11 /* hh */, 50 /* mm */); };
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Apr, Weekday::Monday, 11 /* hh */, 50 /* mm */); };
|
||||
|
||||
graph.SetCurrentTimeGetter(startAt_11_50);
|
||||
// When we will be at |3|, current time should be:
|
||||
@@ -673,7 +658,7 @@ UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
|
||||
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
|
||||
|
||||
auto const startAt_10_50 = []()
|
||||
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 10 /* hh */, 50 /* mm */); };
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Apr, Weekday::Monday, 10 /* hh */, 50 /* mm */); };
|
||||
|
||||
graph.SetCurrentTimeGetter(startAt_10_50);
|
||||
// When we will be at |3|, current time should be:
|
||||
@@ -692,7 +677,7 @@ UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
|
||||
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
|
||||
|
||||
auto const startAt_9_00 = []()
|
||||
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 00 /* mm */); };
|
||||
{ return GetUnixtimeByWeekday(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 00 /* mm */); };
|
||||
|
||||
graph.SetCurrentTimeGetter(startAt_9_00);
|
||||
// If we start at 9:00:00 we will arrive at |3| at:
|
||||
|
||||
@@ -368,4 +368,6 @@ std::string DebugPrint(InOutCitySpeedKMpH const & speed);
|
||||
std::string DebugPrint(InOutCityFactor const & speedFactor);
|
||||
std::string DebugPrint(HighwayType type);
|
||||
void FromString(std::string_view s, HighwayType & highwayType);
|
||||
|
||||
using TimeGetterT = std::function<time_t()>;
|
||||
} // namespace routing
|
||||
|
||||
Reference in New Issue
Block a user