~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to src/mlib/tests/range/adaptor_test/replaced.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Boost.Range library
 
2
//
 
3
//  Copyright Neil Groves 2009. Use, modification and
 
4
//  distribution is subject to the Boost Software License, Version
 
5
//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
 
6
//  http://www.boost.org/LICENSE_1_0.txt)
 
7
//
 
8
//
 
9
// For more information, see http://www.boost.org/libs/range/
 
10
//
 
11
#include <mlib/tests/_pc_.h>
 
12
 
 
13
#include <mlib/range/adaptor/replaced.hpp>
 
14
#include <mlib/range/algorithm_ext.hpp>
 
15
 
 
16
#include <boost/assign.hpp>
 
17
 
 
18
#include <algorithm>
 
19
#include <list>
 
20
#include <set>
 
21
#include <vector>
 
22
 
 
23
namespace boost
 
24
{
 
25
    namespace
 
26
    {
 
27
        template< class Container >
 
28
        void replaced_test_impl( Container& c )
 
29
        {
 
30
            using namespace boost::adaptors;
 
31
 
 
32
            const int value_to_replace = 1;
 
33
            const int replacement_value = 0;
 
34
 
 
35
            std::vector< int > test_result1;
 
36
            boost::push_back(test_result1, c | replaced(value_to_replace, replacement_value));
 
37
 
 
38
            std::vector< int > test_result2;
 
39
            boost::push_back(test_result2, adaptors::replace(c, value_to_replace, replacement_value));
 
40
 
 
41
            std::vector< int > reference( c.begin(), c.end() );
 
42
            std::replace(reference.begin(), reference.end(), value_to_replace, replacement_value);
 
43
 
 
44
            BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
 
45
                                           test_result1.begin(), test_result1.end() );
 
46
        }
 
47
 
 
48
        template< class Container >
 
49
        void replaced_test_impl()
 
50
        {
 
51
            using namespace boost::assign;
 
52
 
 
53
            Container c;
 
54
 
 
55
            // Test empty
 
56
            replaced_test_impl(c);
 
57
 
 
58
            // Test one
 
59
            c += 1;
 
60
            replaced_test_impl(c);
 
61
 
 
62
            // Test many
 
63
            c += 1,1,1,2,2,2,3,3,3,3,3,4,5,6,6,6,7,8,9;
 
64
            replaced_test_impl(c);
 
65
        }
 
66
 
 
67
        void replaced_test()
 
68
        {
 
69
            replaced_test_impl< std::vector< int > >();
 
70
            replaced_test_impl< std::list< int > >();
 
71
            replaced_test_impl< std::set< int > >();
 
72
            replaced_test_impl< std::multiset< int > >();
 
73
        }
 
74
    }
 
75
}
 
76
 
 
77
BOOST_AUTO_TEST_CASE( test_range_replaced_test )
 
78
{
 
79
    boost::replaced_test();
 
80
}
 
81