Files
opm-common/tests/test_CharArrayNullTerm.cpp
Bård Skaflestad 03b3be48b0 Restart *WEL Arrays: Add Foundational Helper Classes
This commit adds new helper classes,

    Opm::RestartIO::Helpers::CharArrayNullTerm<NChar>
    Opm::RestartIO::Helpers::WindowedArray<T>
    Opm::RestartIO::Helpers::WindowedMatrix<T>

the first of which represents a nul-terminated character string of
'NChar' user data (total array size is NChar + 1).  Mainly intended
for representing Fortran-compatible characters arrays--especially
for ZWEL and similar restart vectors (e.g., ZGRP).

The second two simplify working with subsets of large linear arrays,
particularly those that represent N items per well, group, or
segment.  The WindowedArray is a linear array of windows (N items
per window) packed into a std::vector<T> and the WindowedMatrix
additionally imposes a Row-by-Colum structure which is useful for
the case of N windows (each of size K) for each of M entities (e.g.,
K items for each of N connections for each of M wells).
2018-07-12 10:44:27 +02:00

100 lines
2.6 KiB
C++

#define BOOST_TEST_MODULE Aggregate_Well_Data
#include <boost/test/unit_test.hpp>
#include <opm/output/eclipse/CharArrayNullTerm.hpp>
// =====================================================================
BOOST_AUTO_TEST_SUITE(AChar8)
BOOST_AUTO_TEST_CASE (Basic_Operations)
{
// Default Constructor
{
const auto s = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{};
BOOST_CHECK_EQUAL(s.c_str(), std::string(8, ' '));
}
// Construct from Constant String
{
const auto s = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"Inj-1"};
BOOST_CHECK_EQUAL(s.c_str(), std::string{"Inj-1 "});
}
// Copy Construction
{
const auto s1 = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"Inj-1"};
const auto s2 = s1;
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
}
// Move Construction
{
const auto s1 = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"Inj-1"};
const auto s2 = s1;
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
}
// Move Construction
{
auto s1 = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"Inj-1"};
const auto s2 = std::move(s1);
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
}
// Assignment Operator
{
const auto s1 = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"Inj-1"};
auto s2 = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"Prod-2"};
s2 = s1;
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
}
// Move Assignment Operator
{
auto s1 = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"Inj-1"};
auto s2 = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"Prod-2"};
s2 = std::move(s1);
BOOST_CHECK_EQUAL(s2.c_str(), std::string{"Inj-1 "});
}
// Assign std::string
{
auto s = Opm::RestartIO::Helpers::CharArrayNullTerm<8>{"@Hi Hoo@"};
s = "Prod-2";
BOOST_CHECK_EQUAL(s.c_str(), std::string{"Prod-2 "});
}
}
BOOST_AUTO_TEST_CASE (String_Shortening)
{
// Construct from string of more than N characters
{
const auto s = Opm::RestartIO::Helpers::CharArrayNullTerm<10>{
"String too long"
};
BOOST_CHECK_EQUAL(s.c_str(), std::string{"String too"});
}
// Assign string of more than N characters
{
auto s = Opm::RestartIO::Helpers::CharArrayNullTerm<11>{};
s = "This string has too many characters";
BOOST_CHECK_EQUAL(s.c_str(), std::string{"This string"});
}
}
BOOST_AUTO_TEST_SUITE_END()