diff options
author | David Robillard <d@drobilla.net> | 2018-08-18 23:11:28 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-29 14:47:23 +0200 |
commit | 967d2ac6c2034d1374fc603e64212fc06b5f6133 (patch) | |
tree | 7b9caa51edf7d4a4a4a4d50f33b0aebfffc6ead4 | |
parent | 81f652c80c086ea008a4cd325f4e73764a9aa10a (diff) | |
download | chilbert-967d2ac6c2034d1374fc603e64212fc06b5f6133.tar.gz chilbert-967d2ac6c2034d1374fc603e64212fc06b5f6133.tar.bz2 chilbert-967d2ac6c2034d1374fc603e64212fc06b5f6133.zip |
Add tests for left and right rotation
-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); |