From 96fc17b99d56eb636c894c5be9ab39bfdb4ba454 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 27 Aug 2022 00:55:38 -0400 Subject: Initial code dump. --- tests/compressed_vector.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/compressed_vector.cpp (limited to 'tests/compressed_vector.cpp') diff --git a/tests/compressed_vector.cpp b/tests/compressed_vector.cpp new file mode 100644 index 0000000..a5d76e4 --- /dev/null +++ b/tests/compressed_vector.cpp @@ -0,0 +1,72 @@ +#include "compressed_vector.hpp" + +#include +#include +#include +#include +#include +#include + +int main() +{ + compressed_vector cv; + compressed_vector cv2; + std::vector v; + srand(time(NULL)); + for (int i = 0; i < 100; ++i) + { + int r = rand() % 8; + cv.push_back(r); + v.push_back(r); + } + for (int i = 0; i < 100; ++i) + { + if (cv.get(i) != v[i]) + { + printf("%u <=> %u @ %d\n", cv.get(i), v[i], i); + throw std::runtime_error(std::to_string(__LINE__)); + } + } + for (int i = 0; i < 1000; ++i) + { + if (rand() % 3) + { + int r = rand() % 8; + cv.push_back(r); + v.push_back(r); + } + else + { + if (cv.back() != v.back()) + throw std::runtime_error(std::to_string(__LINE__)); + cv.pop_back(); + v.pop_back(); + } + } + if (cv.size() != v.size()) + throw std::runtime_error(std::to_string(__LINE__)); + for (size_t i = 0; i < v.size(); ++i) + { + if (cv.get(i) != v[i]) + { + printf("%u <=> %u @ %lu\n", cv.get(i), v[i], i); + throw std::runtime_error(std::to_string(__LINE__)); + } + cv2.push_back(cv.get(i)); + } + for (size_t i = 0; i < v.size(); ++i) + { + if (cv.get(i) != cv2.get(i)) + { + throw std::runtime_error(std::to_string(__LINE__)); + } + } + size_t h1 = compressed_vector_hash{}(cv); + size_t h2 = compressed_vector_hash{}(cv2); + if (h1 != h2) + { + printf("%lu <=> %lu\n", h1, h2); + throw std::runtime_error(std::to_string(__LINE__)); + } + return 0; +} -- cgit v1.2.3