Update contrib.
1 // Copyright 2002 The Trustees of Indiana University.
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Boost.MultiArray Library
8 // Authors: Ronald Garcia
11 // See http://www.boost.org/libs/multi_array for documentation.
14 // range1.cpp - test of index_range
17 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
21 #include "boost/multi_array/index_range.hpp"
23 #include "boost/test/minimal.hpp"
25 #include "boost/array.hpp"
29 #include "std_log_result.h"
30 #define LOG_FILENAME_LINE __FILE__, __LINE__
34 test_main(int,char*[])
36 typedef boost::detail::multi_array::index_range<int,std::size_t> range;
39 // typical range creation and extraction
41 BOOST_CHECK(r1.start() == -3);
42 BOOST_CHECK(r1.finish() == 5);
43 BOOST_CHECK(r1.stride() == 1);
44 BOOST_CHECK(!r1.is_degenerate());
45 BOOST_CHECK(r1.get_start(0) == -3);
46 BOOST_CHECK(r1.get_finish(100) == 5);
51 BOOST_CHECK(r2.start() == -3);
52 BOOST_CHECK(r2.finish() == 5);
53 BOOST_CHECK(r2.stride() == 2);
54 BOOST_CHECK(!r2.is_degenerate());
58 // degenerate creation
60 BOOST_CHECK(r3.start() == 5);
61 BOOST_CHECK(r3.finish() == 6);
62 BOOST_CHECK(r3.stride() == 1);
63 BOOST_CHECK(r3.is_degenerate());
67 // default range creation
69 BOOST_CHECK(r4.get_start(0) == 0);
70 BOOST_CHECK(r4.get_finish(100) == 100);
71 BOOST_CHECK(r4.stride() == 1);
75 // create a range using the setter methods
76 range r5 = range().stride(2).start(-3).finish(7);
77 BOOST_CHECK(r5.start() == -3);
78 BOOST_CHECK(r5.stride() == 2);
79 BOOST_CHECK(r5.finish() == 7);
82 // try out all the comparison operators
84 range r6 = -3 <= range().stride(2) < 7;
85 BOOST_CHECK(r6.start() == -3);
86 BOOST_CHECK(r6.stride() == 2);
87 BOOST_CHECK(r6.finish() == 7);
91 range r7 = -3 < range() <= 7;
92 BOOST_CHECK(r7.start() == -2);
93 BOOST_CHECK(r7.stride() == 1);
94 BOOST_CHECK(r7.finish() == 8);
97 // arithmetic operators
99 range r8 = range(0,5) + 2;
100 BOOST_CHECK(r8.start() == 2);
101 BOOST_CHECK(r8.stride() == 1);
102 BOOST_CHECK(r8.finish() == 7);
106 range r9 = range(0,5) - 2;
107 BOOST_CHECK(r9.start() == -2);
108 BOOST_CHECK(r9.stride() == 1);
109 BOOST_CHECK(r9.finish() == 3);
112 if(boost::minimal_test::errors_counter() != 0)
113 assert_failed = true;
114 testResultXml("range1");
118 return boost::exit_success;