From 3abb92f098077ae314dd7a56fcf72f8b382f878b Mon Sep 17 00:00:00 2001 From: ryan-dozier Date: Thu, 31 Oct 2024 12:03:56 -0400 Subject: [PATCH] Updating byte_vector to remove some unused functions. Also adding better test coverage to the test_byte_vector --- include/ygm/detail/byte_vector.hpp | 3 --- test/test_byte_vector.cpp | 35 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/ygm/detail/byte_vector.hpp b/include/ygm/detail/byte_vector.hpp index 0959f965..459e4507 100644 --- a/include/ygm/detail/byte_vector.hpp +++ b/include/ygm/detail/byte_vector.hpp @@ -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: @@ -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; } diff --git a/test/test_byte_vector.cpp b/test/test_byte_vector.cpp index 4ddc3878..dfb51d1c 100644 --- a/test/test_byte_vector.cpp +++ b/test/test_byte_vector.cpp @@ -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; } \ No newline at end of file