IODA Bundle
test_minmax.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 #include "eckit/testing/Test.h"
12 
13 #include "odc/Reader.h"
14 
15 #include "TemporaryFiles.h"
16 
17 #include <stdint.h>
18 
19 using namespace eckit::testing;
20 
21 
22 // ------------------------------------------------------------------------------------------------------
23 
24 CASE("Test that the numeric limits are what we expect") {
25  EXPECT(std::numeric_limits<int32_t>::max() == 2147483647);
26  EXPECT(std::numeric_limits<int32_t>::min() == -2147483648);
27 }
28 
29 CASE("Test reading min, max and intermediate values") {
30 
31  SETUP("An odb file containing min/max/intermediate values") {
32 
33  class TemporaryMinMaxODB : public TemporaryFile {
34  public:
35  TemporaryMinMaxODB() {
36  odc::Writer<> oda(path());
38 
39  writer->setNumberOfColumns(2);
40  writer->setColumn(0, "intcol", odc::api::INTEGER);
41  writer->setColumn(1, "realcol", odc::api::REAL);
42  writer->writeHeader();
43 
44  (*writer)[0] = std::numeric_limits<int32_t>::min();
45  (*writer)[1] = 1;
46  ++writer;
47 
48  (*writer)[0] = std::numeric_limits<int32_t>::max();
49  (*writer)[1] = 1;
50  ++writer;
51 
52  (*writer)[0] = std::numeric_limits<int32_t>::min() + std::numeric_limits<int32_t>::max();
53  (*writer)[1] = 1;
54  ++writer;
55  }
56  };
57 
58  TemporaryMinMaxODB tmpODB;
59 
60  SECTION("Read the values back in") {
61 
62  odc::Reader oda(tmpODB.path());
63  odc::Reader::iterator it = oda.begin();
64 
65  EXPECT((*it)[0] == std::numeric_limits<int32_t>::min());
66  ++it;
67 
68  EXPECT((*it)[0] == std::numeric_limits<int32_t>::max());
69  ++it;
70 
71  EXPECT((*it)[0] == std::numeric_limits<int32_t>::max() +
72  std::numeric_limits<int32_t>::min());
73  ++it;
74  }
75  }
76 }
77 
78 // ------------------------------------------------------------------------------------------------------
79 
80 int main(int argc, char* argv[]) {
81  return run_tests(argc, argv);
82 }
83 
void oda
int main(int argc, char *argv[])
Definition: test_minmax.cc:80
CASE("Test that the numeric limits are what we expect")
Definition: test_minmax.cc:24