os/ossrv/stdcpp/tsrc/Boost_test/multi_array/src/range1.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    18 */
    19 
    20 
    21 #include "boost/multi_array/index_range.hpp"
    22 
    23 #include "boost/test/minimal.hpp"
    24 
    25 #include "boost/array.hpp"
    26 #include <cstddef>
    27 
    28 #ifdef __SYMBIAN32__
    29 #include "std_log_result.h"
    30 #define LOG_FILENAME_LINE __FILE__, __LINE__
    31 #endif
    32 
    33 int
    34 test_main(int,char*[])
    35 {
    36   typedef boost::detail::multi_array::index_range<int,std::size_t> range;
    37 
    38   {
    39     // typical range creation and extraction
    40     range r1(-3,5);
    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);
    47   }
    48 
    49   {
    50     range r2(-3,5,2);
    51     BOOST_CHECK(r2.start() == -3);
    52     BOOST_CHECK(r2.finish() == 5);
    53     BOOST_CHECK(r2.stride() == 2);
    54     BOOST_CHECK(!r2.is_degenerate());
    55   }
    56 
    57   {
    58     // degenerate creation
    59     range r3(5);
    60     BOOST_CHECK(r3.start() == 5);
    61     BOOST_CHECK(r3.finish() == 6);
    62     BOOST_CHECK(r3.stride() == 1);
    63     BOOST_CHECK(r3.is_degenerate());
    64   }
    65 
    66   {
    67     // default range creation
    68     range r4;
    69     BOOST_CHECK(r4.get_start(0) == 0);
    70     BOOST_CHECK(r4.get_finish(100) == 100);
    71     BOOST_CHECK(r4.stride() == 1);
    72   }
    73 
    74   {
    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);
    80   }
    81 
    82   // try out all the comparison operators
    83   {
    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);
    88   }
    89 
    90   {
    91     range r7 = -3 < range() <= 7;
    92     BOOST_CHECK(r7.start() == -2);
    93     BOOST_CHECK(r7.stride() == 1);
    94     BOOST_CHECK(r7.finish() == 8);
    95   }
    96 
    97   // arithmetic operators
    98   {
    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);
   103   }
   104 
   105   {
   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);
   110   }
   111 #ifdef __SYMBIAN32__
   112 if(boost::minimal_test::errors_counter() != 0)
   113    assert_failed = true;
   114    	testResultXml("range1");
   115 	close_log_file();
   116 #endif
   117 
   118   return boost::exit_success;
   119 }