FV3 Bundle
test/lorenz95/Resolution.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 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 <fstream>
12 #include <iostream>
13 
14 #include <boost/lexical_cast.hpp>
15 #include <boost/scoped_ptr.hpp>
16 #include <boost/test/unit_test.hpp>
17 
18 #include "./TestConfig.h"
19 #include "eckit/config/LocalConfiguration.h"
20 #include "lorenz95/Resolution.h"
21 #include "test/TestFixture.h"
22 
23 namespace test {
24 
25 // -----------------------------------------------------------------------------
27  public:
29  testconf_.reset(new eckit::LocalConfiguration(TestConfig::config(), "resolution"));
30  }
32  boost::scoped_ptr<const eckit::LocalConfiguration> testconf_;
33 };
34 // -----------------------------------------------------------------------------
35 
36 // -----------------------------------------------------------------------------
37 BOOST_FIXTURE_TEST_SUITE(test_resolution, ResolutionTestFixture)
38 // -----------------------------------------------------------------------------
39  BOOST_AUTO_TEST_CASE(test_resolution_constructor) {
40  boost::scoped_ptr<lorenz95::Resolution> resol(new lorenz95::Resolution(*testconf_));
41  BOOST_CHECK(resol.get() != NULL);
42  }
43 // -----------------------------------------------------------------------------
44  BOOST_AUTO_TEST_CASE(test_resolution_copy_constructor) {
45  boost::scoped_ptr<lorenz95::Resolution> xx(new lorenz95::Resolution(*testconf_));
46  boost::scoped_ptr<lorenz95::Resolution> resol(new lorenz95::Resolution(*xx));
47  BOOST_CHECK(resol.get() != NULL);
48  }
49 // -----------------------------------------------------------------------------
50  BOOST_AUTO_TEST_CASE(test_resolution_get_npoints) {
51  boost::scoped_ptr<lorenz95::Resolution> resol(new lorenz95::Resolution(*testconf_));
52  BOOST_CHECK_EQUAL(resol->npoints(), testconf_->getInt("resol"));
53  }
54 // -----------------------------------------------------------------------------
55  BOOST_AUTO_TEST_CASE(test_resolution_stream_output) {
56  boost::scoped_ptr<lorenz95::Resolution> resol(new lorenz95::Resolution(*testconf_));
57 
58  // use the operator<< method to write the value to a file
59 
60  std::filebuf fb;
61  std::string filename("ResolutionTest.txt");
62  fb.open(filename.c_str(), std::ios::out);
63  std::ostream os(&fb);
64  os << *resol.get();
65  fb.close();
66 
67  // then read the value that was written to the file
68  int inputInt;
69  std::string input;
70  std::ifstream inputFile(filename.c_str());
71  if (inputFile.is_open()) {
72  getline(inputFile, input);
73 
74  try {
75  inputInt = boost::lexical_cast<int>(input);
76  }
77  catch(boost::bad_lexical_cast const&) {
78  // test fails because the value written to
79  // the file can't be converted to an integer
80  BOOST_ERROR("operator<< incorrectly output a non-integer");
81  }
82 
83  // it should equal the value that was used in the constructor
84  BOOST_CHECK_EQUAL(inputInt, resol->npoints());
85  } else {
86  // if we can't open the file then we can't
87  // verify that the value was correctly written
88  BOOST_ERROR("operator<< functionality cannot be determined");
89  }
90  inputFile.close();
91  }
92 // -----------------------------------------------------------------------------
93 BOOST_AUTO_TEST_SUITE_END()
94 // -----------------------------------------------------------------------------
95 
96 } // namespace test
boost::scoped_ptr< const eckit::LocalConfiguration > testconf_
*f90 *************************************************************************GNU Lesser General Public License **This file is part of the GFDL Flexible Modeling System(FMS). ! *! *FMS is free software without even the implied warranty of MERCHANTABILITY or *FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License *for more details **You should have received a copy of the GNU Lesser General Public *License along with FMS If see< http:! ***********************************************************************! this routine is used to retrieve scalar boundary data for symmetric domain. subroutine MPP_GET_BOUNDARY_2D_(field, domain, ebuffer, sbuffer, wbuffer, nbuffer, flags, &position, complete, tile_count) type(domain2D), intent(in) ::domain MPP_TYPE_, intent(in) ::field(:,:) MPP_TYPE_, intent(inout), optional ::ebuffer(:), sbuffer(:), wbuffer(:), nbuffer(:) integer, intent(in), optional ::flags, position, tile_count logical, intent(in), optional ::complete MPP_TYPE_ ::field3D(size(field, 1), size(field, 2), 1) MPP_TYPE_, allocatable, dimension(:,:) ::ebuffer2D, sbuffer2D, wbuffer2D, nbuffer2D integer ::xcount, ycount integer ::ntile logical ::need_ebuffer, need_sbuffer, need_wbuffer, need_nbuffer integer(LONG_KIND), dimension(MAX_DOMAIN_FIELDS, MAX_TILES), save ::f_addrs=-9999 integer(LONG_KIND), dimension(4, MAX_DOMAIN_FIELDS, MAX_TILES), save ::b_addrs=-9999 integer, save ::bsize(4)=0, isize=0, jsize=0, ksize=0, pos, list=0, l_size=0, upflags integer ::buffer_size(4) integer ::max_ntile, tile, update_position, ishift, jshift logical ::do_update, is_complete, set_mismatch character(len=3) ::text MPP_TYPE_ ::d_type type(overlapSpec), pointer ::bound=> NULL() ntile
Handles resolution.
Definition: Resolution.h:25
BOOST_AUTO_TEST_CASE(test_GomL95_constructor)
static const eckit::Configuration & config()
Definition: TestConfig.h:30