Device/Descriptor: pass pointer to OpenOnPort()
[xcsoar.git] / test / src / TestSunEphemeris.cpp
blob0fcb83730f630a658b1d7711483c92b6ff78bef5
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 "Math/SunEphemeris.hpp"
24 #include "Geo/GeoPoint.hpp"
25 #include "Time/BrokenDateTime.hpp"
26 #include "Time/RoughTime.hpp"
27 #include "TestUtil.hpp"
29 static void
30 test_times()
32 const GeoPoint location(Angle::Degrees(7.7061111111111114),
33 Angle::Degrees(51.051944444444445));
34 BrokenDateTime dt;
35 dt.year = 2010;
36 dt.month = 9;
37 dt.day = 24;
38 dt.hour = 8;
39 dt.minute = 21;
40 dt.second = 12;
42 SunEphemeris::Result sun =
43 SunEphemeris::CalcSunTimes(location, dt, RoughTimeDelta::FromHours(2));
45 ok1(between(sun.morning_twilight, 6.88, 6.9));
46 ok1(between(sun.time_of_noon, 13.3, 13.4));
47 ok1(between(sun.time_of_sunset, 19.36, 19.40));
48 ok1(between(sun.time_of_sunrise, 7.32, 7.41));
49 ok1(between(sun.evening_twilight, 19.81, 19.82));
52 #include <stdio.h>
53 static void
54 test_times_southern()
56 // Benalla
57 const GeoPoint location(Angle::Degrees(146.00666666666666),
58 Angle::Degrees(-36.551944444444445));
59 BrokenDateTime dt;
60 dt.year = 2013;
61 dt.month = 2;
62 dt.day = 22;
63 dt.hour = 8;
64 dt.minute = 21;
65 dt.second = 12;
67 SunEphemeris::Result sun =
68 SunEphemeris::CalcSunTimes(location, dt, RoughTimeDelta::FromHours(11));
70 ok1(between(sun.time_of_sunrise, 6.91, 6.95));
71 ok1(between(sun.time_of_sunset, 20.03, 20.04));
74 static void
75 test_azimuth()
77 double test_data1[24] = {
78 9.660271,
79 28.185910,
80 44.824283,
81 59.416812,
82 72.404059,
83 84.420232,
84 96.113747,
85 108.120524,
86 121.080364,
87 135.609075,
88 152.122820,
89 170.453770,
90 -170.455922,
91 -152.140313,
92 -135.650092,
93 -121.146412,
94 -108.210341,
95 -96.225746,
96 -84.552904,
97 -72.554841,
98 -59.579269,
99 -44.983118,
100 -28.311449,
101 -9.711208
104 double test_data2[24] = {
105 135.535117,
106 121.014248,
107 108.070607,
108 96.083211,
109 84.410044,
110 72.414117,
111 59.445455,
112 44.866010,
113 28.227658,
114 9.680160,
115 -9.682373,
116 -28.245579,
117 -44.907783,
118 -59.512321,
119 -72.504563,
120 -84.522294,
121 -96.215579,
122 -108.220331,
123 -121.174709,
124 -135.691072,
125 -152.181075,
126 -170.475266,
127 170.477364,
128 152.198463
131 GeoPoint location(Angle::Degrees(7), Angle::Degrees(51));
133 BrokenDateTime dt;
134 dt.year = 2010;
135 dt.month = 9;
136 dt.day = 24;
137 dt.minute = 30;
138 dt.second = 0;
140 for (unsigned hour = 0; hour < 24; hour++) {
141 dt.hour = hour;
143 SunEphemeris::Result sun =
144 SunEphemeris::CalcSunTimes(location, dt, RoughTimeDelta::FromHours(0));
146 ok1(equals(sun.azimuth, test_data1[hour]));
149 location.latitude.Flip();
151 for (unsigned hour = 0; hour < 24; hour++) {
152 dt.hour = hour;
154 SunEphemeris::Result sun =
155 SunEphemeris::CalcSunTimes(location, dt, RoughTimeDelta::FromHours(2));
157 ok1(equals(sun.azimuth, test_data2[hour]));
161 int main(int argc, char **argv)
163 plan_tests(55);
165 test_times();
166 test_times_southern();
167 test_azimuth();
169 return exit_status();