source: mainline/uspace/lib/cpp/src/__bits/test/ratio.cpp@ c6f23a7

Last change on this file since c6f23a7 was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update headers in C++ files

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <__bits/test/tests.hpp>
8#include <initializer_list>
9#include <ratio>
10#include <utility>
11
12namespace std::test
13{
14 bool ratio_test::run(bool report)
15 {
16 report_ = report;
17 start();
18
19 test_eq(
20 "ratio_add pt1",
21 std::ratio_add<std::ratio<2, 3>, std::ratio<1, 6>>::num,
22 5
23 );
24 test_eq(
25 "ratio_add pt2",
26 std::ratio_add<std::ratio<2, 3>, std::ratio<1, 6>>::den,
27 6
28 );
29
30 test_eq(
31 "ratio_subtract pt1",
32 std::ratio_subtract<std::ratio<2, 3>, std::ratio<1, 6>>::num,
33 1
34 );
35 test_eq(
36 "ratio_subtract pt2",
37 std::ratio_subtract<std::ratio<2, 3>, std::ratio<1, 6>>::den,
38 2
39 );
40
41 test_eq(
42 "ratio_multiply pt1",
43 std::ratio_multiply<std::ratio<2, 3>, std::ratio<1, 6>>::num,
44 1
45 );
46 test_eq(
47 "ratio_multiply pt2",
48 std::ratio_multiply<std::ratio<2, 3>, std::ratio<1, 6>>::den,
49 9
50 );
51
52 test_eq(
53 "ratio_divide pt1",
54 std::ratio_divide<std::ratio<2, 3>, std::ratio<1, 6>>::num,
55 4
56 );
57 test_eq(
58 "ratio_divide pt2",
59 std::ratio_divide<std::ratio<2, 3>, std::ratio<1, 6>>::den,
60 1
61 );
62
63 test_eq(
64 "ratio_equal", std::ratio_equal_v<std::ratio<2, 3>, std::ratio<6, 9>>, true
65 );
66
67 test_eq(
68 "ratio_not_equal", std::ratio_not_equal_v<std::ratio<2, 3>, std::ratio<5, 9>>, true
69 );
70
71 test_eq(
72 "ratio_less", std::ratio_less_v<std::ratio<2, 3>, std::ratio<5, 6>>, true
73 );
74
75 test_eq(
76 "ratio_less_equal pt1", std::ratio_less_equal_v<std::ratio<2, 3>, std::ratio<5, 6>>, true
77 );
78
79 test_eq(
80 "ratio_less_equal pt2", std::ratio_less_equal_v<std::ratio<2, 3>, std::ratio<2, 3>>, true
81 );
82
83 test_eq(
84 "ratio_greater", std::ratio_greater_v<std::ratio<2, 3>, std::ratio<2, 6>>, true
85 );
86
87 test_eq(
88 "ratio_greater_equal pt1", std::ratio_greater_equal_v<std::ratio<2, 3>, std::ratio<2, 6>>, true
89 );
90
91 test_eq(
92 "ratio_greater_equal pt2", std::ratio_greater_equal_v<std::ratio<2, 3>, std::ratio<2, 3>>, true
93 );
94
95 return end();
96 }
97
98 const char* ratio_test::name()
99 {
100 return "ratio";
101 }
102}
Note: See TracBrowser for help on using the repository browser.