mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
87
routing/routing_tests/routing_options_tests.cpp
Normal file
87
routing/routing_tests/routing_options_tests.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "testing/testing.hpp"
|
||||
|
||||
#include "routing/routing_options.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
using namespace routing;
|
||||
|
||||
namespace
|
||||
{
|
||||
using RoadType = RoutingOptions::RoadType;
|
||||
|
||||
class RoutingOptionsTests
|
||||
{
|
||||
public:
|
||||
RoutingOptionsTests()
|
||||
{
|
||||
m_savedOptions = RoutingOptions::LoadCarOptionsFromSettings();
|
||||
}
|
||||
|
||||
~RoutingOptionsTests()
|
||||
{
|
||||
RoutingOptions::SaveCarOptionsToSettings(m_savedOptions);
|
||||
}
|
||||
|
||||
private:
|
||||
RoutingOptions m_savedOptions;
|
||||
};
|
||||
|
||||
RoutingOptions CreateOptions(std::vector<RoutingOptions::Road> const & include)
|
||||
{
|
||||
RoutingOptions options;
|
||||
|
||||
for (auto type : include)
|
||||
options.Add(type);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
void Checker(std::vector<RoutingOptions::Road> const & include)
|
||||
{
|
||||
RoutingOptions options = CreateOptions(include);
|
||||
|
||||
for (auto type : include)
|
||||
TEST(options.Has(type), ());
|
||||
|
||||
auto max = static_cast<RoadType>(RoutingOptions::Road::Max);
|
||||
for (uint8_t i = 1; i < max; i <<= 1)
|
||||
{
|
||||
bool hasInclude = false;
|
||||
auto type = static_cast<RoutingOptions::Road>(i);
|
||||
for (auto has : include)
|
||||
hasInclude |= (type == has);
|
||||
|
||||
if (!hasInclude)
|
||||
TEST(!options.Has(static_cast<RoutingOptions::Road>(i)), ());
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(RoutingOptionTest)
|
||||
{
|
||||
Checker({RoutingOptions::Road::Toll, RoutingOptions::Road::Motorway,
|
||||
RoutingOptions::Road::Dirty});
|
||||
Checker({RoutingOptions::Road::Toll, RoutingOptions::Road::Dirty});
|
||||
|
||||
Checker({RoutingOptions::Road::Toll, RoutingOptions::Road::Ferry,
|
||||
RoutingOptions::Road::Dirty});
|
||||
|
||||
Checker({RoutingOptions::Road::Dirty});
|
||||
Checker({RoutingOptions::Road::Toll});
|
||||
Checker({RoutingOptions::Road::Dirty, RoutingOptions::Road::Motorway});
|
||||
Checker({});
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(RoutingOptionsTests, GetSetTest)
|
||||
{
|
||||
RoutingOptions options = CreateOptions({RoutingOptions::Road::Toll,
|
||||
RoutingOptions::Road::Motorway,
|
||||
RoutingOptions::Road::Dirty});
|
||||
|
||||
RoutingOptions::SaveCarOptionsToSettings(options);
|
||||
RoutingOptions fromSettings = RoutingOptions::LoadCarOptionsFromSettings();
|
||||
|
||||
TEST_EQUAL(options.GetOptions(), fromSettings.GetOptions(), ());
|
||||
}
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user