indexed_iterator_test.cxx 679 B

1234567891011121314151617181920212223
  1. #include "iterator/indexed_iterator.hpp"
  2. #include <vector>
  3. #include <gmock/gmock.h>
  4. using idx_iterator = iterator::indexed_iterator<std::vector<int>::const_iterator>;
  5. TEST(IndexedIteratorTest, TreatsVectorIteratorAsMapIdxToValue) {
  6. std::vector<int> const vec{5, 3, 2, 8, 9, 11, 2, 4};
  7. idx_iterator it{vec.begin()}, end{vec.end()};
  8. for (; it != end; ++it) {
  9. EXPECT_THAT((*it).second, vec[(*it).first]);
  10. }
  11. }
  12. TEST(IndexedIteratorTest, ContainsReferencesToContainersElements) {
  13. std::vector<int> const vec{5, 3, 2, 8, 9, 11, 2, 4};
  14. idx_iterator it{vec.begin()}, end{vec.end()};
  15. for (; it != end; ++it) {
  16. EXPECT_THAT(&(*it).second, &vec[(*it).first]);
  17. }
  18. }