File: test_algorithms.cpp

package info (click to toggle)
frozen 1.2.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,244 kB
  • sloc: cpp: 18,992; ansic: 788; makefile: 77
file content (30 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}