hours.pass.cpp
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// <chrono>
// template <class Duration>
// class hh_mm_ss
//
// constexpr chrono::hours hours() const noexcept;
// Test values
// duration hours minutes seconds fractional
// 5000s 1 23 20 0
// 5000 minutes 83 20 0 0
// 123456789ms 34 17 36 789ms
// 123456789us 0 2 3 456789us
// 123456789ns 0 0 0 123456789ns
// 1000mfn 0 20 9 0.6 (6000/10000)
// 10000mfn 3 21 36 0
#include <chrono>
#include <cassert>
#include "test_macros.h"
template <typename Duration>
constexpr long check_hours(Duration d)
{
using HMS = std::chrono::hh_mm_ss<Duration>;
ASSERT_SAME_TYPE(std::chrono::hours, decltype(std::declval<HMS>().hours()));
ASSERT_NOEXCEPT( std::declval<HMS>().hours());
return HMS(d).hours().count();
}
int main(int, char**)
{
using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>;
static_assert( check_hours(std::chrono::minutes( 1)) == 0, "");
static_assert( check_hours(std::chrono::minutes(-1)) == 0, "");
assert( check_hours(std::chrono::seconds( 5000)) == 1);
assert( check_hours(std::chrono::seconds(-5000)) == 1);
assert( check_hours(std::chrono::minutes( 5000)) == 83);
assert( check_hours(std::chrono::minutes(-5000)) == 83);
assert( check_hours(std::chrono::hours( 11)) == 11);
assert( check_hours(std::chrono::hours(-11)) == 11);
assert( check_hours(std::chrono::milliseconds( 123456789LL)) == 34);
assert( check_hours(std::chrono::milliseconds(-123456789LL)) == 34);
assert( check_hours(std::chrono::microseconds( 123456789LL)) == 0);
assert( check_hours(std::chrono::microseconds(-123456789LL)) == 0);
assert( check_hours(std::chrono::nanoseconds( 123456789LL)) == 0);
assert( check_hours(std::chrono::nanoseconds(-123456789LL)) == 0);
assert( check_hours(microfortnights( 1000)) == 0);
assert( check_hours(microfortnights( -1000)) == 0);
assert( check_hours(microfortnights( 10000)) == 3);
assert( check_hours(microfortnights(-10000)) == 3);
return 0;
}