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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4960254 was 4960254, checked in by Dzejrou <dzejrou@…>, 7 years ago

cpp: added ratio tests

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2018 Jaroslav Jindrak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <__bits/test/tests.hpp>
30#include <initializer_list>
31#include <ratio>
32#include <utility>
33
34namespace std::test
35{
36 bool ratio_test::run(bool report)
37 {
38 report_ = report;
39 start();
40
41 test_eq(
42 "ratio_add pt1",
43 std::ratio_add<std::ratio<2, 3>, std::ratio<1, 6>>::num,
44 5
45 );
46 test_eq(
47 "ratio_add pt2",
48 std::ratio_add<std::ratio<2, 3>, std::ratio<1, 6>>::den,
49 6
50 );
51
52 test_eq(
53 "ratio_subtract pt1",
54 std::ratio_subtract<std::ratio<2, 3>, std::ratio<1, 6>>::num,
55 1
56 );
57 test_eq(
58 "ratio_subtract pt2",
59 std::ratio_subtract<std::ratio<2, 3>, std::ratio<1, 6>>::den,
60 2
61 );
62
63 test_eq(
64 "ratio_multiply pt1",
65 std::ratio_multiply<std::ratio<2, 3>, std::ratio<1, 6>>::num,
66 1
67 );
68 test_eq(
69 "ratio_multiply pt2",
70 std::ratio_multiply<std::ratio<2, 3>, std::ratio<1, 6>>::den,
71 9
72 );
73
74 test_eq(
75 "ratio_divide pt1",
76 std::ratio_divide<std::ratio<2, 3>, std::ratio<1, 6>>::num,
77 4
78 );
79 test_eq(
80 "ratio_divide pt2",
81 std::ratio_divide<std::ratio<2, 3>, std::ratio<1, 6>>::den,
82 1
83 );
84
85 test_eq(
86 "ratio_equal", std::ratio_equal_v<std::ratio<2, 3>, std::ratio<6, 9>>, true
87 );
88
89 test_eq(
90 "ratio_not_equal", std::ratio_not_equal_v<std::ratio<2, 3>, std::ratio<5, 9>>, true
91 );
92
93 test_eq(
94 "ratio_less", std::ratio_less_v<std::ratio<2, 3>, std::ratio<5, 6>>, true
95 );
96
97 test_eq(
98 "ratio_less_equal pt1", std::ratio_less_equal_v<std::ratio<2, 3>, std::ratio<5, 6>>, true
99 );
100
101 test_eq(
102 "ratio_less_equal pt2", std::ratio_less_equal_v<std::ratio<2, 3>, std::ratio<2, 3>>, true
103 );
104
105 test_eq(
106 "ratio_greater", std::ratio_greater_v<std::ratio<2, 3>, std::ratio<2, 6>>, true
107 );
108
109 test_eq(
110 "ratio_greater_equal pt1", std::ratio_greater_equal_v<std::ratio<2, 3>, std::ratio<2, 6>>, true
111 );
112
113 test_eq(
114 "ratio_greater_equal pt2", std::ratio_greater_equal_v<std::ratio<2, 3>, std::ratio<2, 3>>, true
115 );
116
117 return end();
118 }
119
120 const char* ratio_test::name()
121 {
122 return "ratio";
123 }
124}
Note: See TracBrowser for help on using the repository browser.