diff options
-rw-r--r-- | test/test_bitvec.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/test_bitvec.cpp b/test/test_bitvec.cpp index 78a8272..2fa62ca 100644 --- a/test/test_bitvec.cpp +++ b/test/test_bitvec.cpp @@ -197,6 +197,40 @@ test_right_shift(Context& ctx) template <class T, size_t N> void +test_left_rotate(Context& ctx) +{ + const T v = make_random_bitvec<T, N>(ctx); + for (size_t width = 0; width < std::min(N, size_t(128)); ++width) { + for (size_t bits = 0; bits <= width; ++bits) { + T r = v; + r.rotl(bits, width); + + for (size_t i = 0; i < width; ++i) { + assert(r.test((i + bits) % width) == v.test(i)); + } + } + } +} + +template <class T, size_t N> +void +test_right_rotate(Context& ctx) +{ + const T v = make_random_bitvec<T, N>(ctx); + for (size_t width = 0; width < std::min(N, size_t(128)); ++width) { + for (size_t bits = 0; bits <= width; ++bits) { + T r = v; + r.rotr(bits, width); + + for (size_t i = 0; i < width; ++i) { + assert(r.test(i) == v.test((i + bits) % width)); + } + } + } +} + +template <class T, size_t N> +void test_find_first(Context&) { T v = make_zero_bitvec<T, N>(); @@ -283,6 +317,8 @@ test(Context& ctx) test_reset_all<T, N>(ctx); test_left_shift<T, N>(ctx); test_right_shift<T, N>(ctx); + test_left_rotate<T, N>(ctx); + test_right_rotate<T, N>(ctx); test_find_first<T, N>(ctx); test_gray_code<T, N>(ctx); test_comparison<T, N>(ctx); |