IODA Bundle
TestFunctionsForAngleConversion.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// \file UnitTest.cc
12 ///
13 /// @author ECMWF, July 2010
14 
15 const double EPS = 7e-6;
16 
17 #include "eckit/log/Timer.h"
18 #include "odc/Select.h"
20 
21 #include "odc/Writer.h"
22 #include "TestCase.h"
23 
24 using namespace std;
25 using namespace eckit;
26 using namespace odc;
27 
28 using namespace odc::sql::function;
29 
30 
31 static void setUp()
32 {
33  Timer t("Test various functions to convert angles (radians to degrees, etc.)");
34  odc::Writer<> oda("test_angleconv.odb");
35 
36  odc::Writer<>::iterator row = oda.begin();
37  row->setNumberOfColumns(2);
38 
39  row->setColumn(0, "radian_col", odc::api::REAL);
40  row->setColumn(1, "degrees_col", odc::api::REAL);
41 
42  row->writeHeader();
43 
44  (*row)[0] = piconst::pi;
45  (*row)[1] = 180.0e0;
46  ++row;
47 
48  (*row)[0] = 0.0e0;
49  (*row)[1] = 0.0e0;
50  ++row;
51 
52  (*row)[0] = piconst::pi/4.0e0;
53  (*row)[1] = 45.0e0;
54  ++row;
55 }
56 
57 static void tearDown()
58 {
59  PathName("test_angleconv.odb").unlink();
60 }
61 
62 static void test()
63 {
64  const string sql = "select degrees(radian_col),radians(degrees_col), rad2deg(radian_col), deg2rad(degrees_col), radians(degrees(radian_col)), degrees(radians(degrees_col)) from \"test_angleconv.odb\";";
65 
66  Log::info() << "Executing: '" << sql << "'" << std::endl;
67 
68  odc::Select oda(sql);
69  odc::Select::iterator it = oda.begin();
70 
71 // because stored as single real precision; we loose some accuracy
72  ASSERT(fabs((*it)[0] - 180) < EPS); //
73  ASSERT(fabs((*it)[1] - piconst::pi) < EPS); //
74  ASSERT(fabs((*it)[2] - 180.0) < EPS); //
75  ASSERT(fabs((*it)[3] - piconst::pi) < EPS); //
76 
77  ASSERT(fabs((*it)[4] - piconst::pi) < EPS); //
78  ASSERT(fabs((*it)[5] - 180.0e0) < EPS); //
79 
80  ++it;
81  ASSERT(fabs((*it)[0]) < EPS); //
82  ASSERT(fabs((*it)[1]) < EPS); //
83  ASSERT(fabs((*it)[2]) < EPS); //
84  ASSERT(fabs((*it)[3]) < EPS); //
85 
86  ASSERT(fabs((*it)[4]) < EPS); //
87  ASSERT(fabs((*it)[5]) < EPS); //
88 
89  ++it;
90  ASSERT(fabs((*it)[0] - 45) < EPS); //
91  ASSERT(fabs((*it)[1] - piconst::pi/4.0) < EPS); //
92  ASSERT(fabs((*it)[2] - 45.0) < EPS); //
93  ASSERT(fabs((*it)[3] - piconst::pi/4.0) < EPS); //
94 
95  ASSERT(fabs((*it)[4] - piconst::pi/4.0) < EPS); //
96  ASSERT(fabs((*it)[5] - 45.0e0) < EPS); //
97 
98 
99 }
100 
101 
102 
103 SIMPLE_TEST(FunctionsForAngleConversion)
void oda
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
static void tearDown()
static void test()
static void setUp()
const double EPS
void writeHeader()
void setNumberOfColumns(size_t n)
Definition: IteratorProxy.h:95
int setColumn(size_t index, const std::string &name, api::ColumnType type)
Definition: ColumnInfo.h:23
real(kind_real), parameter, public pi
Pi.
Definition: encode.cc:30