summaryrefslogtreecommitdiff
path: root/libs/icl/test/test_doc_code_/test_doc_code.cpp
blob: 7339a5fc1ee2a1092279f49c30c52165bdc3dc2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*-----------------------------------------------------------------------------+    
Copyright (c) 2008-2009: Joachim Faulhaber
+------------------------------------------------------------------------------+
   Distributed under the Boost Software License, Version 1.0.
      (See accompanying file LICENCE.txt or copy at
           http://www.boost.org/LICENSE_1_0.txt)
+-----------------------------------------------------------------------------*/
#define BOOST_TEST_MODULE icl::test_doc_code unit test
#include <libs/icl/test/disable_test_warnings.hpp>

#include <limits>
#include <complex>


#include <string>
#include <vector>
#include <boost/mpl/list.hpp>
#include "../unit_test_unwarned.hpp"


// interval instance types
#include "../test_type_lists.hpp"
#include "../test_value_maker.hpp"

#include <boost/type_traits/is_same.hpp>

#include <boost/icl/rational.hpp>

#include <boost/icl/detail/interval_morphism.hpp>
#include <boost/icl/interval_map.hpp>
#include "../test_laws.hpp"

using namespace std;
using namespace boost;
using namespace unit_test;
using namespace boost::icl;

BOOST_AUTO_TEST_CASE(intro_sample_telecast)
{
    // Switch on my favorite telecasts using an interval_set
    interval<int>::type news(2000, 2015);
    interval<int>::type talk_show(2245, 2330);
    interval_set<int> myTvProgram;
    myTvProgram.add(news).add(talk_show);

    // Iterating over elements (seconds) would be silly ...
    for(interval_set<int>::iterator telecast = myTvProgram.begin(); 
        telecast != myTvProgram.end(); ++telecast)
        //...so this iterates over intervals
        //TV.switch_on(*telecast);
        cout << *telecast;

    cout << endl;
}

BOOST_AUTO_TEST_CASE(interface_sample_identifiers)
{
    typedef interval_set<std::string, less, continuous_interval<std::string> > IdentifiersT;
    IdentifiersT identifiers, excluded;

    // special identifiers shall be excluded
    identifiers += continuous_interval<std::string>::right_open("a", "c");
    identifiers -= std::string("boost");
    cout << "identifiers: " << identifiers << endl;

    excluded = IdentifiersT(icl::hull(identifiers)) - identifiers;
    cout << "excluded   : " << excluded << endl;

    if(icl::contains(identifiers, std::string("boost")))
        cout << "error, identifiers.contains('boost')\n";
}

BOOST_AUTO_TEST_CASE(function_reference_element_iteration)
{
    // begin of doc code -------------------------------------------------------
    interval_set<int> inter_set;
    inter_set.add(interval<int>::right_open(0,3))
             .add(interval<int>::right_open(7,9));

    for(interval_set<int>::element_const_iterator creeper = elements_begin(inter_set); 
        creeper != elements_end(inter_set); ++creeper)
        cout << *creeper << " ";
    cout << endl;
    //Program output: 0 1 2 7 8

    for(interval_set<int>::element_reverse_iterator repeerc = elements_rbegin(inter_set); 
        repeerc != elements_rend(inter_set); ++repeerc)
        cout << *repeerc << " ";
    cout << endl;
    //Program output: 8 7 2 1 0
    // end of doc code ---------------------------------------------------------

    // Testcode
    std::stringstream result;
    for(interval_set<int>::element_iterator creeper2 = elements_begin(inter_set); 
        creeper2 != elements_end(inter_set); ++creeper2)
        result << *creeper2 << " ";

    BOOST_CHECK_EQUAL(result.str(), std::string("0 1 2 7 8 "));

    std::stringstream tluser;
    for(interval_set<int>::element_const_reverse_iterator repeerc2 
            = elements_rbegin(const_cast<const interval_set<int>&>(inter_set)); 
        repeerc2 != elements_rend(const_cast<const interval_set<int>&>(inter_set)); ++repeerc2)
        tluser << *repeerc2 << " ";

    BOOST_CHECK_EQUAL(tluser.str(), std::string("8 7 2 1 0 "));
}