3 # include <simgear_config.h>
6 #include <simgear/compiler.h>
16 #include <simgear/misc/sg_dir.hxx>
17 #include <simgear/structure/exception.hxx>
26 #define COMPARE(a, b) \
28 cerr << "failed:" << #a << " != " << #b << endl; \
29 cerr << "\tgot:" << a << endl; \
33 #define FUZZY_COMPARE(a, b, epsilon) \
34 if (fabs(a - b) > epsilon) { \
35 cerr << "failed:" << #a << " != " << #b << endl; \
36 cerr << "\tgot:" << a << endl; \
37 cerr << "\tepsilon:" << epsilon << endl; \
42 cerr << "failed:" << #a << endl; \
46 const double TEST_EPSILON = 1e-9;
50 SGMetar m1("2011/10/20 11:25 EHAM 201125Z 27012KT 240V300 9999 VCSH FEW025CB SCT048 10/05 Q1025 TEMPO VRB03KT");
51 COMPARE(m1.getYear(), 2011);
52 COMPARE(m1.getMonth(), 10);
53 COMPARE(m1.getDay(), 20);
54 COMPARE(m1.getHour(), 11);
55 COMPARE(m1.getMinute(), 25);
56 COMPARE(m1.getReportType(), -1); // should default to NIL?
58 COMPARE(m1.getWindDir(), 270);
59 FUZZY_COMPARE(m1.getWindSpeed_kt(), 12, TEST_EPSILON);
61 COMPARE(m1.getWeather().size(), 1);
62 COMPARE(m1.getClouds().size(), 2);
64 FUZZY_COMPARE(m1.getTemperature_C(), 10, TEST_EPSILON);
65 FUZZY_COMPARE(m1.getDewpoint_C(), 5, TEST_EPSILON);
66 FUZZY_COMPARE(m1.getPressure_hPa(), 1025, TEST_EPSILON);
69 void test_sensor_failure_weather()
71 SGMetar m1("2011/10/20 11:25 EHAM 201125Z 27012KT 240V300 9999 // FEW025CB SCT048 10/05 Q1025");
72 COMPARE(m1.getWindDir(), 270);
73 FUZZY_COMPARE(m1.getWindSpeed_kt(), 12, TEST_EPSILON);
75 COMPARE(m1.getWeather().size(), 0);
76 COMPARE(m1.getClouds().size(), 2);
78 FUZZY_COMPARE(m1.getTemperature_C(), 10, TEST_EPSILON);
79 FUZZY_COMPARE(m1.getDewpoint_C(), 5, TEST_EPSILON);
80 FUZZY_COMPARE(m1.getPressure_hPa(), 1025, TEST_EPSILON);
83 void test_sensor_failure_cloud()
85 SGMetar m1("2011/10/20 11:25 EHAM 201125Z 27012KT 240V300 9999 FEW025CB/// SCT048/// 10/05 Q1025");
86 COMPARE(m1.getWindDir(), 270);
87 FUZZY_COMPARE(m1.getWindSpeed_kt(), 12, TEST_EPSILON);
89 COMPARE(m1.getWeather().size(), 0);
90 COMPARE(m1.getClouds().size(), 2);
92 FUZZY_COMPARE(m1.getTemperature_C(), 10, TEST_EPSILON);
93 FUZZY_COMPARE(m1.getDewpoint_C(), 5, TEST_EPSILON);
94 FUZZY_COMPARE(m1.getPressure_hPa(), 1025, TEST_EPSILON);
97 int main(int argc, char* argv[])
101 test_sensor_failure_weather();
102 test_sensor_failure_cloud();
103 } catch (sg_exception& e) {
104 cerr << "got exception:" << e.getMessage() << endl;