-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestQuantityPow.cpp
More file actions
48 lines (43 loc) · 1.69 KB
/
TestQuantityPow.cpp
File metadata and controls
48 lines (43 loc) · 1.69 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#define BOOST_TEST_MODULE TestQuantityPow
#include "../CtUnits/ctu/Quantity.hpp"
#include <boost/mp11.hpp>
#include <boost/static_assert.hpp>
#include <boost/test/included/unit_test.hpp>
#include <ratio>
#include <type_traits>
constexpr auto get_example_quantity()
{
using example_unit_dim = ctu::UdMap<
ctu::UnitDimension<bool, 1>, ctu::UnitDimension<char, -3>,
ctu::UnitDimension<int, 5>>;
return ctu::Quantity<long double, example_unit_dim>(4.0L);
}
BOOST_AUTO_TEST_CASE(TestPowWithNaturalPower)
{
const auto expected = ctu::Quantity<
long double,
ctu::UdMap<
ctu::UnitDimension<bool, 2>, ctu::UnitDimension<char, -6>,
ctu::UnitDimension<int, 10>>>(16.0L);
const auto actual = get_example_quantity().pow<std::ratio<2>>();
static_assert(std::is_same_v<decltype(actual), decltype(expected)>);
BOOST_TEST(actual.get_value() == expected.get_value());
}
BOOST_AUTO_TEST_CASE(TestPowWithFractionalPower)
{
const auto expected = ctu::Quantity<
long double,
ctu::UdMap<
ctu::UnitDimension<bool, 1, 2>, ctu::UnitDimension<char, -3, 2>,
ctu::UnitDimension<int, 5, 2>>>(2.0L);
const auto actual = get_example_quantity().pow<std::ratio<1, 2>>();
static_assert(std::is_same_v<decltype(actual), decltype(expected)>);
BOOST_TEST(actual.get_value() == expected.get_value());
}
BOOST_AUTO_TEST_CASE(TestPowWithZeroPower)
{
const auto expected = ctu::Quantity<long double, ctu::UdMap<>>(1.0L);
const auto actual = get_example_quantity().pow<std::ratio<0>>();
static_assert(std::is_same_v<decltype(actual), decltype(expected)>);
BOOST_TEST(actual.get_value() == expected.get_value());
}