units
Use physical dimensions at compile-time or run-time.
normalized-pair-test.cpp
Go to the documentation of this file.
1 /// @file test/normalized-pair-test.cpp
2 /// @brief Test-cases for vnix::rat::normalized_pair.
3 /// @copyright 2019 Thomas E. Vaughan; all rights reserved.
4 /// @license BSD three-clause; see LICENSE.
5 
6 #include "../vnix/rat/normalized-pair.hpp"
7 #include "catch.hpp"
8 
9 using normalized_pair = vnix::rat::normalized_pair<5, 3>;
10 
11 
12 TEST_CASE("Input fraction has positive denominator.", "[normalized-pair]") {
13  normalized_pair const p(3, -2);
14  REQUIRE(p.n() == -3);
15  REQUIRE(p.d() == +2);
16 }
17 
18 
19 TEST_CASE("Input fraction is reduced.", "[normalized-pair]") {
20  normalized_pair const p(-4, 6);
21  REQUIRE(p.n() == -2);
22  REQUIRE(p.d() == +3);
23 }
24 
25 
26 TEST_CASE("Throw on division by zero.", "[normalized-pair]") {
27  REQUIRE_THROWS(normalized_pair(1, 0));
28 }
29 
30 
31 TEST_CASE("Limits are as expected.", "[normalized-pair]") {
32  REQUIRE_NOTHROW(normalized_pair(-16, 1));
33  REQUIRE_THROWS(normalized_pair(-17, 1));
34 
35  REQUIRE_NOTHROW(normalized_pair(+15, 1));
36  REQUIRE_THROWS(normalized_pair(+16, 1));
37 
38  REQUIRE_NOTHROW(normalized_pair(+1, 8));
39  REQUIRE_THROWS(normalized_pair(+1, 9));
40 }
constexpr S n() const
Normalized numerator.
Numerator and denominator of a rational number as separate numbers, not encoded into the same word...
constexpr normalized_pair(S nn, S dd)
Initialize normalized numerator and denominator for encoding of rational number.
Thomas E. Vaughan&#39;s public software.
Definition: rational.hpp:13
constexpr U d() const
Normalized denominator.
Classes and functions supporting a model of a fixed-precision rational number.
Definition: rational.hpp:17