Skip to content

Commit

Permalink
finish testing
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Jan 5, 2025
1 parent 10d1dbf commit 47e2b3f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/geoarrow/hpp/array_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class BaseRandomAccessIterator {
i_++;
return *this;
}
BaseRandomAccessIterator& operator--() {
i_--;
return *this;
}
BaseRandomAccessIterator& operator+=(int64_t n) {
i_ += n;
return *this;
Expand Down Expand Up @@ -78,7 +82,7 @@ class ListSequenceIterator : public BaseRandomAccessIterator<ListSequence> {
}

// Not quite a random access iterator because it doesn't implement []
// (which would necessiate a copy, which we don't really want to do)
// (which would necessitate a copy, which we don't really want to do)
private:
typename ListSequence::child_type stashed_;
};
Expand Down
36 changes: 36 additions & 0 deletions src/geoarrow/hpp/array_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,42 @@ TEST(GeoArrowHppTest, BoxXYZM) {
EXPECT_EQ(coord.upper_bound(), expected_upper);
}

TEST(GeoArrowHppTest, RandomAccessIterator) {
TestCoords coords{{0, 1, 2, 3, 4, 5}, {6, 7, 8, 9, 10, 11}};
CoordSequence<XY> sequence;
geoarrow::array_util::internal::InitFromCoordView(&sequence, coords.view());

auto it = sequence.begin();
EXPECT_EQ(sequence.end() - it, sequence.size());
EXPECT_EQ(it - sequence.end(), -sequence.size());

++it;
ASSERT_EQ(sequence.end() - it, (sequence.size() - 1));
it += 2;
ASSERT_EQ(sequence.end() - it, (sequence.size() - 3));
it -= 2;
ASSERT_EQ(sequence.end() - it, (sequence.size() - 1));
--it;
ASSERT_EQ(it, sequence.begin());

ASSERT_TRUE(sequence.begin() == sequence.begin());
ASSERT_FALSE(sequence.begin() != sequence.begin());
ASSERT_TRUE(sequence.begin() >= sequence.begin());
ASSERT_TRUE(sequence.begin() <= sequence.begin());
ASSERT_FALSE(sequence.begin() > sequence.begin());
ASSERT_FALSE(sequence.begin() < sequence.begin());

++it;
ASSERT_TRUE(it > sequence.begin());
ASSERT_TRUE(it >= sequence.begin());
ASSERT_TRUE(sequence.begin() < it);
ASSERT_TRUE(sequence.begin() <= it);
ASSERT_FALSE(it < sequence.begin());
ASSERT_FALSE(it <= sequence.begin());
ASSERT_FALSE(sequence.begin() > it);
ASSERT_FALSE(sequence.begin() >= it);
}

TEST(GeoArrowHppTest, IterateCoords) {
TestCoords coords{{0, 1, 2}, {5, 6, 7}};

Expand Down

0 comments on commit 47e2b3f

Please sign in to comment.