-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for iterables #127
Add tests for iterables #127
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #127 +/- ##
========================================
Coverage 96.81% 96.81%
========================================
Files 72 72
Lines 2167 2167
========================================
Hits 2098 2098
Misses 69 69 Continue to review full report at Codecov.
|
tests/Unit/TestHelpers.hpp
Outdated
CHECK(c.end() == c.cend()); | ||
CHECK(c.rend() - c.rbegin() == c.size()); | ||
|
||
auto it = c.begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the other begin and end cases? This only checks half. We also should have a test_iterators
and a test_reverse_iterators
because unordered associative containers do not have reverse iteration since there is no order defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and again
bd69d44
to
af6ce8d
Compare
tests/Unit/TestHelpers.hpp
Outdated
template <typename Container> | ||
void test_reverse_iterators(Container& c) { | ||
CHECK(c.rend() - c.rbegin() == c.size()); | ||
auto it = c.begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check that crbegin and crend are equal to rbegin and rend
tests/Unit/TestHelpers.hpp
Outdated
|
||
const auto& const_c = c; | ||
CHECK(const_c.rend() - const_c.rbegin() == const_c.size()); | ||
auto cit = const_c.begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check that crbegin and crend are equal to rbegin and rend
tests/Unit/TestHelpers.hpp
Outdated
cend--; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add for loops checking the cbegin and cend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also test TestHelpers on std::containers
tests/Unit/TestHelpers.hpp
Outdated
// Test for iterators | ||
template <typename Container> | ||
void test_iterators(Container& c) { | ||
CHECK(c.end() - c.begin() == c.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of stuff in here (such as the subtraction in this line) will only compile for random access iterators, but could be made to work for more using things like std::distance
and std::next
. std::set
(for the bidirectional case) and std::unordered_set
(for the forward case) can be used as tests of what works.
6b11c8e
to
8ab6d1a
Compare
tests/Unit/TestHelpers.hpp
Outdated
@@ -141,46 +141,71 @@ void test_move_semantics(T&& a, const T& comparison) { | |||
// Test for iterators | |||
template <typename Container> | |||
void test_iterators(Container& c) { | |||
CHECK(c.end() - c.begin() == c.size()); | |||
// CHECK(c.end() - c.begin() == c.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented out code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHECK(std::distance(c.begin(),c.end()) == c.size())
maybe with a cast
tests/Unit/TestHelpers.hpp
Outdated
auto c_it = const_c.begin(); | ||
auto c_nx = std::next(c_it, std::distance(const_c.begin(), const_c.end())); | ||
CHECK(c_nx == const_c.end()); | ||
// CHECK(const_c.end() - const_c.begin() == const_c.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented out code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
tests/Unit/TestHelpers.hpp
Outdated
// CHECK(c.end() - c.begin() == c.size()); | ||
auto it = c.begin(); | ||
auto nx = std::next(it, std::distance(c.begin(), c.end())); | ||
CHECK(nx == c.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the check against c.size()
removed? I don't think the new version tests much beyond that the std::distance
call doesn't segfault or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove 145-7
tests/Unit/TestHelpers.hpp
Outdated
@@ -141,46 +141,71 @@ void test_move_semantics(T&& a, const T& comparison) { | |||
// Test for iterators | |||
template <typename Container> | |||
void test_iterators(Container& c) { | |||
CHECK(c.end() - c.begin() == c.size()); | |||
// CHECK(c.end() - c.begin() == c.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHECK(std::distance(c.begin(),c.end()) == c.size())
maybe with a cast
tests/Unit/TestHelpers.hpp
Outdated
// CHECK(c.end() - c.begin() == c.size()); | ||
auto it = c.begin(); | ||
auto nx = std::next(it, std::distance(c.begin(), c.end())); | ||
CHECK(nx == c.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove 145-7
tests/Unit/TestHelpers.hpp
Outdated
auto c_it = const_c.begin(); | ||
auto c_nx = std::next(c_it, std::distance(const_c.begin(), const_c.end())); | ||
CHECK(c_nx == const_c.end()); | ||
// CHECK(const_c.end() - const_c.begin() == const_c.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
tests/Unit/TestHelpers.hpp
Outdated
CHECK(c.end() == c.cend()); | ||
CHECK(c.rend() - c.rbegin() == c.size()); | ||
|
||
auto it = c.begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and again
tests/Unit/TestHelpers.hpp
Outdated
auto it = c.begin(); | ||
auto rit = c.rbegin(); | ||
auto end = c.end(); | ||
auto rend = c.rend(); | ||
auto cit = c.cbegin(); | ||
auto cend = c.cend(); | ||
auto crit = c.rbegin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.crbegin();
tests/Unit/TestHelpers.hpp
Outdated
auto cit = c.cbegin(); | ||
auto cend = c.cend(); | ||
auto crit = c.rbegin(); | ||
auto crend = c.rend(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.crend();
tests/Unit/TestHelpers.hpp
Outdated
auto crend = const_c.rend(); | ||
auto cr_it = const_c.rbegin(); | ||
auto cr_nx = std::next(cr_it, std::distance(const_c.begin(), const_c.end())); | ||
CHECK(cr_nx == const_c.rend()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see size comment above
a1a45c8
to
0351bd1
Compare
0351bd1
to
0f74b0e
Compare
No description provided.