#include "util/vector_view.hpp" #include "util/typedefs.hpp" #include #include #include #include #include #include #include BOOST_AUTO_TEST_SUITE(vector_view_test) using namespace osrm; using namespace osrm::util; BOOST_AUTO_TEST_CASE(rw_short) { std::size_t num_elements = 1000; std::unique_ptr data = std::make_unique(sizeof(std::uint16_t) * num_elements); util::vector_view view(reinterpret_cast(data.get()), num_elements); std::vector reference; std::mt19937 rng; rng.seed(1337); std::uniform_int_distribution dist(0, (1UL << 16)); for (std::size_t i = 0; i < num_elements; i++) { auto r = dist(rng); view[i] = r; reference.push_back(r); } for (std::size_t i = 0; i < num_elements; i++) { BOOST_CHECK_EQUAL(view[i], reference[i]); } } BOOST_AUTO_TEST_CASE(rw_bool) { std::size_t num_elements = 1000; auto data = std::make_unique::Word[]>( (num_elements + sizeof(typename vector_view::Word) - 1) / sizeof(typename vector_view::Word)); util::vector_view view(reinterpret_cast::Word *>(data.get()), num_elements); std::vector reference; std::mt19937 rng; rng.seed(1337); std::uniform_int_distribution dist(0, 2); for (std::size_t i = 0; i < num_elements; i++) { auto r = dist(rng); view[i] = r; reference.push_back(r); } for (std::size_t i = 0; i < num_elements; i++) { BOOST_CHECK_EQUAL(view[i], reference[i]); } } BOOST_AUTO_TEST_SUITE_END()