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//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// <chrono>
12
13// duration
14
15// template<class Rep1, class Period1, class Rep2, class Period2>
16// requires ThreeWayComparable<typename CT::rep>
17// constexpr auto operator<=>(const duration<Rep1, Period1>& lhs,
18// const duration<Rep2, Period2>& rhs);
19
20#include <cassert>
21#include <chrono>
22#include <ratio>
23
24#include "test_comparisons.h"
25
26constexpr bool test() {
27 {
28 std::chrono::seconds s1(3);
29 std::chrono::seconds s2(3);
30 assert((s1 <=> s2) == std::strong_ordering::equal);
31 assert(testOrder(s1, s2, std::strong_ordering::equal));
32 }
33 {
34 std::chrono::seconds s1(3);
35 std::chrono::seconds s2(4);
36 assert((s1 <=> s2) == std::strong_ordering::less);
37 assert(testOrder(s1, s2, std::strong_ordering::less));
38 }
39 {
40 std::chrono::milliseconds s1(3);
41 std::chrono::microseconds s2(3000);
42 assert((s1 <=> s2) == std::strong_ordering::equal);
43 assert(testOrder(s1, s2, std::strong_ordering::equal));
44 }
45 {
46 std::chrono::milliseconds s1(3);
47 std::chrono::microseconds s2(4000);
48 assert((s1 <=> s2) == std::strong_ordering::less);
49 assert(testOrder(s1, s2, std::strong_ordering::less));
50 }
51 {
52 std::chrono::duration<int, std::ratio<2, 3>> s1(9);
53 std::chrono::duration<int, std::ratio<3, 5>> s2(10);
54 assert((s1 <=> s2) == std::strong_ordering::equal);
55 assert(testOrder(s1, s2, std::strong_ordering::equal));
56 }
57 {
58 std::chrono::duration<int, std::ratio<2, 3>> s1(10);
59 std::chrono::duration<int, std::ratio<3, 5>> s2(9);
60 assert((s1 <=> s2) == std::strong_ordering::greater);
61 assert(testOrder(s1, s2, std::strong_ordering::greater));
62 }
63 {
64 std::chrono::duration<int, std::ratio<2, 3>> s1(9);
65 std::chrono::duration<double, std::ratio<3, 5>> s2(10.1);
66 assert((s1 <=> s2) == std::strong_ordering::less);
67 assert(testOrder(s1, s2, std::strong_ordering::less));
68 }
69
70 return true;
71}
72
73int main(int, char**) {
74 assert(test());
75 static_assert(test());
76 return 0;
77}
78

source code of libcxx/test/std/time/time.duration/time.duration.comparisons/compare.three_way.pass.cpp