| 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 |
| 9 |
|
| 10 |
// <chrono> |
| 11 |
// class year_month_weekday_last; |
| 12 |
|
| 13 |
// constexpr bool operator==(const year_month_weekday_last& x, const year_month_weekday_last& y) noexcept; |
| 14 |
// Returns: x.year() == y.year() && x.month() == y.month() && x.weekday_last() == y.weekday_last() |
| 15 |
// |
| 16 |
|
| 17 |
|
| 18 |
#include <chrono> |
| 19 |
#include <type_traits> |
| 20 |
#include <cassert> |
| 21 |
|
| 22 |
#include "test_macros.h" |
| 23 |
#include "test_comparisons.h" |
| 24 |
|
| 25 |
int main(int, char**) |
| 26 |
{ |
| 27 |
using year = std::chrono::year; |
| 28 |
using month = std::chrono::month; |
| 29 |
using weekday = std::chrono::weekday; |
| 30 |
using weekday_last = std::chrono::weekday_last; |
| 31 |
using year_month_weekday_last = std::chrono::year_month_weekday_last; |
| 32 |
|
| 33 |
AssertEqualityAreNoexcept<year_month_weekday_last>(); |
| 34 |
AssertEqualityReturnBool<year_month_weekday_last>(); |
| 35 |
|
| 36 |
constexpr month January = std::chrono::January; |
| 37 |
constexpr month February = std::chrono::February; |
| 38 |
constexpr weekday Tuesday = std::chrono::Tuesday; |
| 39 |
constexpr weekday Wednesday = std::chrono::Wednesday; |
| 40 |
|
| 41 |
static_assert( testEquality( |
| 42 |
year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, |
| 43 |
year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, |
| 44 |
true), ""); |
| 45 |
|
| 46 |
// different day |
| 47 |
static_assert( testEquality( |
| 48 |
year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, |
| 49 |
year_month_weekday_last{year{1234}, January, weekday_last{Wednesday}}, |
| 50 |
false), ""); |
| 51 |
|
| 52 |
// different month |
| 53 |
static_assert( testEquality( |
| 54 |
year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, |
| 55 |
year_month_weekday_last{year{1234}, February, weekday_last{Tuesday}}, |
| 56 |
false), ""); |
| 57 |
|
| 58 |
// different year |
| 59 |
static_assert( testEquality( |
| 60 |
year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, |
| 61 |
year_month_weekday_last{year{1235}, January, weekday_last{Tuesday}}, |
| 62 |
false), ""); |
| 63 |
|
| 64 |
|
| 65 |
// different month and day |
| 66 |
static_assert( testEquality( |
| 67 |
year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, |
| 68 |
year_month_weekday_last{year{1234}, February, weekday_last{Wednesday}}, |
| 69 |
false), ""); |
| 70 |
|
| 71 |
// different year and month |
| 72 |
static_assert( testEquality( |
| 73 |
year_month_weekday_last{year{1234}, February, weekday_last{Tuesday}}, |
| 74 |
year_month_weekday_last{year{1235}, January, weekday_last{Tuesday}}, |
| 75 |
false), ""); |
| 76 |
|
| 77 |
// different year and day |
| 78 |
static_assert( testEquality( |
| 79 |
year_month_weekday_last{year{1234}, January, weekday_last{Wednesday}}, |
| 80 |
year_month_weekday_last{year{1235}, January, weekday_last{Tuesday}}, |
| 81 |
false), ""); |
| 82 |
|
| 83 |
// different year, month and day |
| 84 |
static_assert( testEquality( |
| 85 |
year_month_weekday_last{year{1234}, February, weekday_last{Wednesday}}, |
| 86 |
year_month_weekday_last{year{1235}, January, weekday_last{Tuesday}}, |
| 87 |
false), ""); |
| 88 |
|
| 89 |
|
| 90 |
// same year, different days |
| 91 |
for (unsigned i = 1; i < 28; ++i) |
| 92 |
for (unsigned j = 1; j < 28; ++j) |
| 93 |
assert((testEquality( |
| 94 |
year_month_weekday_last{year{1234}, January, weekday_last{weekday{i}}}, |
| 95 |
year_month_weekday_last{year{1234}, January, weekday_last{weekday{j}}}, |
| 96 |
i == j))); |
| 97 |
|
| 98 |
// same year, different months |
| 99 |
for (unsigned i = 1; i < 12; ++i) |
| 100 |
for (unsigned j = 1; j < 12; ++j) |
| 101 |
assert((testEquality( |
| 102 |
year_month_weekday_last{year{1234}, month{i}, weekday_last{Tuesday}}, |
| 103 |
year_month_weekday_last{year{1234}, month{j}, weekday_last{Tuesday}}, |
| 104 |
i == j))); |
| 105 |
|
| 106 |
// same month, different years |
| 107 |
for (int i = 1000; i < 2000; ++i) |
| 108 |
for (int j = 1000; j < 2000; ++j) |
| 109 |
assert((testEquality( |
| 110 |
year_month_weekday_last{year{i}, January, weekday_last{Tuesday}}, |
| 111 |
year_month_weekday_last{year{j}, January, weekday_last{Tuesday}}, |
| 112 |
i == j))); |
| 113 |
|
| 114 |
return 0; |
| 115 |
} |