units
Use physical dimensions at compile-time or run-time.
bit-range-test.cpp
Go to the documentation of this file.
1 /// @file test/bit-range-test.cpp
2 /// @brief Test-cases for vnix::bit_range.
3 /// @copyright 2019 Thomas E. Vaughan; all rights reserved.
4 /// @license BSD three-clause; see LICENSE.
5 
6 #include "../vnix/bit-range.hpp"
7 #include "catch.hpp"
8 
9 using namespace vnix;
10 
11 
12 TEST_CASE("Bit can be set.", "[bit]") {
13  REQUIRE(bit<uint8_t>(0) == 0x01);
14  REQUIRE(bit<uint8_t>(1) == 0x02);
15  REQUIRE(bit<uint8_t>(2) == 0x04);
16  REQUIRE(bit<uint8_t>(3) == 0x08);
17  REQUIRE(bit<uint8_t>(4) == 0x10);
18  REQUIRE(bit<uint8_t>(5) == 0x20);
19  REQUIRE(bit<uint8_t>(6) == 0x40);
20  REQUIRE(bit<uint8_t>(7) == 0x80);
21 }
22 
23 
24 TEST_CASE("Bit-range can be set.", "[bit-range]") {
25  for (unsigned off1 = 0; off1 < 8; ++off1) {
26  for (unsigned off2 = 0; off2 < 8; ++off2) {
27  uint8_t truth = 0;
28  if (off1 < off2) {
29  for (unsigned i = off1; i <= off2; ++i) { truth |= (1 << i); }
30  } else {
31  for (unsigned i = off2; i <= off1; ++i) { truth |= (1 << i); }
32  }
33  REQUIRE(bit_range<uint8_t>(off1, off2) == truth);
34  }
35  }
36 }
Thomas E. Vaughan&#39;s public software.
Definition: rational.hpp:13
constexpr I bit_range(unsigned n1, unsigned n2)
Word with specified range of bits set.
Definition: bit-range.hpp:22
constexpr I bit(unsigned n)
Word with specified bit set.
Definition: bit-range.hpp:15