indexed_iterator_test.cxx 683 B

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