diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-05-26 00:47:54 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-05-26 00:48:06 +0200 |
commit | a1db1cd9e22e77041d5f1360f1d1ccdc52b86306 (patch) | |
tree | c1cc6dc9c17885a0789028f7a55c7126f33beee7 /asl/base/numeric_tests.cpp | |
parent | 54b95b16629f0cd4bc30e6899e00019b3ab94012 (diff) |
Implement chunked_buffer
Diffstat (limited to 'asl/base/numeric_tests.cpp')
-rw-r--r-- | asl/base/numeric_tests.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/asl/base/numeric_tests.cpp b/asl/base/numeric_tests.cpp index cfbc1ac..afcc12a 100644 --- a/asl/base/numeric_tests.cpp +++ b/asl/base/numeric_tests.cpp @@ -13,4 +13,56 @@ ASL_TEST(is_pow2) ASL_TEST_EXPECT(!asl::is_pow2(6)); ASL_TEST_EXPECT(!asl::is_pow2(1978)); ASL_TEST_EXPECT(!asl::is_pow2(0)); + ASL_TEST_EXPECT(asl::is_pow2(4U)); + ASL_TEST_EXPECT(asl::is_pow2(uint64_t{65536})); +} + +ASL_TEST(round_down_pow2) // NOLINT +{ + ASL_TEST_EXPECT(asl::round_down_pow2(0, 1) == 0); + ASL_TEST_EXPECT(asl::round_down_pow2(1, 1) == 1); + ASL_TEST_EXPECT(asl::round_down_pow2(2, 1) == 2); + ASL_TEST_EXPECT(asl::round_down_pow2(3, 1) == 3); + ASL_TEST_EXPECT(asl::round_down_pow2(-1, 1) == -1); + ASL_TEST_EXPECT(asl::round_down_pow2(-2, 1) == -2); + ASL_TEST_EXPECT(asl::round_down_pow2(-3, 1) == -3); + + ASL_TEST_EXPECT(asl::round_down_pow2(0U, 1U) == 0U); + ASL_TEST_EXPECT(asl::round_down_pow2(1U, 1U) == 1U); + ASL_TEST_EXPECT(asl::round_down_pow2(2U, 1U) == 2U); + ASL_TEST_EXPECT(asl::round_down_pow2(3U, 1U) == 3U); + + ASL_TEST_EXPECT(asl::round_down_pow2(0, 16) == 0); + ASL_TEST_EXPECT(asl::round_down_pow2(1, 16) == 0); + ASL_TEST_EXPECT(asl::round_down_pow2(8, 16) == 0); + ASL_TEST_EXPECT(asl::round_down_pow2(15, 16) == 0); + ASL_TEST_EXPECT(asl::round_down_pow2(16, 16) == 16); + ASL_TEST_EXPECT(asl::round_down_pow2(17, 16) == 16); + ASL_TEST_EXPECT(asl::round_down_pow2(255, 16) == 240); + ASL_TEST_EXPECT(asl::round_down_pow2(-255, 16) == -256); +} + +ASL_TEST(round_up_pow2) // NOLINT +{ + ASL_TEST_EXPECT(asl::round_up_pow2(0, 1) == 0); + ASL_TEST_EXPECT(asl::round_up_pow2(1, 1) == 1); + ASL_TEST_EXPECT(asl::round_up_pow2(2, 1) == 2); + ASL_TEST_EXPECT(asl::round_up_pow2(3, 1) == 3); + ASL_TEST_EXPECT(asl::round_up_pow2(-1, 1) == -1); + ASL_TEST_EXPECT(asl::round_up_pow2(-2, 1) == -2); + ASL_TEST_EXPECT(asl::round_up_pow2(-3, 1) == -3); + + ASL_TEST_EXPECT(asl::round_up_pow2(0U, 1U) == 0U); + ASL_TEST_EXPECT(asl::round_up_pow2(1U, 1U) == 1U); + ASL_TEST_EXPECT(asl::round_up_pow2(2U, 1U) == 2U); + ASL_TEST_EXPECT(asl::round_up_pow2(3U, 1U) == 3U); + + ASL_TEST_EXPECT(asl::round_up_pow2(0, 16) == 0); + ASL_TEST_EXPECT(asl::round_up_pow2(1, 16) == 16); + ASL_TEST_EXPECT(asl::round_up_pow2(8, 16) == 16); + ASL_TEST_EXPECT(asl::round_up_pow2(15, 16) == 16); + ASL_TEST_EXPECT(asl::round_up_pow2(16, 16) == 16); + ASL_TEST_EXPECT(asl::round_up_pow2(17, 16) == 32); + ASL_TEST_EXPECT(asl::round_up_pow2(255, 16) == 256); + ASL_TEST_EXPECT(asl::round_up_pow2(-255, 16) == -240); } |