| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include "iterator/indexed_iterator.hpp"
- #include <vector>
- #include <gmock/gmock.h>
- using idx_iterator = iterator::indexed_iterator<std::vector<int>::iterator>;
- // TODO: This ought to be implemented as a compiles-test
- TEST(IndexedIteratorTest, CanCastCompatibleIterators) {
- std::vector<int> v{1, 2, 3, 4, 5};
- idx_iterator eai(v.begin());
- ::iterator::indexed_iterator<std::vector<int>::const_iterator>{eai};
- }
- TEST(IndexedIteratorTest, CanLieAboutIndex) {
- std::vector<int> vec{5, 3, 2, 8, 9, 11, 2, 4};
- idx_iterator it(vec.begin(), 3);
- EXPECT_THAT(it->first, 3);
- }
- TEST(IndexedIteratorTest, FakeIndexDoesntEffectEqualityCheck) {
- std::vector<int> vec{5, 3, 2, 8, 9, 11, 2, 4};
- EXPECT_THAT(idx_iterator(vec.begin()), idx_iterator(vec.begin(), 3));
- }
- TEST(IndexedIteratorTest, TreatsVectorIteratorAsMapIdxToValue) {
- std::vector<int> vec{5, 3, 2, 8, 9, 11, 2, 4};
- std::vector<std::pair<int, int>> const expected{
- {0, 5}, {1, 3}, {2, 2}, {3, 8}, {4, 9}, {5, 11}, {6, 2}, {7, 4}};
- std::vector<std::pair<int, int>> const result(idx_iterator(vec.begin()),
- idx_iterator(vec.end()));
- EXPECT_THAT(result, expected);
- }
- TEST(IndexedIteratorTest, CanMutatePointedToData) {
- std::vector<int> vec{5, 3, 2, 8, 9, 11, 2, 4};
- idx_iterator(vec.begin() + 4, 4)->second = -1;
- EXPECT_THAT(vec[4], -1);
- }
|