• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2008-2010: 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 #ifndef LIBS_ICL_TEST_TEST_ICL_MAP_HPP_JOFA_090119
9 #define LIBS_ICL_TEST_TEST_ICL_MAP_HPP_JOFA_090119
10 
11 #include "portability.hpp"
12 
13 template
14 <
15     class T, class U, class Trt,
16 #if (defined(__GNUC__) && (__GNUC__ < 4)) //MEMO Can be simplified, if gcc-3.4 is obsolete
17     ICL_IntervalMap_TEMPLATE(T,U,Traits,Trt) IntervalMap
18 #else
19     ICL_IntervalMap_TEMPLATE(_T,_U,Traits,Trt) IntervalMap
20 #endif
21 >
icl_map_contains_4_bicremental_types()22 void icl_map_contains_4_bicremental_types()
23 {
24     typedef IntervalMap<T,U,Trt> IntervalMapT;
25     typedef icl::map<T,U,Trt> MapT;
26     //CL typedef std::set<T> SetT;
27     typedef typename MapT::element_type map_element_type;
28 
29     IntervalMapT itv_map_a;
30     itv_map_a.add(IDv(2,4,1)).add(IIv(6,7,3));
31 
32     MapT map_a;
33     segmental::atomize(map_a, itv_map_a);
34 
35     BOOST_CHECK_EQUAL( contains(map_a, MK_v(3)), true );
36     BOOST_CHECK_EQUAL( within(MK_v(3), map_a),   true );
37 
38     map_element_type key_value_pair(MK_v(6), MK_u(3));
39     BOOST_CHECK( contains(map_a, key_value_pair) );
40     BOOST_CHECK( within(key_value_pair, map_a) );
41 
42 }
43 
44 
45 template
46 <
47     class T, class U, class Trt,
48 #if (defined(__GNUC__) && (__GNUC__ < 4)) //MEMO Can be simplified, if gcc-3.4 is obsolete
49     ICL_IntervalMap_TEMPLATE(T,U,Traits,Trt) IntervalMap
50 #else
51     ICL_IntervalMap_TEMPLATE(_T,_U,Traits,Trt) IntervalMap
52 #endif
53 >
icl_map_find_4_bicremental_types()54 void icl_map_find_4_bicremental_types()
55 {
56     typedef IntervalMap<T,U,Trt> IntervalMapT;
57     typedef icl::map<T,U,Trt> MapT;
58 
59     IntervalMapT itv_map_a;
60     itv_map_a.add(IDv(2,4,1)).add(IIv(6,7,3));
61 
62     MapT map_a;
63     segmental::atomize(map_a, itv_map_a);
64 
65     typename MapT::const_iterator found = map_a.find(MK_v(6));
66 
67     BOOST_CHECK_EQUAL( found->second, MK_u(3) );
68     BOOST_CHECK_EQUAL( map_a(MK_v(6)), MK_u(3) );
69 
70     found = map_a.find(MK_v(5));
71 
72     BOOST_CHECK_EQUAL( found == map_a.end(), true );
73     BOOST_CHECK_EQUAL( map_a(MK_v(5)), MK_u(0) );
74 }
75 
76 
77 template
78 <
79     class T, class U, class Trt,
80 #if (defined(__GNUC__) && (__GNUC__ < 4)) //MEMO Can be simplified, if gcc-3.4 is obsolete
81     ICL_IntervalMap_TEMPLATE(T,U,Traits,Trt) IntervalMap
82 #else
83     ICL_IntervalMap_TEMPLATE(_T,_U,Traits,Trt) IntervalMap
84 #endif
85 >
icl_map_inclusion_compare_4_bicremental_types()86 void icl_map_inclusion_compare_4_bicremental_types()
87 {
88     typedef IntervalMap<T,U,Trt> IntervalMapT;
89     typedef icl::map<T,U,Trt> MapT;
90     typedef std::set<T> SetT;
91 
92     IntervalMapT itv_map_sub_a, itv_map_a, itv_map_super_a,
93                  itv_map_b, itv_map_c;
94     itv_map_sub_a.add(IDv(2,4,1)).add(IIv(6,7,3));
95     itv_map_a = itv_map_sub_a;
96     itv_map_a.add(IIv(9,9,1));
97     itv_map_c = itv_map_sub_a;
98     itv_map_c.erase(MK_v(7)).add(IIv(11,11,2));
99     itv_map_b = itv_map_a;
100     itv_map_b.set(IIv(6,7,2));
101 
102     MapT map_sub_a, map_a, map_a2, map_b, map_c;
103     segmental::atomize(map_a, itv_map_a);
104     segmental::atomize(map_b, itv_map_b);
105     segmental::atomize(map_c, itv_map_c);
106     segmental::atomize(map_sub_a, itv_map_sub_a);
107 
108     map_a2 = map_a;
109     BOOST_CHECK_EQUAL( inclusion_compare(MapT(), MapT()), inclusion::equal );
110     BOOST_CHECK_EQUAL( inclusion_compare(map_a, map_a), inclusion::equal );
111     BOOST_CHECK_EQUAL( inclusion_compare(map_a, map_a2), inclusion::equal );
112 
113     BOOST_CHECK_EQUAL( inclusion_compare(map_a, MapT()), inclusion::superset );
114     BOOST_CHECK_EQUAL( inclusion_compare(map_a, map_sub_a), inclusion::superset );
115     BOOST_CHECK_EQUAL( inclusion_compare(MapT(), map_a), inclusion::subset );
116     BOOST_CHECK_EQUAL( inclusion_compare(map_sub_a, map_a), inclusion::subset );
117 
118     BOOST_CHECK_EQUAL( inclusion_compare(map_a, map_b), inclusion::unrelated );
119     BOOST_CHECK_EQUAL( inclusion_compare(map_a, map_c), inclusion::unrelated );
120 
121     SetT set_sub_a, set_a, set_a2, set_b, set_c;
122     icl::domain(set_a,     map_a);
123     icl::domain(set_a2,    map_a2);
124     icl::domain(set_sub_a, map_sub_a);
125 
126     BOOST_CHECK_EQUAL( inclusion_compare(MapT(), SetT()), inclusion::equal );
127     BOOST_CHECK_EQUAL( inclusion_compare(SetT(), MapT()), inclusion::equal );
128     BOOST_CHECK_EQUAL( inclusion_compare(SetT(), SetT()), inclusion::equal );
129 
130     BOOST_CHECK_EQUAL( inclusion_compare(map_a, set_a), inclusion::equal );
131     BOOST_CHECK_EQUAL( inclusion_compare(set_a, map_a), inclusion::equal );
132     BOOST_CHECK_EQUAL( inclusion_compare(set_a, set_a2), inclusion::equal );
133 
134     BOOST_CHECK_EQUAL( inclusion_compare(map_a, SetT()), inclusion::superset );
135     BOOST_CHECK_EQUAL( inclusion_compare(map_a, set_sub_a), inclusion::superset );
136 
137     BOOST_CHECK_EQUAL( inclusion_compare(SetT(), map_a), inclusion::subset );
138     BOOST_CHECK_EQUAL( inclusion_compare(set_sub_a, map_a), inclusion::subset );
139 
140     BOOST_CHECK_EQUAL( inclusion_compare(set_a, SetT()), inclusion::superset );
141     BOOST_CHECK_EQUAL( inclusion_compare(set_a, set_sub_a), inclusion::superset );
142 
143     BOOST_CHECK_EQUAL( inclusion_compare(SetT(), set_a), inclusion::subset );
144     BOOST_CHECK_EQUAL( inclusion_compare(set_sub_a, set_a), inclusion::subset );
145 
146     BOOST_CHECK_EQUAL( inclusion_compare(set_a, map_c), inclusion::unrelated );
147     BOOST_CHECK_EQUAL( inclusion_compare(map_c, set_a), inclusion::unrelated );
148 
149 }
150 
151 
152 template
153 <
154     class T, class U, class Trt,
155 #if (defined(__GNUC__) && (__GNUC__ < 4)) //MEMO Can be simplified, if gcc-3.4 is obsolete
156     ICL_IntervalMap_TEMPLATE(T,U,Traits,Trt) IntervalMap
157 #else
158     ICL_IntervalMap_TEMPLATE(_T,_U,Traits,Trt) IntervalMap
159 #endif
160 >
icl_map_move_4_discrete_types()161 void icl_map_move_4_discrete_types()
162 {
163     typedef icl::map<T,U,Trt> MapT;
164     typedef typename MapT::element_type map_element_type;
165 
166     map_element_type kv_6_3(MK_v(6), MK_u(3));
167 
168     MapT map_b;
169     map_b.add(kv_6_3);
170     MapT mv_cons_1(boost::move(MapT().add(kv_6_3)));
171     MapT cp_cons_1(map_b);
172 
173     BOOST_CHECK_EQUAL( mv_cons_1, cp_cons_1 );
174     BOOST_CHECK_EQUAL( map_b, cp_cons_1 );
175 
176     MapT mv_ass_1, cp_ass_1;
177     mv_ass_1 = boost::move(MapT().add(kv_6_3));
178     cp_ass_1 = map_b;
179 
180     BOOST_CHECK_EQUAL( mv_ass_1, cp_ass_1 );
181     BOOST_CHECK_EQUAL( map_b, cp_ass_1 );
182 }
183 
184 
185 #endif // LIBS_ICL_TEST_TEST_ICL_MAP_HPP_JOFA_090119
186 
187