diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/multi_array/test/range1.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/multi_array/test/range1.cpp')
-rw-r--r-- | src/boost/libs/multi_array/test/range1.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/boost/libs/multi_array/test/range1.cpp b/src/boost/libs/multi_array/test/range1.cpp new file mode 100644 index 00000000..7457bfc3 --- /dev/null +++ b/src/boost/libs/multi_array/test/range1.cpp @@ -0,0 +1,114 @@ +// Copyright 2002 The Trustees of Indiana University. + +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Boost.MultiArray Library +// Authors: Ronald Garcia +// Jeremy Siek +// Andrew Lumsdaine +// See http://www.boost.org/libs/multi_array for documentation. + +// +// range1.cpp - test of index_range +// + + +#include <boost/multi_array/index_range.hpp> + +#include <boost/core/lightweight_test.hpp> + +#include <boost/array.hpp> +#include <cstddef> + +int +main() +{ + typedef boost::detail::multi_array::index_range<int,std::size_t> range; + + { + // typical range creation and extraction + range r1(-3,5); + BOOST_TEST(r1.start() == -3); + BOOST_TEST(r1.finish() == 5); + BOOST_TEST(r1.stride() == 1); + BOOST_TEST(r1.size(0) == 8); + BOOST_TEST(!r1.is_degenerate()); + BOOST_TEST(r1.get_start(0) == -3); + BOOST_TEST(r1.get_finish(100) == 5); + } + + { + range r2(-3,5,2); + BOOST_TEST(r2.start() == -3); + BOOST_TEST(r2.finish() == 5); + BOOST_TEST(r2.stride() == 2); + BOOST_TEST(r2.size(0) == 4); + BOOST_TEST(!r2.is_degenerate()); + } + + { + // degenerate creation + range r3(5); + BOOST_TEST(r3.start() == 5); + BOOST_TEST(r3.finish() == 6); + BOOST_TEST(r3.stride() == 1); + BOOST_TEST(r3.size(0) == 1); + BOOST_TEST(r3.is_degenerate()); + } + + { + // default range creation + range r4; + BOOST_TEST(r4.get_start(0) == 0); + BOOST_TEST(r4.get_finish(100) == 100); + BOOST_TEST(r4.stride() == 1); + BOOST_TEST(r4.size(0) == 0); + } + + { + // create a range using the setter methods + range r5 = range().stride(2).start(-3).finish(7); + BOOST_TEST(r5.start() == -3); + BOOST_TEST(r5.stride() == 2); + BOOST_TEST(r5.finish() == 7); + BOOST_TEST(r5.size(0) == 5); + } + + // try out all the comparison operators + { + range r6 = -3 <= range().stride(2) < 7; + BOOST_TEST(r6.start() == -3); + BOOST_TEST(r6.stride() == 2); + BOOST_TEST(r6.finish() == 7); + BOOST_TEST(r6.size(0) == 5); + } + + { + range r7 = -3 < range() <= 7; + BOOST_TEST(r7.start() == -2); + BOOST_TEST(r7.stride() == 1); + BOOST_TEST(r7.finish() == 8); + BOOST_TEST(r7.size(0) == 10); + } + + // arithmetic operators + { + range r8 = range(0,5) + 2; + BOOST_TEST(r8.start() == 2); + BOOST_TEST(r8.stride() == 1); + BOOST_TEST(r8.finish() == 7); + BOOST_TEST(r8.size(0) == 5); + } + + { + range r9 = range(0,5) - 2; + BOOST_TEST(r9.start() == -2); + BOOST_TEST(r9.stride() == 1); + BOOST_TEST(r9.finish() == 3); + BOOST_TEST(r9.size(0) == 5); + } + + return boost::report_errors(); +} |