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 "Computer/ClimbAverageCalculator.hpp"
24 #include "TestUtil.hpp"
31 ClimbAverageCalculator c
;
36 constexpr fixed AVERAGE_TIME
= fixed(30);
38 // Test normal behavior
39 c
.GetAverage(fixed(0), fixed(0), AVERAGE_TIME
);
40 for (unsigned i
= 1; i
<= 15; i
++)
41 av
= c
.GetAverage(fixed(i
), fixed(i
), AVERAGE_TIME
);
45 for (unsigned i
= 1; i
<= 15; i
++)
46 av
= c
.GetAverage(fixed(15 + i
), fixed(15 + i
* 2), AVERAGE_TIME
);
50 for (unsigned i
= 1; i
<= 15; i
++)
51 av
= c
.GetAverage(fixed(30 + i
), fixed(45 + i
* 2), AVERAGE_TIME
);
57 TestDuplicateTimestamps()
59 ClimbAverageCalculator c
;
62 constexpr fixed AVERAGE_TIME
= fixed(30);
64 // Test time difference = zero behavior
66 c
.GetAverage(fixed(0), fixed(0), AVERAGE_TIME
);
67 for (unsigned i
= 1; i
<= 15; i
++)
68 c
.GetAverage(fixed(i
), fixed(i
), AVERAGE_TIME
);
70 for (unsigned i
= 1; i
<= 15; i
++) {
71 c
.GetAverage(fixed(15 + i
), fixed(15 + i
* 2), AVERAGE_TIME
);
72 c
.GetAverage(fixed(15 + i
), fixed(15 + i
* 2), AVERAGE_TIME
);
73 av
= c
.GetAverage(fixed(15 + i
), fixed(15 + i
* 2), AVERAGE_TIME
);
82 ClimbAverageCalculator c
;
85 constexpr fixed AVERAGE_TIME
= fixed(30);
88 // Test expiration for empty data
89 ok1(c
.Expired(fixed(0), fixed(60)));
90 ok1(c
.Expired(fixed(15), fixed(60)));
92 // Add values and test non-expiration
94 for (unsigned i
= 1; i
<= 60; i
++) {
95 c
.GetAverage(fixed(i
), fixed(i
), AVERAGE_TIME
);
96 expired
= expired
|| c
.Expired(fixed(i
), fixed(60));
101 // Test expiration with 30sec
102 ok1(!c
.Expired(fixed(89), fixed(30)));
103 ok1(!c
.Expired(fixed(90), fixed(30)));
104 ok1(c
.Expired(fixed(91), fixed(30)));
106 // Test expiration with 60sec
107 ok1(!c
.Expired(fixed(119), fixed(60)));
108 ok1(!c
.Expired(fixed(120), fixed(60)));
109 ok1(c
.Expired(fixed(121), fixed(60)));
112 ok1(c
.Expired(fixed(59), fixed(60)));
113 ok1(!c
.Expired(fixed(60), fixed(60)));
114 ok1(!c
.Expired(fixed(61), fixed(60)));
117 int main(int argc
, char **argv
)
122 TestDuplicateTimestamps();
125 return exit_status();