[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / time / time.point / time.point.comparisons / compare.three_way.pass.cpp
blobaed80138303e936e0ba156293303d2c8aaa3d19b
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // <chrono>
13 // time_point
15 // template<class Clock, class Duration1,
16 // three_way_comparable_with<Duration1> Duration2>
17 // constexpr auto operator<=>(const time_point<Clock, Duration1>& lhs,
18 // const time_point<Clock, Duration2>& rhs);
20 #include <cassert>
21 #include <chrono>
22 #include <ratio>
24 #include "test_comparisons.h"
26 constexpr void test_with_integral_ticks_value() {
27 using Clock = std::chrono::system_clock;
29 using Duration1 = std::chrono::milliseconds;
30 using Duration2 = std::chrono::microseconds;
31 using T1 = std::chrono::time_point<Clock, Duration1>;
32 using T2 = std::chrono::time_point<Clock, Duration2>;
35 T1 t1(Duration1(3));
36 T1 t2(Duration1(3));
37 assert((t1 <=> t2) == std::strong_ordering::equal);
38 assert(testOrder(t1, t2, std::strong_ordering::equal));
41 T1 t1(Duration1(3));
42 T1 t2(Duration1(4));
43 assert((t1 <=> t2) == std::strong_ordering::less);
44 assert(testOrder(t1, t2, std::strong_ordering::less));
47 T1 t1(Duration1(3));
48 T2 t2(Duration2(3000));
49 assert((t1 <=> t2) == std::strong_ordering::equal);
50 assert(testOrder(t1, t2, std::strong_ordering::equal));
53 T1 t1(Duration1(3));
54 T2 t2(Duration2(3001));
55 assert((t1 <=> t2) == std::strong_ordering::less);
56 assert(testOrder(t1, t2, std::strong_ordering::less));
57 assert((t2 <=> t1) == std::strong_ordering::greater);
58 assert(testOrder(t2, t1, std::strong_ordering::greater));
62 constexpr void test_with_integral_ticks_value_and_custom_period_value() {
63 using Clock = std::chrono::system_clock;
65 using DInt30Hz = std::chrono::duration<int, std::ratio<1, 30>>;
66 using DInt60Hz = std::chrono::duration<int, std::ratio<1, 60>>;
68 using TIntR1 = std::chrono::time_point<Clock, DInt30Hz>;
69 using TIntR2 = std::chrono::time_point<Clock, DInt60Hz>;
72 TIntR1 t1(DInt30Hz(10));
73 TIntR2 t2(DInt60Hz(20));
74 assert((t1 <=> t2) == std::strong_ordering::equal);
75 assert(testOrder(t1, t2, std::strong_ordering::equal));
78 TIntR1 t1(DInt30Hz(10));
79 TIntR2 t2(DInt60Hz(21));
80 assert((t1 <=> t2) == std::strong_ordering::less);
81 assert(testOrder(t1, t2, std::strong_ordering::less));
84 TIntR1 t1(DInt30Hz(11));
85 TIntR2 t2(DInt60Hz(20));
86 assert((t1 <=> t2) == std::strong_ordering::greater);
87 assert(testOrder(t1, t2, std::strong_ordering::greater));
91 constexpr void test_with_floating_point_ticks_value() {
92 using Clock = std::chrono::system_clock;
94 using DF30Hz = std::chrono::duration<double, std::ratio<1, 30>>;
95 using DF60Hz = std::chrono::duration<double, std::ratio<1, 60>>;
96 using F1 = std::chrono::time_point<Clock, DF30Hz>;
97 using F2 = std::chrono::time_point<Clock, DF60Hz>;
99 // No equality comparison test for floating point values.
102 F1 t1(DF30Hz(3.5));
103 F2 t2(DF60Hz(7.1));
104 assert((t1 <=> t2) == std::weak_ordering::less);
105 assert(testOrder(t1, t2, std::weak_ordering::less));
108 F1 t1(DF30Hz(3.6));
109 F2 t2(DF60Hz(7.0));
110 assert((t1 <=> t2) == std::weak_ordering::greater);
111 assert(testOrder(t1, t2, std::weak_ordering::greater));
115 constexpr bool test() {
116 test_with_integral_ticks_value();
117 test_with_integral_ticks_value_and_custom_period_value();
118 test_with_floating_point_ticks_value();
120 return true;
123 int main(int, char**) {
124 assert(test());
125 static_assert(test());
126 return 0;