Skip to content

Commit

Permalink
Fixes compiler warnings in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp committed Apr 22, 2016
1 parent b710044 commit 4bb661e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/test_radix_tree_erase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(erase, change_size)
tree.erase(key);
ASSERT_EQ(size_before_erase - 1, tree.size());
}
ASSERT_EQ(0, tree.size());
ASSERT_EQ(0u, tree.size());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_radix_tree_greedy_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(greedy_match, complex_tree)
for (tree_t::iterator it = tree.begin(); it != tree.end(); ++it) {
vector_found_t vec;
tree.greedy_match(it->first, vec);
ASSERT_GE(vec.size(), 1);
ASSERT_GE(vec.size(), 1u);
map_found_t map_found = vec_found_to_map(vec);
ASSERT_NE(map_found.end(), map_found.find(it->first)) << "there is no such key in found";
ASSERT_EQ(map_found[it->first], it->second);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_radix_tree_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(iterator, distance)
tree.insert( tree_t::value_type(key, rand()%100) );
}
}
ASSERT_EQ(unique_keys.size(), std::distance(tree.begin(), tree.end()) );
ASSERT_EQ(unique_keys.size(), size_t(std::distance(tree.begin(), tree.end())) );
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@ TEST(iterator, std__copy)
std::map<std::string, int> map;
std::copy(tree.begin(), tree.end(), std::inserter(map, map.end()));

ASSERT_EQ(map.size(), std::distance(tree.begin(), tree.end()) );
ASSERT_EQ(map.size(), size_t(std::distance(tree.begin(), tree.end())) );
for(tree_t::iterator it = tree.begin(); it != tree.end(); ++it) {
ASSERT_NE(map.end(), map.find(it->first));
}
Expand Down
39 changes: 24 additions & 15 deletions tests/test_radix_tree_prefix_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ bool is_prefix_of(const std::string& prefix, const std::string& str) {
return p.first == prefix.end();
}

void check_nonexistent_prefixes(tree_t& tree)
{
SCOPED_TRACE("should never be found");
const std::string never_found_strings[] = {
"abcdfe", "abcdefe", "abe", "cc", "abcdec", "bcdefc"
};
std::vector<std::string> should_never_be_found = make_vector(never_found_strings);
for (size_t i = 0; i < should_never_be_found.size(); i++) {
const std::string key = should_never_be_found[i];
SCOPED_TRACE(key);
vector_found_t vec;
tree.prefix_match(key, vec);
ASSERT_EQ(0u, vec.size());
}
}

TEST(prefix_match, empty_tree)
{
tree_t tree;
check_nonexistent_prefixes(tree);
}

TEST(prefix_match, complex_tree)
{
tree_t tree;
Expand All @@ -22,7 +44,7 @@ TEST(prefix_match, complex_tree)
for (tree_t::iterator it = tree.begin(); it != tree.end(); ++it) {
vector_found_t vec;
tree.prefix_match(it->first, vec);
ASSERT_GE(vec.size(), 1);
ASSERT_GE(vec.size(), 1u);
map_found_t map_found = vec_found_to_map(vec);
ASSERT_NE(map_found.end(), map_found.find(it->first)) << "there is no such key in found";
ASSERT_EQ(map_found[it->first], it->second);
Expand Down Expand Up @@ -70,18 +92,5 @@ TEST(prefix_match, complex_tree)
ASSERT_EQ(prefix_it->second, vec_found_to_map(vec));
}
}
{
SCOPED_TRACE("should never be found");
const std::string never_found_strings[] = {
"abcdfe", "abcdefe", "abe", "cc", "abcdec", "bcdefc"
};
std::vector<std::string> should_never_be_found = make_vector(never_found_strings);
for (size_t i = 0; i < should_never_be_found.size(); i++) {
const std::string key = should_never_be_found[i];
SCOPED_TRACE(key);
vector_found_t vec;
tree.prefix_match(key, vec);
ASSERT_EQ(0, vec.size());
}
}
check_nonexistent_prefixes(tree);
}

0 comments on commit 4bb661e

Please sign in to comment.