always emit a small component view
Unit Tests for Reodering by Predicate
This commit is contained in:
committed by
Patrick Niklaus
parent
b9ed20bb9b
commit
c3cc79f798
@@ -6,6 +6,10 @@ file(GLOB ExtractorTestsSources
|
||||
extractor_tests.cpp
|
||||
extractor/*.cpp)
|
||||
|
||||
file(GLOB PartitionTestsSources
|
||||
partition_tests.cpp
|
||||
partition/*.cpp)
|
||||
|
||||
file(GLOB LibraryTestsSources
|
||||
library_tests.cpp
|
||||
library/*.cpp)
|
||||
@@ -29,6 +33,11 @@ add_executable(extractor-tests
|
||||
${ExtractorTestsSources}
|
||||
$<TARGET_OBJECTS:EXTRACTOR> $<TARGET_OBJECTS:UTIL>)
|
||||
|
||||
add_executable(partition-tests
|
||||
EXCLUDE_FROM_ALL
|
||||
${PartitionTestsSources}
|
||||
$<TARGET_OBJECTS:PARTITIONER> $<TARGET_OBJECTS:UTIL>)
|
||||
|
||||
add_executable(library-tests
|
||||
EXCLUDE_FROM_ALL
|
||||
${LibraryTestsSources})
|
||||
@@ -57,6 +66,7 @@ target_include_directories(util-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(engine-tests ${ENGINE_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(extractor-tests ${EXTRACTOR_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(partition-tests ${PARTITIONER_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(library-tests osrm ${ENGINE_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(server-tests osrm ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(util-tests ${UTIL_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
@@ -64,4 +74,4 @@ target_link_libraries(util-tests ${UTIL_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_L
|
||||
|
||||
add_custom_target(tests
|
||||
DEPENDS
|
||||
engine-tests extractor-tests library-tests server-tests util-tests)
|
||||
engine-tests extractor-tests partition-tests library-tests server-tests util-tests)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "partition/reorder_first_last.hpp"
|
||||
|
||||
#include <boost/test/test_case_template.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using namespace osrm::partition;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(reorder_first_last)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(reordering_one_is_equivalent_to_min_and_max)
|
||||
{
|
||||
std::vector<int> range{9, 0, 8, 1, 7, 2, 6, 3, 5, 4};
|
||||
|
||||
reorderFirstLast(begin(range), end(range), 1, std::less<>{});
|
||||
|
||||
BOOST_CHECK_EQUAL(range.front(), 0);
|
||||
BOOST_CHECK_EQUAL(range.back(), 9);
|
||||
|
||||
reorderFirstLast(begin(range), end(range), 1, std::greater<>{});
|
||||
|
||||
BOOST_CHECK_EQUAL(range.front(), 9);
|
||||
BOOST_CHECK_EQUAL(range.back(), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(reordering_n_shuffles_n_smallest_to_front_n_largest_to_back)
|
||||
{
|
||||
std::vector<int> range{9, 3, 8, 2};
|
||||
|
||||
reorderFirstLast(begin(range), end(range), 2, std::less<>{});
|
||||
|
||||
// Smallest at front, but: no ordering guarantee in that subrange!
|
||||
BOOST_CHECK((range[0] == 2 and range[1] == 3) or (range[0] == 3 and range[1] == 2));
|
||||
|
||||
// Largest at back, but: no ordering guarantee in that subrange!
|
||||
BOOST_CHECK((range[2] == 8 and range[3] == 9) or (range[2] == 9 and range[3] == 8));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(reordering_n_with_iterators)
|
||||
{
|
||||
std::vector<int> range{9, 3, 8, 2};
|
||||
|
||||
reorderFirstLast(begin(range), end(range), 1, std::less<>{});
|
||||
|
||||
BOOST_CHECK_EQUAL(range.front(), 2);
|
||||
BOOST_CHECK_EQUAL(range.back(), 9);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -0,0 +1,7 @@
|
||||
#define BOOST_TEST_MODULE partition tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
/*
|
||||
* This file will contain an automatically generated main function.
|
||||
*/
|
||||
Reference in New Issue
Block a user