osrm-backend/unit_tests/util/permutation.cpp
Patrick Niklaus 0266c9d969 Renumber nodes after running osrm-partition
The new numbering uses the partition information
to sort border nodes first to compactify storages
that need access indexed by border node ID.

We also get an optimized cache performance for free
sincr we can also recursively sort the nodes by cell ID.

This implements issue #3779.
2017-06-02 18:12:13 +00:00

31 lines
837 B
C++

#include "../common/range_tools.hpp"
#include "util/permutation.hpp"
#include <boost/test/test_case_template.hpp>
#include <boost/test/unit_test.hpp>
#include <algorithm>
#include <numeric>
#include <random>
BOOST_AUTO_TEST_SUITE(permutation_test)
using namespace osrm;
using namespace osrm::util;
BOOST_AUTO_TEST_CASE(basic_permuation)
{
// cycles (0 3 2 1 4 8) (5) (6 9 7)
// 0 1 2 3 4 5 6 7 8 9
std::vector<std::uint32_t> values{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const std::vector<std::uint32_t> permutation{3, 4, 1, 2, 8, 5, 9, 6, 0, 7};
std::vector<std::uint32_t> reference{9, 3, 4, 1, 2, 6, 8, 10, 5, 7};
inplacePermutation(values.begin(), values.end(), permutation);
CHECK_EQUAL_COLLECTIONS(values, reference);
}
BOOST_AUTO_TEST_SUITE_END()