Skip to content

Commit

Permalink
Updating byte_vector to remove some unused functions. Also adding bet…
Browse files Browse the repository at this point in the history
…ter test coverage to the test_byte_vector
  • Loading branch information
ryan-dozier committed Oct 31, 2024
1 parent 7b008c4 commit 3abb92f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
3 changes: 0 additions & 3 deletions include/ygm/detail/byte_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class byte_vector {
using value_type = std::byte;
using pointer = std::byte*;
using reference = std::byte&;
using difference_type = std::ptrdiff_t;
public:
class Byte_Iterator {
public:
Expand All @@ -43,8 +42,6 @@ class byte_vector {
Byte_Iterator& operator+=(int n) { i += n; return *this; }
Byte_Iterator& operator-=(int n) { i -= n; return *this; }

difference_type operator-(Byte_Iterator const& r) const { return i - r.i; }

bool operator<(Byte_Iterator const& r) const { return i < r.i; }
bool operator<=(Byte_Iterator const& r) const { return i <= r.i; }
bool operator>(Byte_Iterator const& r) const { return i > r.i; }
Expand Down
35 changes: 35 additions & 0 deletions test/test_byte_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,46 @@ int main() {
for(const auto& s : vec_sentences) {
for(int i = 0; i < s.size(); i++) {
ASSERT_RELEASE(s[i] == (char)(*bv_it) && s[i] == (*str_it));
ASSERT_RELEASE(s[i] == (char)bv_it->() && s[i] == (*str_it));
bv_it++;
str_it++;
}
}
}

{
// iterator operator tests
auto test_it1 = buffer.begin();
auto test_it2 = buffer.begin();
// Testing logical Operators
ASSERT_RELEASE(test_it1 == test_it2);
ASSERT_RELEASE(test_it1 <= test_it2);
ASSERT_RELEASE(test_it1 >= test_it2);
test_it2++;
ASSERT_RELEASE(test_it1 != test_it2);
ASSERT_RELEASE(test_it1 < test_it2);
ASSERT_RELEASE(test_it1 <= test_it2);
ASSERT_RELEASE(test_it2 > test_it1);
ASSERT_RELEASE(test_it2 >= test_it1);
test_it2--;
ASSERT_RELEASE(test_it1 == test_it2);
test_it2 += 3; // testing +=
ASSERT_RELEASE(test_it1[3] == test_it2); // testing [] operator
test_it2 -= 3; // testing -=
ASSERT_RELEASE(test_it1 == test_it2);

//testing postfix and prefix operators
ASSERT_RELEASE(test_it1 == test_it2++);
ASSERT_RELEASE(test_it1 == --test_it2);

ASSERT_RELEASE(!(test_it1 < test_it2++));
ASSERT_RELEASE(!(test_it1 > --test_it2));

test_it2++; // test_it1 is at 0, test_it2 is at 1
ASSERT_RELEASE(test_it1 != test_it2--);
ASSERT_RELEASE(test_it1 == test_it2);
ASSERT_RELEASE(test_it1 < ++test_it2);
}

return 0;
}

0 comments on commit 3abb92f

Please sign in to comment.