IODA Bundle
TestFunctionsForTemperatureConversion.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 #include "eckit/log/Timer.h"
16 #include "odc/Select.h"
17 
18 #include "odc/Writer.h"
19 #include "TestCase.h"
20 
21 using namespace std;
22 using namespace eckit;
23 using namespace odc;
24 
25 
26 
27 static void setUp()
28 {
29  Timer t("Test various functions to convert temperatures");
30  odc::Writer<> oda("test_tempconv.odb");
31 
32  odc::Writer<>::iterator row = oda.begin();
33  row->setNumberOfColumns(3);
34 
35  row->setColumn(0, "kelvin_col", odc::api::REAL);
36  row->setColumn(1, "celsius_col", odc::api::REAL);
37  row->setColumn(2, "fahrenheit_col", odc::api::REAL);
38 
39  row->writeHeader();
40 
41  (*row)[0] = 273.15;
42  (*row)[1] = 0.0;
43  (*row)[2] = 32;
44  ++row;
45 }
46 
47 static void tearDown()
48 {
49  PathName("test_tempconv.odb").unlink();
50 }
51 
52 static void test()
53 {
54  const string sql = "select celsius(kelvin_col), fahrenheit(kelvin_col), c2k(celsius_col),c2f(celsius_col),f2c(fahrenheit_col), f2k(fahrenheit_col), k2f(kelvin_col) from \"test_tempconv.odb\";";
55 
56  Log::info() << "Executing: '" << sql << "'" << std::endl;
57 
58  odc::Select oda(sql);
59  odc::Select::iterator it = oda.begin();
60 
61  ASSERT((*it)[0] == 0.0); // celsius(273.15) = 0.0
62  ASSERT((*it)[1] == 32); // farhenheit(273.15) = 31.73
63  ASSERT((*it)[2] == 273.15); // c2k
64  ASSERT((*it)[3] == 32); // c2f
65 
66  ASSERT((*it)[4] == 0); // f2c
67  ASSERT((*it)[5] == 273.15); // f2k
68  ASSERT((*it)[6] == 32); // k2f
69 
70 }
71 
72 
73 
74 SIMPLE_TEST(FunctionsForTemperatureConversion)
void oda
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
static void tearDown()
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
Definition: encode.cc:30