Skip to content

Commit

Permalink
Adding more comaprison tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Nov 7, 2023
1 parent 416d056 commit b07d0c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/tools/ranges/TransformView/Iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,40 @@ class Iterator {
friend constexpr bool operator<( const Iterator& left,
const Iterator& right) {

static_assert(
concepts::IsRandomAccessIterator< Iterator >::value == true,
"the at() method can only be made available for random access iterators" );

return left.iter_ < right.iter_;
}

friend constexpr bool operator>( const Iterator& left,
const Iterator& right ) {

static_assert(
concepts::IsRandomAccessIterator< Iterator >::value == true,
"the at() method can only be made available for random access iterators" );

return right < left;
}

friend constexpr bool operator<=( const Iterator& left,
const Iterator& right ) {

static_assert(
concepts::IsRandomAccessIterator< Iterator >::value == true,
"the at() method can only be made available for random access iterators" );

return !( right < left );
}

friend constexpr bool operator>=( const Iterator& left,
const Iterator& right ) {

static_assert(
concepts::IsRandomAccessIterator< Iterator >::value == true,
"the at() method can only be made available for random access iterators" );

return !( left < right );
}
};
17 changes: 17 additions & 0 deletions src/tools/ranges/TransformView/Iterator/test/Iterator.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ SCENARIO( "TransformView" ) {
// CHECK( begin == iter );
// iter = 1 + begin;
// CHECK( second == iter );

// the following should not compile: no random access iterator
// CHECK( second >= begin );
// CHECK( second > begin );
// CHECK( begin <= second );
// CHECK( begin < second );
} // THEN
} // WHEN
} // GIVEN
Expand Down Expand Up @@ -137,6 +143,12 @@ SCENARIO( "TransformView" ) {
// CHECK( begin == iter );
// iter = 1 + begin;
// CHECK( second == iter );

// the following should not compile: no random access iterator
// CHECK( second >= begin );
// CHECK( second > begin );
// CHECK( begin <= second );
// CHECK( begin < second );
} // THEN
} // WHEN
} // GIVEN
Expand Down Expand Up @@ -197,6 +209,11 @@ SCENARIO( "TransformView" ) {
CHECK( begin == iter );
iter = 1 + begin;
CHECK( second == iter );

CHECK( second >= begin );
CHECK( second > begin );
CHECK( begin <= second );
CHECK( begin < second );
} // THEN
} // WHEN
} // GIVEN
Expand Down

0 comments on commit b07d0c0

Please sign in to comment.