Skip to content
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

Merged

Conversation

mar-celine
Copy link
Contributor

No description provided.

@codecov-io
Copy link

codecov-io commented Jul 20, 2017

Codecov Report

Merging #127 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6db2f5d...0f74b0e. Read the comment docs.

CHECK(c.end() == c.cend());
CHECK(c.rend() - c.rbegin() == c.size());

auto it = c.begin();
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and again

template <typename Container>
void test_reverse_iterators(Container& c) {
CHECK(c.rend() - c.rbegin() == c.size());
auto it = c.begin();
Copy link
Member

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


const auto& const_c = c;
CHECK(const_c.rend() - const_c.rbegin() == const_c.size());
auto cit = const_c.begin();
Copy link
Member

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

cend--;
}
}

Copy link
Member

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

Copy link
Member

@kidder kidder left a 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

// Test for iterators
template <typename Container>
void test_iterators(Container& c) {
CHECK(c.end() - c.begin() == c.size());
Copy link
Member

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.

@@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

Copy link
Member

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

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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

// 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());
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove 145-7

@@ -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());
Copy link
Member

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

// 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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove 145-7

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

CHECK(c.end() == c.cend());
CHECK(c.rend() - c.rbegin() == c.size());

auto it = c.begin();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and again

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.crbegin();

auto cit = c.cbegin();
auto cend = c.cend();
auto crit = c.rbegin();
auto crend = c.rend();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.crend();

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see size comment above

kidder
kidder previously approved these changes Jul 25, 2017
@nilsdeppe nilsdeppe merged commit e1356bd into sxs-collaboration:develop Jul 25, 2017
@mar-celine mar-celine deleted the gab_test_iterator_addition branch December 1, 2018 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants