mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Added unit test for Span class.
This commit is contained in:
parent
cd42d4af34
commit
937df8869b
@ -41,6 +41,7 @@ list (APPEND MAIN_SOURCE_FILES
|
|||||||
list (APPEND TEST_SOURCE_FILES
|
list (APPEND TEST_SOURCE_FILES
|
||||||
tests/test_block.cpp
|
tests/test_block.cpp
|
||||||
tests/test_boprops_ad.cpp
|
tests/test_boprops_ad.cpp
|
||||||
|
tests/test_span.cpp
|
||||||
tests/test_syntax.cpp
|
tests/test_syntax.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
69
tests/test_span.cpp
Normal file
69
tests/test_span.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2013 SINTEF ICT, Applied Mathematics.
|
||||||
|
|
||||||
|
This file is part of the Open Porous Media project (OPM).
|
||||||
|
|
||||||
|
OPM is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OPM is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; 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 General Public License
|
||||||
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#if HAVE_DYNAMIC_BOOST_TEST
|
||||||
|
#define BOOST_TEST_DYN_LINK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE SpanTest
|
||||||
|
|
||||||
|
#include <opm/autodiff/AutoDiffHelpers.hpp>
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(OneArgConstr)
|
||||||
|
{
|
||||||
|
const int num = 4;
|
||||||
|
const Span s(num);
|
||||||
|
BOOST_CHECK(s.size() == num);
|
||||||
|
for (int i = 0; i < num; ++i) {
|
||||||
|
BOOST_CHECK(s[i] == i);
|
||||||
|
}
|
||||||
|
int count = 0;
|
||||||
|
for (Span::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||||
|
BOOST_CHECK(*it == count);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
BOOST_CHECK(count = num);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(ThreeArgConstr)
|
||||||
|
{
|
||||||
|
const int num = 3;
|
||||||
|
const int stride = 7;
|
||||||
|
const int start = 5;
|
||||||
|
const int seq[num] = { start, start + 1*stride, start + 2*stride };
|
||||||
|
|
||||||
|
const Span s(num, stride, start);
|
||||||
|
BOOST_CHECK(s.size() == num);
|
||||||
|
for (int i = 0; i < num; ++i) {
|
||||||
|
BOOST_CHECK(s[i] == seq[i]);
|
||||||
|
}
|
||||||
|
int count = 0;
|
||||||
|
for (Span::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||||
|
BOOST_CHECK(*it == seq[count]);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
BOOST_CHECK(count = num);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user