summaryrefslogtreecommitdiffstats
path: root/tests/test_algorithms.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:39:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:39:03 +0000
commit408c608fc7bf1557ee987dd7fbe662fabed21a53 (patch)
tree8b07135336de378134bfedc808d49747174810d3 /tests/test_algorithms.cpp
parentInitial commit. (diff)
downloadfrozen-upstream.tar.xz
frozen-upstream.zip
Adding upstream version 1.1.1.upstream/1.1.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_algorithms.cpp')
-rw-r--r--tests/test_algorithms.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_algorithms.cpp b/tests/test_algorithms.cpp
new file mode 100644
index 0000000..b0ecc83
--- /dev/null
+++ b/tests/test_algorithms.cpp
@@ -0,0 +1,30 @@
+#include <algorithm>
+#include <frozen/bits/algorithms.h>
+#include <iostream>
+
+#include "bench.hpp"
+#include "catch.hpp"
+
+TEST_CASE("next_highest_power_of_two", "[algorithm]") {
+ REQUIRE(frozen::bits::next_highest_power_of_two(1) == 1);
+ REQUIRE(frozen::bits::next_highest_power_of_two(2) == 2);
+ REQUIRE(frozen::bits::next_highest_power_of_two(3) == 4);
+ REQUIRE(frozen::bits::next_highest_power_of_two(4) == 4);
+ REQUIRE(frozen::bits::next_highest_power_of_two(5) == 8);
+ REQUIRE(frozen::bits::next_highest_power_of_two(6) == 8);
+ REQUIRE(frozen::bits::next_highest_power_of_two(7) == 8);
+ REQUIRE(frozen::bits::next_highest_power_of_two(8) == 8);
+ REQUIRE(frozen::bits::next_highest_power_of_two(16) == 16);
+}
+
+TEST_CASE("log", "[algorithm]") {
+ REQUIRE(frozen::bits::log(1) == 0);
+ REQUIRE(frozen::bits::log(2) == 1);
+ REQUIRE(frozen::bits::log(3) == 1);
+ REQUIRE(frozen::bits::log(4) == 2);
+ REQUIRE(frozen::bits::log(5) == 2);
+ REQUIRE(frozen::bits::log(7) == 2);
+ REQUIRE(frozen::bits::log(8) == 3);
+ REQUIRE(frozen::bits::log(16) == 4);
+ REQUIRE(frozen::bits::log(32) == 5);
+}