1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <chrono>
11 
12 // duration
13 
14 // template <class Rep1, class Period1, class Rep2, class Period2>
15 //   constexpr
16 //   bool
17 //   operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
18 
19 // template <class Rep1, class Period1, class Rep2, class Period2>
20 //   constexpr
21 //   bool
22 //   operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
23 
24 // template <class Rep1, class Period1, class Rep2, class Period2>
25 //   constexpr
26 //   bool
27 //   operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
28 
29 // template <class Rep1, class Period1, class Rep2, class Period2>
30 //   constexpr
31 //   bool
32 //   operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
33 
34 #include <chrono>
35 #include <cassert>
36 
37 #include "test_macros.h"
38 
main()39 int main()
40 {
41     {
42     std::chrono::seconds s1(3);
43     std::chrono::seconds s2(3);
44     assert(!(s1 < s2));
45     assert(!(s1 > s2));
46     assert( (s1 <= s2));
47     assert( (s1 >= s2));
48     }
49     {
50     std::chrono::seconds s1(3);
51     std::chrono::seconds s2(4);
52     assert( (s1 < s2));
53     assert(!(s1 > s2));
54     assert( (s1 <= s2));
55     assert(!(s1 >= s2));
56     }
57     {
58     std::chrono::milliseconds s1(3);
59     std::chrono::microseconds s2(3000);
60     assert(!(s1 < s2));
61     assert(!(s1 > s2));
62     assert( (s1 <= s2));
63     assert( (s1 >= s2));
64     }
65     {
66     std::chrono::milliseconds s1(3);
67     std::chrono::microseconds s2(4000);
68     assert( (s1 < s2));
69     assert(!(s1 > s2));
70     assert( (s1 <= s2));
71     assert(!(s1 >= s2));
72     }
73     {
74     std::chrono::duration<int, std::ratio<2, 3> > s1(9);
75     std::chrono::duration<int, std::ratio<3, 5> > s2(10);
76     assert(!(s1 < s2));
77     assert(!(s1 > s2));
78     assert( (s1 <= s2));
79     assert( (s1 >= s2));
80     }
81     {
82     std::chrono::duration<int, std::ratio<2, 3> > s1(10);
83     std::chrono::duration<int, std::ratio<3, 5> > s2(9);
84     assert(!(s1 < s2));
85     assert( (s1 > s2));
86     assert(!(s1 <= s2));
87     assert( (s1 >= s2));
88     }
89     {
90     std::chrono::duration<int, std::ratio<2, 3> > s1(9);
91     std::chrono::duration<double, std::ratio<3, 5> > s2(10);
92     assert(!(s1 < s2));
93     assert(!(s1 > s2));
94     assert( (s1 <= s2));
95     assert( (s1 >= s2));
96     }
97 #if TEST_STD_VER >= 11
98     {
99     constexpr std::chrono::seconds s1(3);
100     constexpr std::chrono::seconds s2(3);
101     static_assert(!(s1 < s2), "");
102     static_assert(!(s1 > s2), "");
103     static_assert( (s1 <= s2), "");
104     static_assert( (s1 >= s2), "");
105     }
106     {
107     constexpr std::chrono::seconds s1(3);
108     constexpr std::chrono::seconds s2(4);
109     static_assert( (s1 < s2), "");
110     static_assert(!(s1 > s2), "");
111     static_assert( (s1 <= s2), "");
112     static_assert(!(s1 >= s2), "");
113     }
114     {
115     constexpr std::chrono::milliseconds s1(3);
116     constexpr std::chrono::microseconds s2(3000);
117     static_assert(!(s1 < s2), "");
118     static_assert(!(s1 > s2), "");
119     static_assert( (s1 <= s2), "");
120     static_assert( (s1 >= s2), "");
121     }
122     {
123     constexpr std::chrono::milliseconds s1(3);
124     constexpr std::chrono::microseconds s2(4000);
125     static_assert( (s1 < s2), "");
126     static_assert(!(s1 > s2), "");
127     static_assert( (s1 <= s2), "");
128     static_assert(!(s1 >= s2), "");
129     }
130     {
131     constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9);
132     constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(10);
133     static_assert(!(s1 < s2), "");
134     static_assert(!(s1 > s2), "");
135     static_assert( (s1 <= s2), "");
136     static_assert( (s1 >= s2), "");
137     }
138     {
139     constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(10);
140     constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(9);
141     static_assert(!(s1 < s2), "");
142     static_assert( (s1 > s2), "");
143     static_assert(!(s1 <= s2), "");
144     static_assert( (s1 >= s2), "");
145     }
146     {
147     constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9);
148     constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(10);
149     static_assert(!(s1 < s2), "");
150     static_assert(!(s1 > s2), "");
151     static_assert( (s1 <= s2), "");
152     static_assert( (s1 >= s2), "");
153     }
154 #endif
155 }
156