]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/test.cpp
Added first stab at a socket class.
[flightgear.git] / src / WeatherCM / test.cpp
1 /*****************************************************************************
2
3  Module:       test.cpp
4  Author:       Christian Mayer
5  Date started: 28.05.99
6  Called by:    command line
7
8  ---------- Copyright (C) 1999  Christian Mayer (vader@t-online.de) ----------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Test program for the weather database
30
31 HISTORY
32 ------------------------------------------------------------------------------
33 28.05.99   CM   Created
34 *****************************************************************************/
35
36 /****************************************************************************/
37 /* INCLUDES                                                                 */
38 /****************************************************************************/
39 #include "FGLocalWeatherDatabase.h"
40 #include "FGGlobalWeatherDatabase.h"
41 #include "LibVoronoi/FGVoronoi.h"
42 #include "FGWeatherUtils.h"
43 #include <time.h>
44 #include STL_IOSTREAM
45 #include <vector>
46
47 /****************************************************************************/
48 /********************************** CODE ************************************/
49 /****************************************************************************/
50 int main(void)
51 {
52     //init local database:
53
54     FGLocalWeatherDatabase local(Point3D(0,0,0), 10000, FGLocalWeatherDatabase::use_global);
55     FGGlobalWeatherDatabase global(FGGlobalWeatherDatabase_working);
56
57     Point3D p(0);
58     Point2D p2d(0);
59     FGPhysicalProperties x;
60     FGPhysicalProperties2D x2d;
61     FGPhysicalProperties2DVector getAllvect;
62
63     cout << "\n**************** FGGlobalWeatherDatabase Test ****************\n";
64     x.Temperature.insert(FGTemperatureItem(100, Celsius(10)));
65     global.add(Point2D(5,5), x);
66
67     x.Temperature.insert(FGTemperatureItem(110, Celsius(-10)));
68     global.add(Point3D(10,10,10), x);
69
70     x2d.Temperature.insert(FGTemperatureItem(90, Celsius(-20)));
71     x2d.p = Point2D(10,5);
72
73     global.add(x2d);
74
75     getAllvect = global.getAll(p2d, 10000);
76     cout << "Returned size: " << getAllvect.size() << "\n";
77     getAllvect = global.getAll(p2d, 10000, 30);
78     cout << "Returned size: " << getAllvect.size() << "\n";
79     getAllvect = global.getAll(p, 10000);
80     cout << "Returned size: " << getAllvect.size() << "\n";
81     getAllvect = global.getAll(p, 10000, 3);
82     cout << "Returned size: " << getAllvect.size() << "\n";
83
84     cout << "Temperature: " << global.get(Point3D(5, 5, 100)).Temperature << "°C\n";
85     cout << "AirPressure at    0m: " << global.get(Point3D(5, 5,    0)).AirPressure << "\n";
86     cout << "AirPressure at 1000m: " << global.get(Point3D(5, 5, 1000)).AirPressure << "\n";
87
88     cout << global;
89
90
91     cout << "\n**************** FGMicroWeather Test ****************\n";
92     vector<Point2D> points;
93
94     points.push_back(Point2D(0.1, 0.1));
95     points.push_back(Point2D(0.9, 0.1));
96     points.push_back(Point2D(0.9, 0.9));
97     points.push_back(Point2D(0.1, 0.9));
98     points.push_back(Point2D(0.1, 0.1));
99
100     x2d.p = Point2D(0.4, 0.4);
101
102     FGMicroWeather micro(x2d, points);
103
104     cout << "hasPoint 0.5, 0.5: ";
105     if (micro.hasPoint(Point2D(0.5, 0.5)) == true)
106         cout << "true";
107     else
108         cout << "false";
109
110     cout << "\nhasPoint 0.9, 0.5: ";
111     if (micro.hasPoint(Point2D(0.9, 0.5)) == true)
112         cout << "true";
113     else
114         cout << "false";
115
116     cout << "\nhasPoint 1.5, 0.5: ";
117     if (micro.hasPoint(Point2D(1.5, 0.5)) == true)
118         cout << "true";
119     else
120         cout << "false";
121
122     cout << "\n";
123
124
125     cout << "\n**************** Voronoi Diagram Test ****************\n";
126     FGVoronoiInputList input;
127     FGVoronoiOutputList output;
128     FGVoronoiInput test(Point2D(0.0), FGPhysicalProperties2D());
129
130     test.position = Point2D(0.1,0.2);
131     input.push_back(test);
132
133     test.position = Point2D(0.8,0.9);
134     input.push_back(test);
135
136     test.position = Point2D(0.9,0.1);
137     input.push_back(test);
138
139     test.position = Point2D(0.6,0.4);
140     input.push_back(test);
141
142     test.position = Point2D(1.1,1.2);
143     input.push_back(test);
144
145     test.position = Point2D(1.8,1.9);
146     input.push_back(test);
147
148     test.position = Point2D(1.9,1.1);
149     input.push_back(test);
150
151     test.position = Point2D(1.6,1.4);
152     input.push_back(test);
153
154     test.position = Point2D(2.9,2.1);
155     input.push_back(test);
156
157     test.position = Point2D(2.6,2.4);
158     input.push_back(test);
159
160     output = Voronoiate(input);
161
162     cout << "\n";
163     for (FGVoronoiOutputList::iterator it=output.begin(); it!=output.end(); it++)
164     {
165         cout << "Cell start: ";
166         for (Point2DList::iterator it2= it->boundary.begin();it2!= it->boundary.end();it2++)
167         {
168             if (it2==it->boundary.begin())
169                 cout << "(";
170             else
171                 cout << "-(";
172             
173             cout << *it2 << ")";
174         }
175         cout << "\n";
176     }
177
178     cout << "\n**************** Database Stress Test ****************\n";
179
180     time_t starttime, currenttime;
181     unsigned long count = 0;
182     unsigned long count2 = 0;
183     float xxx, yyy;
184     cout << "Filling Database... ";
185     time( &starttime );
186     for (count = 0; count < 5000; count++)
187     {
188         xxx = (rand()%36000)/100.0;
189         yyy = (rand()%18000)/100.0;
190
191         local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point2D(xxx, yyy)));
192     }
193     local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(-10.0)));
194     local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(+10.0)));
195     local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(-100.0)));
196     local.addProperties(FGPhysicalProperties2D(FGPhysicalProperties(), Point3D(+100.0)));
197
198     time( &currenttime );
199     cout << float(count)/float(currenttime - starttime) << "/s filling rate; ";
200     time( &starttime );
201
202     for (count = 0; count < 5; count++)
203     {
204         local.reset(FGLocalWeatherDatabase::use_global);        //make sure I've got a current voronoi
205     }
206
207     time( &currenttime );
208     cout << float(currenttime - starttime)/float(count) << "s resetting time; Done\n";
209     count = 0;
210
211     //for (;count<200;)
212     cout << "local.get() test: 10 seconds\n";
213     time( &starttime );
214     time( &currenttime );
215     for (;currenttime<(starttime+10);)
216     {
217         time( &currenttime );
218         count++;
219         local.get(Point3D(0.0));
220     }
221
222     cout << "Result: " << float(count) / float(currenttime-starttime) << "/s\n";
223
224     count = 0;
225     cout << "output = Voronoiate(input) test: 10 seconds\n";
226     time( &starttime );
227     time( &currenttime );
228     for (;currenttime<(starttime+10);)
229     {
230         time( &currenttime );
231         count++;
232         output = Voronoiate(input);
233     }
234
235     cout << "Result: " << float(count) / float(currenttime-starttime) << "/s\n";
236     cout << "Reference: 176800/s\n";
237
238     cout << "\n**************** Database Stress Test end ****************\n";
239     return 0;
240 }
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255