1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2008-2009: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENCE.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #define BOOST_TEST_MODULE icl::test_doc_code unit test
9 #include <libs/icl/test/disable_test_warnings.hpp>
10
11 #include <limits>
12 #include <complex>
13
14
15 #include <string>
16 #include <vector>
17 #include <boost/mpl/list.hpp>
18 #include "../unit_test_unwarned.hpp"
19
20
21 // interval instance types
22 #include "../test_type_lists.hpp"
23 #include "../test_value_maker.hpp"
24
25 #include <boost/type_traits/is_same.hpp>
26
27 #include <boost/icl/rational.hpp>
28
29 #include <boost/icl/detail/interval_morphism.hpp>
30 #include <boost/icl/interval_map.hpp>
31 #include "../test_laws.hpp"
32
33 using namespace std;
34 using namespace boost;
35 using namespace unit_test;
36 using namespace boost::icl;
37
BOOST_AUTO_TEST_CASE(intro_sample_telecast)38 BOOST_AUTO_TEST_CASE(intro_sample_telecast)
39 {
40 // Switch on my favorite telecasts using an interval_set
41 interval<int>::type news(2000, 2015);
42 interval<int>::type talk_show(2245, 2330);
43 interval_set<int> myTvProgram;
44 myTvProgram.add(news).add(talk_show);
45
46 // Iterating over elements (seconds) would be silly ...
47 for(interval_set<int>::iterator telecast = myTvProgram.begin();
48 telecast != myTvProgram.end(); ++telecast)
49 //...so this iterates over intervals
50 //TV.switch_on(*telecast);
51 cout << *telecast;
52
53 cout << endl;
54 }
55
BOOST_AUTO_TEST_CASE(interface_sample_identifiers)56 BOOST_AUTO_TEST_CASE(interface_sample_identifiers)
57 {
58 typedef interval_set<std::string, less, continuous_interval<std::string> > IdentifiersT;
59 IdentifiersT identifiers, excluded;
60
61 // special identifiers shall be excluded
62 identifiers += continuous_interval<std::string>::right_open("a", "c");
63 identifiers -= std::string("boost");
64 cout << "identifiers: " << identifiers << endl;
65
66 excluded = IdentifiersT(icl::hull(identifiers)) - identifiers;
67 cout << "excluded : " << excluded << endl;
68
69 if(icl::contains(identifiers, std::string("boost")))
70 cout << "error, identifiers.contains('boost')\n";
71 }
72
BOOST_AUTO_TEST_CASE(function_reference_element_iteration)73 BOOST_AUTO_TEST_CASE(function_reference_element_iteration)
74 {
75 // begin of doc code -------------------------------------------------------
76 interval_set<int> inter_set;
77 inter_set.add(interval<int>::right_open(0,3))
78 .add(interval<int>::right_open(7,9));
79
80 for(interval_set<int>::element_const_iterator creeper = elements_begin(inter_set);
81 creeper != elements_end(inter_set); ++creeper)
82 cout << *creeper << " ";
83 cout << endl;
84 //Program output: 0 1 2 7 8
85
86 for(interval_set<int>::element_reverse_iterator repeerc = elements_rbegin(inter_set);
87 repeerc != elements_rend(inter_set); ++repeerc)
88 cout << *repeerc << " ";
89 cout << endl;
90 //Program output: 8 7 2 1 0
91 // end of doc code ---------------------------------------------------------
92
93 // Testcode
94 std::stringstream result;
95 for(interval_set<int>::element_iterator creeper2 = elements_begin(inter_set);
96 creeper2 != elements_end(inter_set); ++creeper2)
97 result << *creeper2 << " ";
98
99 BOOST_CHECK_EQUAL(result.str(), std::string("0 1 2 7 8 "));
100
101 std::stringstream tluser;
102 for(interval_set<int>::element_const_reverse_iterator repeerc2
103 = elements_rbegin(const_cast<const interval_set<int>&>(inter_set));
104 repeerc2 != elements_rend(const_cast<const interval_set<int>&>(inter_set)); ++repeerc2)
105 tluser << *repeerc2 << " ";
106
107 BOOST_CHECK_EQUAL(tluser.str(), std::string("8 7 2 1 0 "));
108 }
109
110