[PassBuilder] VectorizerEnd Extension Points (#123494)
[llvm-project.git] / libcxx / test / std / time / time.cal / time.cal.ymd / time.cal.ymd.nonmembers / comparisons.pass.cpp
blobafc9f5d3d7666f834658b2838f495e346ce4bf1c
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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // <chrono>
11 // class year_month_day;
13 // constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
14 // constexpr strong_ordering operator<=>(const year_month_day& x, const year_month_day& y) noexcept;
16 #include <chrono>
17 #include <type_traits>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "test_comparisons.h"
23 constexpr bool test() {
24 using day = std::chrono::day;
25 using year = std::chrono::year;
26 using month = std::chrono::month;
27 using year_month_day = std::chrono::year_month_day;
29 constexpr month January = std::chrono::January;
30 constexpr month February = std::chrono::February;
32 assert(testOrder(
33 year_month_day{year{1234}, January, day{1}},
34 year_month_day{year{1234}, January, day{1}},
35 std::strong_ordering::equal));
37 // different day
38 assert(testOrder(
39 year_month_day{year{1234}, January, day{1}},
40 year_month_day{year{1234}, January, day{2}},
41 std::strong_ordering::less));
43 // different month
44 assert(testOrder(
45 year_month_day{year{1234}, January, day{1}},
46 year_month_day{year{1234}, February, day{1}},
47 std::strong_ordering::less));
49 // different year
50 assert(testOrder(
51 year_month_day{year{1234}, January, day{1}},
52 year_month_day{year{1235}, January, day{1}},
53 std::strong_ordering::less));
55 // different month and day
56 assert(testOrder(
57 year_month_day{year{1234}, January, day{2}},
58 year_month_day{year{1234}, February, day{1}},
59 std::strong_ordering::less));
61 // different year and month
62 assert(testOrder(
63 year_month_day{year{1234}, February, day{1}},
64 year_month_day{year{1235}, January, day{1}},
65 std::strong_ordering::less));
67 // different year and day
68 assert(testOrder(
69 year_month_day{year{1234}, January, day{2}},
70 year_month_day{year{1235}, January, day{1}},
71 std::strong_ordering::less));
73 // different year, month and day
74 assert(testOrder(
75 year_month_day{year{1234}, February, day{2}},
76 year_month_day{year{1235}, January, day{1}},
77 std::strong_ordering::less));
79 // same year, different days
80 for (unsigned i = 1; i < 28; ++i)
81 for (unsigned j = 1; j < 28; ++j)
82 assert((testOrder(
83 year_month_day{year{1234}, January, day{i}},
84 year_month_day{year{1234}, January, day{j}},
85 i == j ? std::strong_ordering::equal
86 : i < j ? std::strong_ordering::less
87 : std::strong_ordering::greater)));
89 // same year, different months
90 for (unsigned i = 1; i < 12; ++i)
91 for (unsigned j = 1; j < 12; ++j)
92 assert((testOrder(
93 year_month_day{year{1234}, month{i}, day{12}},
94 year_month_day{year{1234}, month{j}, day{12}},
95 i == j ? std::strong_ordering::equal
96 : i < j ? std::strong_ordering::less
97 : std::strong_ordering::greater)));
99 // same month, different years
100 for (int i = -5; i < 5; ++i)
101 for (int j = -5; j < 5; ++j)
102 assert((testOrder(
103 year_month_day{year{i}, January, day{12}},
104 year_month_day{year{j}, January, day{12}},
105 i == j ? std::strong_ordering::equal
106 : i < j ? std::strong_ordering::less
107 : std::strong_ordering::greater)));
109 return true;
112 int main(int, char**) {
113 using year_month_day = std::chrono::year_month_day;
114 AssertOrderAreNoexcept<year_month_day>();
115 AssertOrderReturn<std::strong_ordering, year_month_day>();
117 test();
118 static_assert(test());
120 return 0;