Fix vector<bool> serialization for tar files and add unit tests
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#include "contractor/files.hpp"
|
||||
#include "contractor/graph_contractor_adaptors.hpp"
|
||||
|
||||
#include "../common/range_tools.hpp"
|
||||
#include "../common/temporary_file.hpp"
|
||||
#include "helper.hpp"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(tar)
|
||||
|
||||
using namespace osrm;
|
||||
using namespace osrm::contractor;
|
||||
using namespace osrm::unit_test;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(read_write_hsgr)
|
||||
{
|
||||
auto reference_checksum = 0xFF00FF00;
|
||||
auto reference_connectivity_checksum = 0xDEADBEEF;
|
||||
std::vector<TestEdge> edges = {TestEdge{0, 1, 3},
|
||||
TestEdge{0, 5, 1},
|
||||
TestEdge{1, 3, 3},
|
||||
TestEdge{1, 4, 1},
|
||||
TestEdge{3, 1, 1},
|
||||
TestEdge{4, 3, 1},
|
||||
TestEdge{5, 1, 1}};
|
||||
auto reference_graph = QueryGraph {6, toEdges<QueryEdge>(makeGraph(edges))};
|
||||
std::vector<std::vector<bool>> reference_filters = {
|
||||
{false, false, true, true, false, false, true},
|
||||
{true, false, true, false, true, false, true},
|
||||
{false, false, false, false, false, false, false},
|
||||
{true, true, true, true, true, true, true},
|
||||
};
|
||||
|
||||
TemporaryFile tmp {TEST_DATA_DIR "/read_write_hsgr_test.osrm.hsgr"};
|
||||
contractor::files::writeGraph(tmp.path, reference_checksum, reference_graph, reference_filters, reference_connectivity_checksum);
|
||||
|
||||
unsigned checksum;
|
||||
unsigned connectivity_checksum;
|
||||
QueryGraph graph;
|
||||
std::vector<std::vector<bool>> filters;
|
||||
contractor::files::readGraph(tmp.path, checksum, graph, filters, connectivity_checksum);
|
||||
|
||||
BOOST_CHECK_EQUAL(checksum, reference_checksum);
|
||||
BOOST_CHECK_EQUAL(connectivity_checksum, reference_connectivity_checksum);
|
||||
BOOST_CHECK_EQUAL(filters.size(), reference_filters.size());
|
||||
CHECK_EQUAL_COLLECTIONS(filters[0], reference_filters[0]);
|
||||
CHECK_EQUAL_COLLECTIONS(filters[1], reference_filters[1]);
|
||||
CHECK_EQUAL_COLLECTIONS(filters[2], reference_filters[2]);
|
||||
CHECK_EQUAL_COLLECTIONS(filters[3], reference_filters[3]);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "contractor/graph_contractor.hpp"
|
||||
|
||||
#include "../common/range_tools.hpp"
|
||||
#include "helper.hpp"
|
||||
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
@@ -9,32 +10,10 @@
|
||||
|
||||
using namespace osrm;
|
||||
using namespace osrm::contractor;
|
||||
using namespace osrm::unit_test;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(graph_contractor)
|
||||
|
||||
using TestEdge = std::tuple<unsigned, unsigned, int>;
|
||||
ContractorGraph makeGraph(const std::vector<TestEdge> &edges)
|
||||
{
|
||||
std::vector<ContractorEdge> input_edges;
|
||||
auto id = 0u;
|
||||
auto max_id = 0u;
|
||||
for (const auto &edge : edges)
|
||||
{
|
||||
unsigned start;
|
||||
unsigned target;
|
||||
int weight;
|
||||
std::tie(start, target, weight) = edge;
|
||||
max_id = std::max(std::max(start, target), max_id);
|
||||
input_edges.push_back(ContractorEdge{
|
||||
start, target, ContractorEdgeData{weight, weight * 2, id++, 0, false, true, false}});
|
||||
input_edges.push_back(ContractorEdge{
|
||||
target, start, ContractorEdgeData{weight, weight * 2, id++, 0, false, false, true}});
|
||||
}
|
||||
std::sort(input_edges.begin(), input_edges.end());
|
||||
|
||||
return ContractorGraph{max_id + 1, std::move(input_edges)};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(contract_graph)
|
||||
{
|
||||
tbb::task_scheduler_init scheduler(1);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef OSRM_UNIT_TESTS_CONTRACTOR_HELPER_HPP_
|
||||
#define OSRM_UNIT_TESTS_CONTRACTOR_HELPER_HPP_
|
||||
|
||||
#include "contractor/contractor_graph.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace unit_test
|
||||
{
|
||||
|
||||
using TestEdge = std::tuple<unsigned, unsigned, int>;
|
||||
inline contractor::ContractorGraph makeGraph(const std::vector<TestEdge> &edges)
|
||||
{
|
||||
std::vector<contractor::ContractorEdge> input_edges;
|
||||
auto id = 0u;
|
||||
auto max_id = 0u;
|
||||
for (const auto &edge : edges)
|
||||
{
|
||||
unsigned start;
|
||||
unsigned target;
|
||||
int weight;
|
||||
std::tie(start, target, weight) = edge;
|
||||
max_id = std::max(std::max(start, target), max_id);
|
||||
input_edges.push_back(contractor::ContractorEdge{
|
||||
start, target, contractor::ContractorEdgeData{weight, weight * 2, id++, 0, false, true, false}});
|
||||
input_edges.push_back(contractor::ContractorEdge{
|
||||
target, start, contractor::ContractorEdgeData{weight, weight * 2, id++, 0, false, false, true}});
|
||||
}
|
||||
std::sort(input_edges.begin(), input_edges.end());
|
||||
|
||||
return contractor::ContractorGraph{max_id + 1, std::move(input_edges)};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user