comparison base/test/RangeMapperTest.h @ 880:b4787b595db3

Implement and test the interpolating and auto range mappers
author Chris Cannam
date Fri, 31 Jan 2014 17:09:02 +0000
parents eb6b6a88faed
children
comparison
equal deleted inserted replaced
879:eb6b6a88faed 880:b4787b595db3
129 QCOMPARE(rm.getValueForPosition(5), 1000.0); 129 QCOMPARE(rm.getValueForPosition(5), 1000.0);
130 QCOMPARE(rm.getValueForPosition(4), 10000.0); 130 QCOMPARE(rm.getValueForPosition(4), 10000.0);
131 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3)); 131 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3));
132 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7)); 132 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7));
133 } 133 }
134
135 void interpolatingForward()
136 {
137 InterpolatingRangeMapper::CoordMap mappings;
138 mappings[1] = 10;
139 mappings[3] = 30;
140 mappings[5] = 70;
141 InterpolatingRangeMapper rm(mappings, "x");
142 QCOMPARE(rm.getUnit(), QString("x"));
143 QCOMPARE(rm.getPositionForValue(1.0), 10);
144 QCOMPARE(rm.getPositionForValue(0.0), 10);
145 QCOMPARE(rm.getPositionForValue(5.0), 70);
146 QCOMPARE(rm.getPositionForValue(6.0), 70);
147 QCOMPARE(rm.getPositionForValue(3.0), 30);
148 QCOMPARE(rm.getPositionForValue(2.5), 25);
149 QCOMPARE(rm.getPositionForValue(4.5), 60);
150 }
151
152 void interpolatingBackward()
153 {
154 InterpolatingRangeMapper::CoordMap mappings;
155 mappings[1] = 10;
156 mappings[3] = 30;
157 mappings[5] = 70;
158 InterpolatingRangeMapper rm(mappings, "x");
159 QCOMPARE(rm.getUnit(), QString("x"));
160 QCOMPARE(rm.getValueForPosition(10), 1.0);
161 QCOMPARE(rm.getValueForPosition(9), 1.0);
162 QCOMPARE(rm.getValueForPosition(70), 5.0);
163 QCOMPARE(rm.getValueForPosition(80), 5.0);
164 QCOMPARE(rm.getValueForPosition(30), 3.0);
165 QCOMPARE(rm.getValueForPosition(25), 2.5);
166 QCOMPARE(rm.getValueForPosition(60), 4.5);
167 }
168
169 void autoLinearForward()
170 {
171 AutoRangeMapper::CoordMap mappings;
172 mappings[0.5] = 1;
173 mappings[4.0] = 8;
174 AutoRangeMapper rm1(mappings, "x");
175 QCOMPARE(rm1.getUnit(), QString("x"));
176 QCOMPARE(rm1.getType(), AutoRangeMapper::StraightLine);
177 QCOMPARE(rm1.getPositionForValue(0.5), 1);
178 QCOMPARE(rm1.getPositionForValue(4.0), 8);
179 QCOMPARE(rm1.getPositionForValue(3.0), 6);
180 QCOMPARE(rm1.getPositionForValue(3.1), 6);
181 mappings[3.0] = 6;
182 mappings[3.5] = 7;
183 AutoRangeMapper rm2(mappings, "x");
184 QCOMPARE(rm2.getUnit(), QString("x"));
185 QCOMPARE(rm2.getType(), AutoRangeMapper::StraightLine);
186 QCOMPARE(rm2.getPositionForValue(0.5), 1);
187 QCOMPARE(rm2.getPositionForValue(4.0), 8);
188 QCOMPARE(rm2.getPositionForValue(3.0), 6);
189 QCOMPARE(rm2.getPositionForValue(3.1), 6);
190 }
191
192 void autoLogForward()
193 {
194 AutoRangeMapper::CoordMap mappings;
195 mappings[10] = 3;
196 mappings[1000] = 5;
197 mappings[100000] = 7;
198 AutoRangeMapper rm1(mappings, "x");
199 QCOMPARE(rm1.getUnit(), QString("x"));
200 QCOMPARE(rm1.getType(), AutoRangeMapper::Logarithmic);
201 QCOMPARE(rm1.getPositionForValue(10.0), 3);
202 QCOMPARE(rm1.getPositionForValue(100000.0), 7);
203 QCOMPARE(rm1.getPositionForValue(1.0), 3);
204 QCOMPARE(rm1.getPositionForValue(1000000.0), 7);
205 QCOMPARE(rm1.getPositionForValue(1000.0), 5);
206 QCOMPARE(rm1.getPositionForValue(900.0), 5);
207 QCOMPARE(rm1.getPositionForValue(20000), 6);
208 mappings[100] = 4;
209 AutoRangeMapper rm2(mappings, "x");
210 QCOMPARE(rm2.getUnit(), QString("x"));
211 QCOMPARE(rm2.getType(), AutoRangeMapper::Logarithmic);
212 QCOMPARE(rm2.getPositionForValue(10.0), 3);
213 QCOMPARE(rm2.getPositionForValue(100000.0), 7);
214 QCOMPARE(rm2.getPositionForValue(1.0), 3);
215 QCOMPARE(rm2.getPositionForValue(1000000.0), 7);
216 QCOMPARE(rm2.getPositionForValue(1000.0), 5);
217 QCOMPARE(rm2.getPositionForValue(900.0), 5);
218 QCOMPARE(rm2.getPositionForValue(20000), 6);
219 }
220
221 void autoInterpolatingForward()
222 {
223 AutoRangeMapper::CoordMap mappings;
224 mappings[1] = 10;
225 mappings[3] = 30;
226 mappings[5] = 70;
227 AutoRangeMapper rm(mappings, "x");
228 QCOMPARE(rm.getUnit(), QString("x"));
229 QCOMPARE(rm.getType(), AutoRangeMapper::Interpolating);
230 QCOMPARE(rm.getPositionForValue(1.0), 10);
231 QCOMPARE(rm.getPositionForValue(0.0), 10);
232 QCOMPARE(rm.getPositionForValue(5.0), 70);
233 QCOMPARE(rm.getPositionForValue(6.0), 70);
234 QCOMPARE(rm.getPositionForValue(3.0), 30);
235 QCOMPARE(rm.getPositionForValue(2.5), 25);
236 QCOMPARE(rm.getPositionForValue(4.5), 60);
237 }
134 }; 238 };
135 239
136 #endif 240 #endif
137 241
138 242