TaskStats: remove unused attribute "Time"
[xcsoar.git] / test / src / TestRoughTime.cpp
blobac568afb4cbaf557d78e35985d1db63a704ecf61
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Time/RoughTime.hpp"
24 #include "TestUtil.hpp"
26 int main(int argc, char **argv)
28 plan_tests(77);
30 RoughTime a = RoughTime::Invalid();
31 ok1(!a.IsValid());
33 a = RoughTime(12, 1);
34 ok1(a.IsValid());
35 ok1(a.GetHour() == 12);
36 ok1(a.GetMinute() == 1);
37 ok1(a.GetMinuteOfDay() == 12 * 60 + 1);
39 /* compare a RoughTime with itself */
40 ok1(a == a);
41 ok1(!(a != a));
42 ok1(a <= a);
43 ok1(a >= a);
44 ok1(!(a < a));
45 ok1(!(a > a));
47 /* compare a RoughTime with another one */
48 RoughTime b(11, 59);
49 ok1(b.IsValid());
50 ok1(a != b);
51 ok1(!(a == b));
52 ok1(!(a <= b));
53 ok1(a >= b);
54 ok1(!(a < b));
55 ok1(a > b);
56 ok1(b != a);
57 ok1(!(b == a));
58 ok1(b <= a);
59 ok1(!(b >= a));
60 ok1(b < a);
61 ok1(!(b > a));
63 /* test RoughTimeSpan::IsInside() */
64 RoughTimeSpan s = RoughTimeSpan::Invalid();
65 ok1(!s.IsDefined());
66 ok1(s.IsInside(a));
67 ok1(s.IsInside(b));
69 s = RoughTimeSpan(RoughTime(12, 0), RoughTime::Invalid());
70 ok1(s.IsDefined());
71 ok1(s.IsInside(a));
72 ok1(!s.IsInside(b));
74 s = RoughTimeSpan(RoughTime::Invalid(), RoughTime(12, 0));
75 ok1(s.IsDefined());
76 ok1(!s.IsInside(a));
77 ok1(s.IsInside(b));
79 s = RoughTimeSpan(RoughTime(12, 0), RoughTime(12, 1));
80 ok1(s.IsDefined());
81 ok1(!s.IsInside(a));
82 ok1(!s.IsInside(b));
84 s = RoughTimeSpan(RoughTime(12, 0), RoughTime(12, 30));
85 ok1(s.IsDefined());
86 ok1(s.IsInside(a));
87 ok1(!s.IsInside(b));
89 /* test midnight wraparound */
90 a = RoughTime(0, 0);
91 b = RoughTime(23, 59);
92 ok1(b.IsValid());
93 ok1(a != b);
94 ok1(!(a == b));
95 ok1(!(a <= b));
96 ok1(a >= b);
97 ok1(!(a < b));
98 ok1(a > b);
99 ok1(b != a);
100 ok1(!(b == a));
101 ok1(b <= a);
102 ok1(!(b >= a));
103 ok1(b < a);
104 ok1(!(b > a));
106 RoughTime c(22, 0);
107 RoughTime d(2, 0);
108 s = RoughTimeSpan(RoughTime(23, 0), RoughTime::Invalid());
109 ok1(s.IsDefined());
110 ok1(s.IsInside(a));
111 ok1(s.IsInside(b));
112 ok1(!s.IsInside(c));
113 ok1(s.IsInside(d));
115 s = RoughTimeSpan(RoughTime::Invalid(), RoughTime(1, 0));
116 ok1(s.IsDefined());
117 ok1(s.IsInside(a));
118 ok1(s.IsInside(b));
119 ok1(s.IsInside(c));
120 ok1(!s.IsInside(d));
122 s = RoughTimeSpan(RoughTime(23, 1), RoughTime(0, 30));
123 ok1(s.IsDefined());
124 ok1(s.IsInside(a));
125 ok1(s.IsInside(b));
126 ok1(!s.IsInside(c));
127 ok1(!s.IsInside(d));
129 /* test operator+(RoughTime, RoughTimeDelta) */
130 ok1(RoughTime(0, 0) + RoughTimeDelta::FromMinutes(0) == RoughTime(0, 0));
131 ok1(RoughTime(0, 0) + RoughTimeDelta::FromMinutes(1) == RoughTime(0, 1));
132 ok1(RoughTime(0, 0) + RoughTimeDelta::FromMinutes(60) == RoughTime(1, 0));
133 ok1(RoughTime(0, 0) + RoughTimeDelta::FromHours(24) == RoughTime(0, 0));
134 ok1(RoughTime(0, 0) + RoughTimeDelta::FromHours(25) == RoughTime(1, 0));
136 ok1(RoughTime(0, 0) - RoughTimeDelta::FromMinutes(0) == RoughTime(0, 0));
137 ok1(RoughTime(0, 0) - RoughTimeDelta::FromMinutes(1) == RoughTime(23, 59));
138 ok1(RoughTime(0, 0) - RoughTimeDelta::FromMinutes(60) == RoughTime(23, 0));
139 ok1(RoughTime(0, 0) - RoughTimeDelta::FromHours(24) == RoughTime(0, 0));
140 ok1(RoughTime(0, 0) - RoughTimeDelta::FromHours(25) == RoughTime(23, 0));
142 return exit_status();