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 FUZZY_COMPARE(m1.getTemperature_C(), 10, TEST_EPSILON);
62 FUZZY_COMPARE(m1.getDewpoint_C(), 5, TEST_EPSILON);
63 FUZZY_COMPARE(m1.getPressure_hPa(), 1025, TEST_EPSILON);
66 int main(int argc, char* argv[])
70 } catch (sg_exception& e) {
71 cerr << "got exception:" << e.getMessage() << endl;