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