IODA Bundle
TestFunctionThin.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 <cmath>
18 
19 #include "eckit/log/Timer.h"
20 #include "odc/Select.h"
21 
22 #include "odc/Writer.h"
23 #include "TestCase.h"
24 
25 using namespace std;
26 using namespace eckit;
27 using namespace odc;
28 
29 
30 static void setUp()
31 {
32  Timer t("Test thin function");
33  odc::Writer<> oda("test_thin.odb");
34 
35  odc::Writer<>::iterator row = oda.begin();
36  row->setNumberOfColumns(1);
37 
38  row->setColumn(0, "lat", odc::api::REAL);
39 
40  row->writeHeader();
41 
42  (*row)[0] = 45.0;
43  (*++row)[0] = 45.0;
44  (*++row)[0] = 45.0;
45  (*++row)[0] = 45.0;
46  (*++row)[0] = 45.0;
47  (*++row)[0] = 45.0;
48 }
49 
50 static void tearDown()
51 {
52  PathName("test_thin.odb").unlink();
53 }
54 
55 static void test()
56 {
57  const string sql = "select thin(2.0,lat) from \"test_thin.odb\";";
58 
59  Log::info() << "Executing: '" << sql << "'" << std::endl;
60 
61  int i=0;
62  odc::Select oda(sql);
63  for(odc::Select::iterator it = oda.begin(); it != oda.end(); ++it) {
64  if (i % 2 == 1)
65  ASSERT(fabs((*it)[0] - 0.0e0) < EPS); //
66  else
67  ASSERT(fabs((*it)[0] - 1.0) < EPS); //
68  ++i;
69  }
70 
71 }
72 
73 
74 SIMPLE_TEST(FunctionThin)
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
Definition: encode.cc:30