brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 1f56785 Raw
88 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <chrono>11// class month_weekday;12 13// constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;14//   Returns: x.month() == y.month() && x.day() == y.day().15//16 17#include <chrono>18#include <type_traits>19#include <cassert>20 21#include "test_macros.h"22#include "test_comparisons.h"23 24int main(int, char**)25{26    using month_weekday   = std::chrono::month_weekday;27    using month           = std::chrono::month;28    using weekday_indexed = std::chrono::weekday_indexed;29    using weekday         = std::chrono::weekday;30 31    constexpr weekday Sunday = std::chrono::Sunday;32    constexpr weekday Monday = std::chrono::Monday;33 34    AssertEqualityAreNoexcept<month_weekday>();35    AssertEqualityReturnBool<month_weekday>();36 37    static_assert( testEquality(38        month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}},39        month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}},40        true), "");41 42    static_assert( testEquality(43        month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}},44        month_weekday{std::chrono::January, weekday_indexed{Sunday, 2}},45        false), "");46 47    static_assert( testEquality(48        month_weekday{std::chrono::January,  weekday_indexed{Sunday, 1}},49        month_weekday{std::chrono::February, weekday_indexed{Sunday, 1}},50        false), "");51 52    static_assert( testEquality(53        month_weekday{std::chrono::January, weekday_indexed{Monday, 1}},54        month_weekday{std::chrono::January, weekday_indexed{Sunday, 2}},55        false), "");56 57    static_assert( testEquality(58        month_weekday{std::chrono::January,  weekday_indexed{Monday, 1}},59        month_weekday{std::chrono::February, weekday_indexed{Sunday, 1}},60        false), "");61 62//  same day, different months63    for (unsigned i = 1; i < 12; ++i)64        for (unsigned j = 1; j < 12; ++j)65            assert((testEquality(66                month_weekday{month{i}, weekday_indexed{Sunday, 1}},67                month_weekday{month{j}, weekday_indexed{Sunday, 1}},68                i == j)));69 70//  same month, different weeks71    for (unsigned i = 1; i < 5; ++i)72        for (unsigned j = 1; j < 5; ++j)73            assert((testEquality(74                month_weekday{month{2}, weekday_indexed{Sunday, i}},75                month_weekday{month{2}, weekday_indexed{Sunday, j}},76                i == j)));77 78//  same month, different days79    for (unsigned i = 0; i < 6; ++i)80        for (unsigned j = 0; j < 6; ++j)81            assert((testEquality(82                month_weekday{month{2}, weekday_indexed{weekday{i}, 2}},83                month_weekday{month{2}, weekday_indexed{weekday{j}, 2}},84                i == j)));85 86  return 0;87}88