0
2
0
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_CONCEPT_MAPS_H |
20 | 20 |
#define LEMON_CONCEPT_MAPS_H |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/utility.h> |
23 | 23 |
#include <lemon/concept_check.h> |
24 | 24 |
|
25 | 25 |
///\ingroup concept |
26 | 26 |
///\file |
27 | 27 |
///\brief Map concepts checking classes for testing and documenting. |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup concept |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// Readable map concept |
37 | 37 |
|
38 | 38 |
/// Readable map concept. |
39 | 39 |
/// |
40 | 40 |
template<typename K, typename T> |
41 | 41 |
class ReadMap |
42 | 42 |
{ |
43 | 43 |
public: |
44 | 44 |
/// The key type of the map. |
45 | 45 |
typedef K Key; |
46 | 46 |
/// The value type of the map. (The type of objects associated with the keys). |
47 | 47 |
typedef T Value; |
48 | 48 |
|
49 | 49 |
/// Returns the value associated with the given key. |
50 |
|
|
51 |
/// Returns the value associated with the given key. |
|
52 |
/// \bug Value shouldn't need to be default constructible. |
|
53 |
Value operator[](const Key &) const { return Value(); } |
|
50 |
Value operator[](const Key &) const { |
|
51 |
return *static_cast<Value *>(0); |
|
52 |
} |
|
54 | 53 |
|
55 | 54 |
template<typename _ReadMap> |
56 | 55 |
struct Constraints { |
57 | 56 |
void constraints() { |
58 | 57 |
Value val = m[key]; |
59 | 58 |
val = m[key]; |
60 | 59 |
typename _ReadMap::Value own_val = m[own_key]; |
61 | 60 |
own_val = m[own_key]; |
62 | 61 |
|
63 | 62 |
ignore_unused_variable_warning(key); |
64 | 63 |
ignore_unused_variable_warning(val); |
65 | 64 |
ignore_unused_variable_warning(own_key); |
66 | 65 |
ignore_unused_variable_warning(own_val); |
67 | 66 |
} |
68 | 67 |
const Key& key; |
69 | 68 |
const typename _ReadMap::Key& own_key; |
70 | 69 |
const _ReadMap& m; |
71 | 70 |
}; |
72 | 71 |
|
73 | 72 |
}; |
74 | 73 |
|
75 | 74 |
|
76 | 75 |
/// Writable map concept |
77 | 76 |
|
78 | 77 |
/// Writable map concept. |
79 | 78 |
/// |
80 | 79 |
template<typename K, typename T> |
81 | 80 |
class WriteMap |
82 | 81 |
{ |
83 | 82 |
public: |
84 | 83 |
/// The key type of the map. |
85 | 84 |
typedef K Key; |
86 | 85 |
/// The value type of the map. (The type of objects associated with the keys). |
87 | 86 |
typedef T Value; |
88 | 87 |
|
89 | 88 |
/// Sets the value associated with the given key. |
90 | 89 |
void set(const Key &, const Value &) {} |
91 | 90 |
|
92 | 91 |
/// Default constructor. |
93 | 92 |
WriteMap() {} |
94 | 93 |
|
95 | 94 |
template <typename _WriteMap> |
96 | 95 |
struct Constraints { |
97 | 96 |
void constraints() { |
98 | 97 |
m.set(key, val); |
99 | 98 |
m.set(own_key, own_val); |
100 | 99 |
|
101 | 100 |
ignore_unused_variable_warning(key); |
102 | 101 |
ignore_unused_variable_warning(val); |
103 | 102 |
ignore_unused_variable_warning(own_key); |
104 | 103 |
ignore_unused_variable_warning(own_val); |
105 | 104 |
} |
106 | 105 |
const Key& key; |
107 | 106 |
const Value& val; |
108 | 107 |
const typename _WriteMap::Key& own_key; |
109 | 108 |
const typename _WriteMap::Value own_val; |
110 | 109 |
_WriteMap& m; |
111 | 110 |
}; |
112 | 111 |
}; |
113 | 112 |
|
114 | 113 |
/// Read/writable map concept |
115 | 114 |
|
116 | 115 |
/// Read/writable map concept. |
117 | 116 |
/// |
118 | 117 |
template<typename K, typename T> |
119 | 118 |
class ReadWriteMap : public ReadMap<K,T>, |
120 | 119 |
public WriteMap<K,T> |
121 | 120 |
{ |
122 | 121 |
public: |
123 | 122 |
/// The key type of the map. |
124 | 123 |
typedef K Key; |
125 | 124 |
/// The value type of the map. (The type of objects associated with the keys). |
126 | 125 |
typedef T Value; |
127 | 126 |
|
128 | 127 |
/// Returns the value associated with the given key. |
129 |
Value operator[](const Key &) const { |
|
128 |
Value operator[](const Key &) const { |
|
129 |
return *static_cast<Value *>(0); |
|
130 |
} |
|
130 | 131 |
|
131 | 132 |
/// Sets the value associated with the given key. |
132 | 133 |
void set(const Key &, const Value &) {} |
133 | 134 |
|
134 | 135 |
template<typename _ReadWriteMap> |
135 | 136 |
struct Constraints { |
136 | 137 |
void constraints() { |
137 | 138 |
checkConcept<ReadMap<K, T>, _ReadWriteMap >(); |
138 | 139 |
checkConcept<WriteMap<K, T>, _ReadWriteMap >(); |
139 | 140 |
} |
140 | 141 |
}; |
141 | 142 |
}; |
142 | 143 |
|
143 | 144 |
|
144 | 145 |
/// Dereferable map concept |
145 | 146 |
|
146 | 147 |
/// Dereferable map concept. |
147 | 148 |
/// |
148 | 149 |
template<typename K, typename T, typename R, typename CR> |
149 | 150 |
class ReferenceMap : public ReadWriteMap<K,T> |
150 | 151 |
{ |
151 | 152 |
public: |
152 | 153 |
/// Tag for reference maps. |
153 | 154 |
typedef True ReferenceMapTag; |
154 | 155 |
/// The key type of the map. |
155 | 156 |
typedef K Key; |
156 | 157 |
/// The value type of the map. (The type of objects associated with the keys). |
157 | 158 |
typedef T Value; |
158 | 159 |
/// The reference type of the map. |
159 | 160 |
typedef R Reference; |
160 | 161 |
/// The const reference type of the map. |
161 | 162 |
typedef CR ConstReference; |
162 | 163 |
|
163 |
protected: |
|
164 |
Value tmp; |
|
165 | 164 |
public: |
166 | 165 |
|
167 | 166 |
/// Returns a reference to the value associated with the given key. |
168 |
Reference operator[](const Key &) { |
|
167 |
Reference operator[](const Key &) { |
|
168 |
return *static_cast<Value *>(0); |
|
169 |
} |
|
169 | 170 |
|
170 | 171 |
/// Returns a const reference to the value associated with the given key. |
171 |
ConstReference operator[](const Key &) const { |
|
172 |
ConstReference operator[](const Key &) const { |
|
173 |
return *static_cast<Value *>(0); |
|
174 |
} |
|
172 | 175 |
|
173 | 176 |
/// Sets the value associated with the given key. |
174 | 177 |
void set(const Key &k,const Value &t) { operator[](k)=t; } |
175 | 178 |
|
176 | 179 |
template<typename _ReferenceMap> |
177 | 180 |
struct Constraints { |
178 | 181 |
void constraints() { |
179 | 182 |
checkConcept<ReadWriteMap<K, T>, _ReferenceMap >(); |
180 | 183 |
ref = m[key]; |
181 | 184 |
m[key] = val; |
182 | 185 |
m[key] = ref; |
183 | 186 |
m[key] = cref; |
184 | 187 |
own_ref = m[own_key]; |
185 | 188 |
m[own_key] = own_val; |
186 | 189 |
m[own_key] = own_ref; |
187 | 190 |
m[own_key] = own_cref; |
188 | 191 |
m[key] = m[own_key]; |
189 | 192 |
m[own_key] = m[key]; |
190 | 193 |
} |
191 | 194 |
const Key& key; |
192 | 195 |
Value& val; |
193 | 196 |
Reference ref; |
194 | 197 |
ConstReference cref; |
195 | 198 |
const typename _ReferenceMap::Key& own_key; |
196 | 199 |
typename _ReferenceMap::Value& own_val; |
197 | 200 |
typename _ReferenceMap::Reference own_ref; |
198 | 201 |
typename _ReferenceMap::ConstReference own_cref; |
199 | 202 |
_ReferenceMap& m; |
200 | 203 |
}; |
201 | 204 |
}; |
202 | 205 |
|
203 | 206 |
// @} |
204 | 207 |
|
205 | 208 |
} //namespace concepts |
206 | 209 |
|
207 | 210 |
} //namespace lemon |
208 | 211 |
|
209 | 212 |
#endif // LEMON_CONCEPT_MAPS_H |
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <deque> |
20 | 20 |
#include <set> |
21 | 21 |
|
22 | 22 |
#include <lemon/concept_check.h> |
23 | 23 |
#include <lemon/concepts/maps.h> |
24 | 24 |
#include <lemon/maps.h> |
25 | 25 |
|
26 | 26 |
#include "test_tools.h" |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
using namespace lemon::concepts; |
30 | 30 |
|
31 | 31 |
struct A {}; |
32 | 32 |
inline bool operator<(A, A) { return true; } |
33 | 33 |
struct B {}; |
34 | 34 |
|
35 |
class C { |
|
36 |
int x; |
|
37 |
public: |
|
38 |
C(int _x) : x(_x) {} |
|
39 |
}; |
|
40 |
|
|
35 | 41 |
class F { |
36 | 42 |
public: |
37 | 43 |
typedef A argument_type; |
38 | 44 |
typedef B result_type; |
39 | 45 |
|
40 | 46 |
B operator()(const A&) const { return B(); } |
41 | 47 |
private: |
42 | 48 |
F& operator=(const F&); |
43 | 49 |
}; |
44 | 50 |
|
45 | 51 |
int func(A) { return 3; } |
46 | 52 |
|
47 | 53 |
int binc(int a, B) { return a+1; } |
48 | 54 |
|
49 | 55 |
typedef ReadMap<A, double> DoubleMap; |
50 | 56 |
typedef ReadWriteMap<A, double> DoubleWriteMap; |
51 | 57 |
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap; |
52 | 58 |
|
53 | 59 |
typedef ReadMap<A, bool> BoolMap; |
54 | 60 |
typedef ReadWriteMap<A, bool> BoolWriteMap; |
55 | 61 |
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap; |
56 | 62 |
|
57 | 63 |
int main() |
58 | 64 |
{ |
59 | 65 |
// Map concepts |
60 | 66 |
checkConcept<ReadMap<A,B>, ReadMap<A,B> >(); |
67 |
checkConcept<ReadMap<A,C>, ReadMap<A,C> >(); |
|
61 | 68 |
checkConcept<WriteMap<A,B>, WriteMap<A,B> >(); |
69 |
checkConcept<WriteMap<A,C>, WriteMap<A,C> >(); |
|
62 | 70 |
checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >(); |
71 |
checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >(); |
|
63 | 72 |
checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >(); |
73 |
checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >(); |
|
64 | 74 |
|
65 | 75 |
// NullMap |
66 | 76 |
{ |
67 | 77 |
checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >(); |
68 | 78 |
NullMap<A,B> map1; |
69 | 79 |
NullMap<A,B> map2 = map1; |
70 | 80 |
map1 = nullMap<A,B>(); |
71 | 81 |
} |
72 | 82 |
|
73 | 83 |
// ConstMap |
74 | 84 |
{ |
75 | 85 |
checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >(); |
76 | 86 |
ConstMap<A,B> map1; |
77 | 87 |
ConstMap<A,B> map2(B()); |
78 | 88 |
ConstMap<A,B> map3 = map1; |
79 | 89 |
map1 = constMap<A>(B()); |
80 | 90 |
map1.setAll(B()); |
81 | 91 |
|
82 | 92 |
checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >(); |
83 | 93 |
check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap"); |
84 | 94 |
|
85 | 95 |
checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >(); |
86 | 96 |
ConstMap<A,Const<int,10> > map4; |
87 | 97 |
ConstMap<A,Const<int,10> > map5 = map4; |
88 | 98 |
map4 = map5; |
89 | 99 |
check(map4[A()] == 10 && map5[A()] == 10, "Something is wrong with ConstMap"); |
90 | 100 |
} |
91 | 101 |
|
92 | 102 |
// IdentityMap |
93 | 103 |
{ |
94 | 104 |
checkConcept<ReadMap<A,A>, IdentityMap<A> >(); |
95 | 105 |
IdentityMap<A> map1; |
96 | 106 |
IdentityMap<A> map2 = map1; |
97 | 107 |
map1 = identityMap<A>(); |
98 | 108 |
|
99 | 109 |
checkConcept<ReadMap<double,double>, IdentityMap<double> >(); |
100 | 110 |
check(identityMap<double>()[1.0] == 1.0 && identityMap<double>()[3.14] == 3.14, |
101 | 111 |
"Something is wrong with IdentityMap"); |
102 | 112 |
} |
103 | 113 |
|
104 | 114 |
// RangeMap |
105 | 115 |
{ |
106 | 116 |
checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >(); |
107 | 117 |
RangeMap<B> map1; |
108 | 118 |
RangeMap<B> map2(10); |
109 | 119 |
RangeMap<B> map3(10,B()); |
110 | 120 |
RangeMap<B> map4 = map1; |
111 | 121 |
RangeMap<B> map5 = rangeMap<B>(); |
112 | 122 |
RangeMap<B> map6 = rangeMap<B>(10); |
113 | 123 |
RangeMap<B> map7 = rangeMap(10,B()); |
114 | 124 |
|
115 | 125 |
checkConcept< ReferenceMap<int, double, double&, const double&>, |
116 | 126 |
RangeMap<double> >(); |
117 | 127 |
std::vector<double> v(10, 0); |
118 | 128 |
v[5] = 100; |
119 | 129 |
RangeMap<double> map8(v); |
120 | 130 |
RangeMap<double> map9 = rangeMap(v); |
121 | 131 |
check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100, |
122 | 132 |
"Something is wrong with RangeMap"); |
123 | 133 |
} |
124 | 134 |
|
125 | 135 |
// SparseMap |
126 | 136 |
{ |
127 | 137 |
checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >(); |
128 | 138 |
SparseMap<A,B> map1; |
129 | 139 |
SparseMap<A,B> map2(B()); |
130 | 140 |
SparseMap<A,B> map3 = sparseMap<A,B>(); |
131 | 141 |
SparseMap<A,B> map4 = sparseMap<A>(B()); |
132 | 142 |
|
133 | 143 |
checkConcept< ReferenceMap<double, int, int&, const int&>, |
134 | 144 |
SparseMap<double, int> >(); |
135 | 145 |
std::map<double, int> m; |
136 | 146 |
SparseMap<double, int> map5(m); |
137 | 147 |
SparseMap<double, int> map6(m,10); |
138 | 148 |
SparseMap<double, int> map7 = sparseMap(m); |
139 | 149 |
SparseMap<double, int> map8 = sparseMap(m,10); |
140 | 150 |
|
141 | 151 |
check(map5[1.0] == 0 && map5[3.14] == 0 && map6[1.0] == 10 && map6[3.14] == 10, |
142 | 152 |
"Something is wrong with SparseMap"); |
143 | 153 |
map5[1.0] = map6[3.14] = 100; |
144 | 154 |
check(map5[1.0] == 100 && map5[3.14] == 0 && map6[1.0] == 10 && map6[3.14] == 100, |
145 | 155 |
"Something is wrong with SparseMap"); |
146 | 156 |
} |
147 | 157 |
|
148 | 158 |
// ComposeMap |
149 | 159 |
{ |
150 | 160 |
typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap; |
151 | 161 |
checkConcept<ReadMap<B,double>, CompMap>(); |
152 | 162 |
CompMap map1(DoubleMap(),ReadMap<B,A>()); |
153 | 163 |
CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>()); |
154 | 164 |
|
155 | 165 |
SparseMap<double, bool> m1(false); m1[3.14] = true; |
156 | 166 |
RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14; |
157 | 167 |
check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], "Something is wrong with ComposeMap") |
158 | 168 |
} |
159 | 169 |
|
160 | 170 |
// CombineMap |
161 | 171 |
{ |
162 | 172 |
typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap; |
163 | 173 |
checkConcept<ReadMap<A,double>, CombMap>(); |
164 | 174 |
CombMap map1(DoubleMap(), DoubleMap()); |
165 | 175 |
CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>()); |
166 | 176 |
|
167 | 177 |
check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3, |
168 | 178 |
"Something is wrong with CombineMap"); |
169 | 179 |
} |
170 | 180 |
|
171 | 181 |
// FunctorToMap, MapToFunctor |
172 | 182 |
{ |
173 | 183 |
checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >(); |
174 | 184 |
checkConcept<ReadMap<A,B>, FunctorToMap<F> >(); |
175 | 185 |
FunctorToMap<F> map1; |
176 | 186 |
FunctorToMap<F> map2(F()); |
177 | 187 |
B b = functorToMap(F())[A()]; |
178 | 188 |
|
179 | 189 |
checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); |
180 | 190 |
MapToFunctor<ReadMap<A,B> > map(ReadMap<A,B>()); |
181 | 191 |
|
182 | 192 |
check(functorToMap(&func)[A()] == 3, "Something is wrong with FunctorToMap"); |
183 | 193 |
check(mapToFunctor(constMap<A,int>(2))(A()) == 2, "Something is wrong with MapToFunctor"); |
184 | 194 |
check(mapToFunctor(functorToMap(&func))(A()) == 3 && mapToFunctor(functorToMap(&func))[A()] == 3, |
185 | 195 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
186 | 196 |
check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2, |
187 | 197 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
188 | 198 |
} |
189 | 199 |
|
190 | 200 |
// ConvertMap |
191 | 201 |
{ |
192 | 202 |
checkConcept<ReadMap<double,double>, ConvertMap<ReadMap<double, int>, double> >(); |
193 | 203 |
ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true)); |
194 | 204 |
ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false)); |
195 | 205 |
} |
196 | 206 |
|
197 | 207 |
// ForkMap |
198 | 208 |
{ |
199 | 209 |
checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >(); |
200 | 210 |
|
201 | 211 |
typedef RangeMap<double> RM; |
202 | 212 |
typedef SparseMap<int, double> SM; |
203 | 213 |
RM m1(10, -1); |
204 | 214 |
SM m2(-1); |
205 | 215 |
checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >(); |
206 | 216 |
checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >(); |
207 | 217 |
ForkMap<RM, SM> map1(m1,m2); |
208 | 218 |
ForkMap<SM, RM> map2 = forkMap(m2,m1); |
209 | 219 |
map2.set(5, 10); |
210 | 220 |
check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && m2[5] == 10 && map2[1] == -1 && map2[5] == 10, |
211 | 221 |
"Something is wrong with ForkMap"); |
212 | 222 |
} |
213 | 223 |
|
214 | 224 |
// Arithmetic maps: |
215 | 225 |
// - AddMap, SubMap, MulMap, DivMap |
216 | 226 |
// - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap |
217 | 227 |
// - NegMap, NegWriteMap, AbsMap |
218 | 228 |
{ |
219 | 229 |
checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >(); |
220 | 230 |
checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >(); |
221 | 231 |
checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >(); |
222 | 232 |
checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >(); |
223 | 233 |
|
224 | 234 |
ConstMap<int, double> c1(1.0), c2(3.14); |
225 | 235 |
IdentityMap<int> im; |
226 | 236 |
ConvertMap<IdentityMap<int>, double> id(im); |
227 | 237 |
check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0, "Something is wrong with AddMap"); |
228 | 238 |
check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0, "Something is wrong with SubMap"); |
229 | 239 |
check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28, "Something is wrong with MulMap"); |
230 | 240 |
check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57, "Something is wrong with DivMap"); |
231 | 241 |
|
232 | 242 |
checkConcept<DoubleMap, ShiftMap<DoubleMap> >(); |
233 | 243 |
checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >(); |
234 | 244 |
checkConcept<DoubleMap, ScaleMap<DoubleMap> >(); |
235 | 245 |
checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >(); |
236 | 246 |
checkConcept<DoubleMap, NegMap<DoubleMap> >(); |
237 | 247 |
checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >(); |
238 | 248 |
checkConcept<DoubleMap, AbsMap<DoubleMap> >(); |
239 | 249 |
|
240 | 250 |
check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0, |
241 | 251 |
"Something is wrong with ShiftMap"); |
242 | 252 |
check(shiftWriteMap(id, 2.0)[1] == 3.0 && shiftWriteMap(id, 2.0)[10] == 12.0, |
243 | 253 |
"Something is wrong with ShiftWriteMap"); |
244 | 254 |
check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0, |
245 | 255 |
"Something is wrong with ScaleMap"); |
246 | 256 |
check(scaleWriteMap(id, 2.0)[1] == 2.0 && scaleWriteMap(id, 2.0)[10] == 20.0, |
247 | 257 |
"Something is wrong with ScaleWriteMap"); |
248 | 258 |
check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0, |
249 | 259 |
"Something is wrong with NegMap"); |
250 | 260 |
check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0, |
251 | 261 |
"Something is wrong with NegWriteMap"); |
252 | 262 |
check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0, |
253 | 263 |
"Something is wrong with AbsMap"); |
254 | 264 |
} |
255 | 265 |
|
256 | 266 |
// Logical maps: |
257 | 267 |
// - TrueMap, FalseMap |
258 | 268 |
// - AndMap, OrMap |
259 | 269 |
// - NotMap, NotWriteMap |
260 | 270 |
// - EqualMap, LessMap |
261 | 271 |
{ |
262 | 272 |
checkConcept<BoolMap, TrueMap<A> >(); |
263 | 273 |
checkConcept<BoolMap, FalseMap<A> >(); |
264 | 274 |
checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >(); |
265 | 275 |
checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >(); |
266 | 276 |
checkConcept<BoolMap, NotMap<BoolMap> >(); |
267 | 277 |
checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >(); |
268 | 278 |
checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >(); |
269 | 279 |
checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >(); |
270 | 280 |
|
271 | 281 |
TrueMap<int> tm; |
272 | 282 |
FalseMap<int> fm; |
273 | 283 |
RangeMap<bool> rm(2); |
274 | 284 |
rm[0] = true; rm[1] = false; |
275 | 285 |
check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && !andMap(fm,rm)[0] && !andMap(fm,rm)[1], |
276 | 286 |
"Something is wrong with AndMap"); |
277 | 287 |
check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && orMap(fm,rm)[0] && !orMap(fm,rm)[1], |
278 | 288 |
"Something is wrong with OrMap"); |
279 | 289 |
check(!notMap(rm)[0] && notMap(rm)[1], "Something is wrong with NotMap"); |
280 | 290 |
check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], "Something is wrong with NotWriteMap"); |
281 | 291 |
|
282 | 292 |
ConstMap<int, double> cm(2.0); |
283 | 293 |
IdentityMap<int> im; |
284 | 294 |
ConvertMap<IdentityMap<int>, double> id(im); |
285 | 295 |
check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3], |
286 | 296 |
"Something is wrong with LessMap"); |
287 | 297 |
check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3], |
288 | 298 |
"Something is wrong with EqualMap"); |
289 | 299 |
} |
290 | 300 |
|
291 | 301 |
return 0; |
292 | 302 |
} |
0 comments (0 inline)