Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/multi_array/test/range1.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.4 KB
Line 
1// Copyright 2002 The Trustees of Indiana University.
2
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)
6
7//  Boost.MultiArray Library
8//  Authors: Ronald Garcia
9//           Jeremy Siek
10//           Andrew Lumsdaine
11//  See http://www.boost.org/libs/multi_array for documentation.
12
13//
14// range1.cpp - test of index_range
15//
16
17
18#include "boost/multi_array/index_range.hpp"
19
20#include "boost/test/minimal.hpp"
21
22#include "boost/array.hpp"
23#include <cstddef>
24
25int
26test_main(int,char*[])
27{
28  typedef boost::detail::multi_array::index_range<int,std::size_t> range;
29
30  {
31    // typical range creation and extraction
32    range r1(-3,5);
33    BOOST_CHECK(r1.start() == -3);
34    BOOST_CHECK(r1.finish() == 5);
35    BOOST_CHECK(r1.stride() == 1);
36    BOOST_CHECK(!r1.is_degenerate());
37    BOOST_CHECK(r1.get_start(0) == -3);
38    BOOST_CHECK(r1.get_finish(100) == 5);
39  }
40
41  {
42    range r2(-3,5,2);
43    BOOST_CHECK(r2.start() == -3);
44    BOOST_CHECK(r2.finish() == 5);
45    BOOST_CHECK(r2.stride() == 2);
46    BOOST_CHECK(!r2.is_degenerate());
47  }
48
49  {
50    // degenerate creation
51    range r3(5);
52    BOOST_CHECK(r3.start() == 5);
53    BOOST_CHECK(r3.finish() == 6);
54    BOOST_CHECK(r3.stride() == 1);
55    BOOST_CHECK(r3.is_degenerate());
56  }
57
58  {
59    // default range creation
60    range r4;
61    BOOST_CHECK(r4.get_start(0) == 0);
62    BOOST_CHECK(r4.get_finish(100) == 100);
63    BOOST_CHECK(r4.stride() == 1);
64  }
65
66  {
67    // create a range using the setter methods
68    range r5 = range().stride(2).start(-3).finish(7);
69    BOOST_CHECK(r5.start() == -3);
70    BOOST_CHECK(r5.stride() == 2);
71    BOOST_CHECK(r5.finish() == 7);
72  }
73
74  // try out all the comparison operators
75  {
76    range r6 = -3 <= range().stride(2) < 7;
77    BOOST_CHECK(r6.start() == -3);
78    BOOST_CHECK(r6.stride() == 2);
79    BOOST_CHECK(r6.finish() == 7);
80  }
81
82  {
83    range r7 = -3 < range() <= 7;
84    BOOST_CHECK(r7.start() == -2);
85    BOOST_CHECK(r7.stride() == 1);
86    BOOST_CHECK(r7.finish() == 8);
87  }
88
89  // arithmetic operators
90  {
91    range r8 = range(0,5) + 2;
92    BOOST_CHECK(r8.start() == 2);
93    BOOST_CHECK(r8.stride() == 1);
94    BOOST_CHECK(r8.finish() == 7);
95  }
96
97  {
98    range r9 = range(0,5) - 2;
99    BOOST_CHECK(r9.start() == -2);
100    BOOST_CHECK(r9.stride() == 1);
101    BOOST_CHECK(r9.finish() == 3);
102  }
103
104  return boost::exit_success;
105}
Note: See TracBrowser for help on using the repository browser.