Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tessil committed Jan 26, 2019
1 parent 5555350 commit a4bab66
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/custom_allocator_tests.cpp
Expand Up @@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(test_custom_allocator_1) {
tsl::ordered_map<int, int, std::hash<int>, std::equal_to<int>,
custom_allocator<std::pair<int, int>>> map;

const int nb_elements = 10000;
const int nb_elements = 1000;
for(int i = 0; i < nb_elements; i++) {
map.insert({i, i*2});
}
Expand Down
39 changes: 39 additions & 0 deletions tests/ordered_map_tests.cpp
Expand Up @@ -922,6 +922,16 @@ BOOST_AUTO_TEST_CASE(test_move_constructor) {
BOOST_CHECK(map_move == utils::get_filled_hash_map<HMap>(nb_values*2));
}

BOOST_AUTO_TEST_CASE(test_move_constructor_empty) {
tsl::ordered_map<std::string, move_only_test> map(0);
tsl::ordered_map<std::string, move_only_test> map_move(std::move(map));

BOOST_CHECK(map.empty());
BOOST_CHECK(map_move.empty());

BOOST_CHECK(map.find("") == map.end());
BOOST_CHECK(map_move.find("") == map_move.end());
}

BOOST_AUTO_TEST_CASE(test_move_operator) {
// insert x values in map, move map into map_move, check map and map_move,
Expand All @@ -946,6 +956,18 @@ BOOST_AUTO_TEST_CASE(test_move_operator) {
BOOST_CHECK(map_move == utils::get_filled_hash_map<HMap>(nb_values*2));
}

BOOST_AUTO_TEST_CASE(test_move_operator_empty) {
tsl::ordered_map<std::string, move_only_test> map(0);
tsl::ordered_map<std::string, move_only_test> map_move;
map_move = (std::move(map));

BOOST_CHECK(map.empty());
BOOST_CHECK(map_move.empty());

BOOST_CHECK(map.find("") == map.end());
BOOST_CHECK(map_move.find("") == map_move.end());
}

BOOST_AUTO_TEST_CASE(test_reassign_moved_object_move_constructor) {
using HMap = tsl::ordered_map<std::string, std::string>;

Expand Down Expand Up @@ -1110,6 +1132,23 @@ BOOST_AUTO_TEST_CASE(test_swap) {
BOOST_CHECK(map2 == (tsl::ordered_map<std::int64_t, std::int64_t>{{1, 10}, {8, 80}, {3, 30}, {4, 40}}));
}

BOOST_AUTO_TEST_CASE(test_swap_empty) {
tsl::ordered_map<std::int64_t, std::int64_t> map = {{1, 10}, {8, 80}, {3, 30}};
tsl::ordered_map<std::int64_t, std::int64_t> map2;

using std::swap;
swap(map, map2);

BOOST_CHECK(map == (tsl::ordered_map<std::int64_t, std::int64_t>{}));
BOOST_CHECK(map2 == (tsl::ordered_map<std::int64_t, std::int64_t>{{1, 10}, {8, 80}, {3, 30}}));

map.insert({6, 60});
map2.insert({4, 40});

BOOST_CHECK(map == (tsl::ordered_map<std::int64_t, std::int64_t>{{6, 60}}));
BOOST_CHECK(map2 == (tsl::ordered_map<std::int64_t, std::int64_t>{{1, 10}, {8, 80}, {3, 30}, {4, 40}}));
}

/**
* front(), back()
*/
Expand Down

0 comments on commit a4bab66

Please sign in to comment.