comparison base/test/TestRangeMapper.h @ 1429:48e9f538e6e9

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents ccc8658914ef
children
comparison
equal deleted inserted replaced
1428:87ae75da6527 1429:48e9f538e6e9
30 Q_OBJECT 30 Q_OBJECT
31 31
32 private slots: 32 private slots:
33 void linearUpForward() 33 void linearUpForward()
34 { 34 {
35 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", false); 35 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", false);
36 QCOMPARE(rm.getUnit(), QString("x")); 36 QCOMPARE(rm.getUnit(), QString("x"));
37 QCOMPARE(rm.getPositionForValue(0.5), 1); 37 QCOMPARE(rm.getPositionForValue(0.5), 1);
38 QCOMPARE(rm.getPositionForValue(4.0), 8); 38 QCOMPARE(rm.getPositionForValue(4.0), 8);
39 QCOMPARE(rm.getPositionForValue(3.0), 6); 39 QCOMPARE(rm.getPositionForValue(3.0), 6);
40 QCOMPARE(rm.getPositionForValue(3.1), 6); 40 QCOMPARE(rm.getPositionForValue(3.1), 6);
41 QCOMPARE(rm.getPositionForValue(3.4), 7); 41 QCOMPARE(rm.getPositionForValue(3.4), 7);
42 QCOMPARE(rm.getPositionForValue(0.2), 1); 42 QCOMPARE(rm.getPositionForValue(0.2), 1);
43 QCOMPARE(rm.getPositionForValue(-12), 1); 43 QCOMPARE(rm.getPositionForValue(-12), 1);
44 QCOMPARE(rm.getPositionForValue(6.1), 8); 44 QCOMPARE(rm.getPositionForValue(6.1), 8);
45 QCOMPARE(rm.getPositionForValueUnclamped(3.0), 6); 45 QCOMPARE(rm.getPositionForValueUnclamped(3.0), 6);
46 QCOMPARE(rm.getPositionForValueUnclamped(0.2), 0); 46 QCOMPARE(rm.getPositionForValueUnclamped(0.2), 0);
47 QCOMPARE(rm.getPositionForValueUnclamped(-12), -24); 47 QCOMPARE(rm.getPositionForValueUnclamped(-12), -24);
48 QCOMPARE(rm.getPositionForValueUnclamped(6.1), 12); 48 QCOMPARE(rm.getPositionForValueUnclamped(6.1), 12);
49 } 49 }
50 50
51 void linearDownForward() 51 void linearDownForward()
52 { 52 {
53 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", true); 53 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", true);
54 QCOMPARE(rm.getUnit(), QString("x")); 54 QCOMPARE(rm.getUnit(), QString("x"));
55 QCOMPARE(rm.getPositionForValue(0.5), 8); 55 QCOMPARE(rm.getPositionForValue(0.5), 8);
56 QCOMPARE(rm.getPositionForValue(4.0), 1); 56 QCOMPARE(rm.getPositionForValue(4.0), 1);
57 QCOMPARE(rm.getPositionForValue(3.0), 3); 57 QCOMPARE(rm.getPositionForValue(3.0), 3);
58 QCOMPARE(rm.getPositionForValue(3.1), 3); 58 QCOMPARE(rm.getPositionForValue(3.1), 3);
59 QCOMPARE(rm.getPositionForValue(3.4), 2); 59 QCOMPARE(rm.getPositionForValue(3.4), 2);
60 QCOMPARE(rm.getPositionForValue(0.2), 8); 60 QCOMPARE(rm.getPositionForValue(0.2), 8);
61 QCOMPARE(rm.getPositionForValue(-12), 8); 61 QCOMPARE(rm.getPositionForValue(-12), 8);
62 QCOMPARE(rm.getPositionForValue(6.1), 1); 62 QCOMPARE(rm.getPositionForValue(6.1), 1);
63 QCOMPARE(rm.getPositionForValueUnclamped(3.0), 3); 63 QCOMPARE(rm.getPositionForValueUnclamped(3.0), 3);
64 QCOMPARE(rm.getPositionForValueUnclamped(0.2), 9); 64 QCOMPARE(rm.getPositionForValueUnclamped(0.2), 9);
65 QCOMPARE(rm.getPositionForValueUnclamped(-12), 33); 65 QCOMPARE(rm.getPositionForValueUnclamped(-12), 33);
66 QCOMPARE(rm.getPositionForValueUnclamped(6.1), -3); 66 QCOMPARE(rm.getPositionForValueUnclamped(6.1), -3);
67 } 67 }
68 68
69 void linearUpBackward() 69 void linearUpBackward()
70 { 70 {
71 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", false); 71 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", false);
72 QCOMPARE(rm.getUnit(), QString("x")); 72 QCOMPARE(rm.getUnit(), QString("x"));
73 QCOMPARE(rm.getValueForPosition(1), 0.5); 73 QCOMPARE(rm.getValueForPosition(1), 0.5);
74 QCOMPARE(rm.getValueForPosition(8), 4.0); 74 QCOMPARE(rm.getValueForPosition(8), 4.0);
75 QCOMPARE(rm.getValueForPosition(6), 3.0); 75 QCOMPARE(rm.getValueForPosition(6), 3.0);
76 QCOMPARE(rm.getValueForPosition(7), 3.5); 76 QCOMPARE(rm.getValueForPosition(7), 3.5);
77 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(1)); 77 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(1));
78 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(8)); 78 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(8));
79 QCOMPARE(rm.getValueForPositionUnclamped(6), 3.0); 79 QCOMPARE(rm.getValueForPositionUnclamped(6), 3.0);
80 QCOMPARE(rm.getValueForPositionUnclamped(0) + 1.0, 0.0 + 1.0); 80 QCOMPARE(rm.getValueForPositionUnclamped(0) + 1.0, 0.0 + 1.0);
81 QCOMPARE(rm.getValueForPositionUnclamped(-24), -12.0); 81 QCOMPARE(rm.getValueForPositionUnclamped(-24), -12.0);
82 QCOMPARE(rm.getValueForPositionUnclamped(12), 6.0); 82 QCOMPARE(rm.getValueForPositionUnclamped(12), 6.0);
83 } 83 }
84 84
85 void linearDownBackward() 85 void linearDownBackward()
86 { 86 {
87 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", true); 87 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", true);
88 QCOMPARE(rm.getUnit(), QString("x")); 88 QCOMPARE(rm.getUnit(), QString("x"));
89 QCOMPARE(rm.getValueForPosition(8), 0.5); 89 QCOMPARE(rm.getValueForPosition(8), 0.5);
90 QCOMPARE(rm.getValueForPosition(1), 4.0); 90 QCOMPARE(rm.getValueForPosition(1), 4.0);
91 QCOMPARE(rm.getValueForPosition(3), 3.0); 91 QCOMPARE(rm.getValueForPosition(3), 3.0);
92 QCOMPARE(rm.getValueForPosition(2), 3.5); 92 QCOMPARE(rm.getValueForPosition(2), 3.5);
93 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(1)); 93 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(1));
94 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(8)); 94 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(8));
95 QCOMPARE(rm.getValueForPositionUnclamped(3), 3.0); 95 QCOMPARE(rm.getValueForPositionUnclamped(3), 3.0);
96 QCOMPARE(rm.getValueForPositionUnclamped(9) + 1.0, 0.0 + 1.0); 96 QCOMPARE(rm.getValueForPositionUnclamped(9) + 1.0, 0.0 + 1.0);
97 QCOMPARE(rm.getValueForPositionUnclamped(33), -12.0); 97 QCOMPARE(rm.getValueForPositionUnclamped(33), -12.0);
98 QCOMPARE(rm.getValueForPositionUnclamped(-3), 6.0); 98 QCOMPARE(rm.getValueForPositionUnclamped(-3), 6.0);
99 } 99 }
100 100
101 void logUpForward() 101 void logUpForward()
102 { 102 {
103 LogRangeMapper rm(3, 7, 10, 100000, "x", false); 103 LogRangeMapper rm(3, 7, 10, 100000, "x", false);
104 QCOMPARE(rm.getUnit(), QString("x")); 104 QCOMPARE(rm.getUnit(), QString("x"));
105 QCOMPARE(rm.getPositionForValue(10.0), 3); 105 QCOMPARE(rm.getPositionForValue(10.0), 3);
106 QCOMPARE(rm.getPositionForValue(100000.0), 7); 106 QCOMPARE(rm.getPositionForValue(100000.0), 7);
107 QCOMPARE(rm.getPositionForValue(1.0), 3); 107 QCOMPARE(rm.getPositionForValue(1.0), 3);
108 QCOMPARE(rm.getPositionForValue(1000000.0), 7); 108 QCOMPARE(rm.getPositionForValue(1000000.0), 7);
109 QCOMPARE(rm.getPositionForValue(1000.0), 5); 109 QCOMPARE(rm.getPositionForValue(1000.0), 5);
110 QCOMPARE(rm.getPositionForValue(900.0), 5); 110 QCOMPARE(rm.getPositionForValue(900.0), 5);
111 QCOMPARE(rm.getPositionForValue(20000), 6); 111 QCOMPARE(rm.getPositionForValue(20000), 6);
112 QCOMPARE(rm.getPositionForValueUnclamped(1.0), 2); 112 QCOMPARE(rm.getPositionForValueUnclamped(1.0), 2);
113 QCOMPARE(rm.getPositionForValueUnclamped(1000000.0), 8); 113 QCOMPARE(rm.getPositionForValueUnclamped(1000000.0), 8);
114 QCOMPARE(rm.getPositionForValueUnclamped(1000.0), 5); 114 QCOMPARE(rm.getPositionForValueUnclamped(1000.0), 5);
115 } 115 }
116 116
117 void logDownForward() 117 void logDownForward()
118 { 118 {
119 LogRangeMapper rm(3, 7, 10, 100000, "x", true); 119 LogRangeMapper rm(3, 7, 10, 100000, "x", true);
120 QCOMPARE(rm.getUnit(), QString("x")); 120 QCOMPARE(rm.getUnit(), QString("x"));
121 QCOMPARE(rm.getPositionForValue(10.0), 7); 121 QCOMPARE(rm.getPositionForValue(10.0), 7);
122 QCOMPARE(rm.getPositionForValue(100000.0), 3); 122 QCOMPARE(rm.getPositionForValue(100000.0), 3);
123 QCOMPARE(rm.getPositionForValue(1.0), 7); 123 QCOMPARE(rm.getPositionForValue(1.0), 7);
124 QCOMPARE(rm.getPositionForValue(1000000.0), 3); 124 QCOMPARE(rm.getPositionForValue(1000000.0), 3);
125 QCOMPARE(rm.getPositionForValue(1000.0), 5); 125 QCOMPARE(rm.getPositionForValue(1000.0), 5);
126 QCOMPARE(rm.getPositionForValue(900.0), 5); 126 QCOMPARE(rm.getPositionForValue(900.0), 5);
127 QCOMPARE(rm.getPositionForValue(20000), 4); 127 QCOMPARE(rm.getPositionForValue(20000), 4);
128 QCOMPARE(rm.getPositionForValueUnclamped(1.0), 8); 128 QCOMPARE(rm.getPositionForValueUnclamped(1.0), 8);
129 QCOMPARE(rm.getPositionForValueUnclamped(1000000.0), 2); 129 QCOMPARE(rm.getPositionForValueUnclamped(1000000.0), 2);
130 QCOMPARE(rm.getPositionForValueUnclamped(1000.0), 5); 130 QCOMPARE(rm.getPositionForValueUnclamped(1000.0), 5);
131 } 131 }
132 132
133 void logUpBackward() 133 void logUpBackward()
134 { 134 {
135 LogRangeMapper rm(3, 7, 10, 100000, "x", false); 135 LogRangeMapper rm(3, 7, 10, 100000, "x", false);
136 QCOMPARE(rm.getUnit(), QString("x")); 136 QCOMPARE(rm.getUnit(), QString("x"));
137 QCOMPARE(rm.getValueForPosition(3), 10.0); 137 QCOMPARE(rm.getValueForPosition(3), 10.0);
138 QCOMPARE(rm.getValueForPosition(7), 100000.0); 138 QCOMPARE(rm.getValueForPosition(7), 100000.0);
139 QCOMPARE(rm.getValueForPosition(5), 1000.0); 139 QCOMPARE(rm.getValueForPosition(5), 1000.0);
140 QCOMPARE(rm.getValueForPosition(6), 10000.0); 140 QCOMPARE(rm.getValueForPosition(6), 10000.0);
141 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3)); 141 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3));
142 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7)); 142 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7));
143 QCOMPARE(rm.getValueForPositionUnclamped(2), 1.0); 143 QCOMPARE(rm.getValueForPositionUnclamped(2), 1.0);
144 QCOMPARE(rm.getValueForPositionUnclamped(8), 1000000.0); 144 QCOMPARE(rm.getValueForPositionUnclamped(8), 1000000.0);
145 QCOMPARE(rm.getValueForPositionUnclamped(5), 1000.0); 145 QCOMPARE(rm.getValueForPositionUnclamped(5), 1000.0);
146 } 146 }
147 147
148 void logDownBackward() 148 void logDownBackward()
149 { 149 {
150 LogRangeMapper rm(3, 7, 10, 100000, "x", true); 150 LogRangeMapper rm(3, 7, 10, 100000, "x", true);
151 QCOMPARE(rm.getUnit(), QString("x")); 151 QCOMPARE(rm.getUnit(), QString("x"));
152 QCOMPARE(rm.getValueForPosition(7), 10.0); 152 QCOMPARE(rm.getValueForPosition(7), 10.0);
153 QCOMPARE(rm.getValueForPosition(3), 100000.0); 153 QCOMPARE(rm.getValueForPosition(3), 100000.0);
154 QCOMPARE(rm.getValueForPosition(5), 1000.0); 154 QCOMPARE(rm.getValueForPosition(5), 1000.0);
155 QCOMPARE(rm.getValueForPosition(4), 10000.0); 155 QCOMPARE(rm.getValueForPosition(4), 10000.0);
156 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3)); 156 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3));
157 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7)); 157 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7));
158 QCOMPARE(rm.getValueForPositionUnclamped(8), 1.0); 158 QCOMPARE(rm.getValueForPositionUnclamped(8), 1.0);
159 QCOMPARE(rm.getValueForPositionUnclamped(2), 1000000.0); 159 QCOMPARE(rm.getValueForPositionUnclamped(2), 1000000.0);
160 QCOMPARE(rm.getValueForPositionUnclamped(5), 1000.0); 160 QCOMPARE(rm.getValueForPositionUnclamped(5), 1000.0);
161 } 161 }
162 162
163 void interpolatingForward() 163 void interpolatingForward()
164 { 164 {
165 InterpolatingRangeMapper::CoordMap mappings; 165 InterpolatingRangeMapper::CoordMap mappings;
166 mappings[1] = 10; 166 mappings[1] = 10;
167 mappings[3] = 30; 167 mappings[3] = 30;
168 mappings[5] = 70; 168 mappings[5] = 70;
169 InterpolatingRangeMapper rm(mappings, "x"); 169 InterpolatingRangeMapper rm(mappings, "x");
170 QCOMPARE(rm.getUnit(), QString("x")); 170 QCOMPARE(rm.getUnit(), QString("x"));
171 QCOMPARE(rm.getPositionForValue(1.0), 10); 171 QCOMPARE(rm.getPositionForValue(1.0), 10);
172 QCOMPARE(rm.getPositionForValue(0.0), 10); 172 QCOMPARE(rm.getPositionForValue(0.0), 10);
173 QCOMPARE(rm.getPositionForValue(5.0), 70); 173 QCOMPARE(rm.getPositionForValue(5.0), 70);
174 QCOMPARE(rm.getPositionForValue(6.0), 70); 174 QCOMPARE(rm.getPositionForValue(6.0), 70);
175 QCOMPARE(rm.getPositionForValue(3.0), 30); 175 QCOMPARE(rm.getPositionForValue(3.0), 30);
176 QCOMPARE(rm.getPositionForValue(2.5), 25); 176 QCOMPARE(rm.getPositionForValue(2.5), 25);
177 QCOMPARE(rm.getPositionForValue(4.5), 60); 177 QCOMPARE(rm.getPositionForValue(4.5), 60);
178 QCOMPARE(rm.getPositionForValueUnclamped(0.0), 0); 178 QCOMPARE(rm.getPositionForValueUnclamped(0.0), 0);
179 QCOMPARE(rm.getPositionForValueUnclamped(2.5), 25); 179 QCOMPARE(rm.getPositionForValueUnclamped(2.5), 25);
180 QCOMPARE(rm.getPositionForValueUnclamped(6.0), 90); 180 QCOMPARE(rm.getPositionForValueUnclamped(6.0), 90);
181 } 181 }
182 182
183 void interpolatingBackward() 183 void interpolatingBackward()
184 { 184 {
185 InterpolatingRangeMapper::CoordMap mappings; 185 InterpolatingRangeMapper::CoordMap mappings;
186 mappings[1] = 10; 186 mappings[1] = 10;
187 mappings[3] = 30; 187 mappings[3] = 30;
188 mappings[5] = 70; 188 mappings[5] = 70;
189 InterpolatingRangeMapper rm(mappings, "x"); 189 InterpolatingRangeMapper rm(mappings, "x");
190 QCOMPARE(rm.getUnit(), QString("x")); 190 QCOMPARE(rm.getUnit(), QString("x"));
191 QCOMPARE(rm.getValueForPosition(10), 1.0); 191 QCOMPARE(rm.getValueForPosition(10), 1.0);
192 QCOMPARE(rm.getValueForPosition(9), 1.0); 192 QCOMPARE(rm.getValueForPosition(9), 1.0);
193 QCOMPARE(rm.getValueForPosition(70), 5.0); 193 QCOMPARE(rm.getValueForPosition(70), 5.0);
194 QCOMPARE(rm.getValueForPosition(80), 5.0); 194 QCOMPARE(rm.getValueForPosition(80), 5.0);
195 QCOMPARE(rm.getValueForPosition(30), 3.0); 195 QCOMPARE(rm.getValueForPosition(30), 3.0);
196 QCOMPARE(rm.getValueForPosition(25), 2.5); 196 QCOMPARE(rm.getValueForPosition(25), 2.5);
197 QCOMPARE(rm.getValueForPosition(60), 4.5); 197 QCOMPARE(rm.getValueForPosition(60), 4.5);
198 } 198 }
199 199
200 void autoLinearForward() 200 void autoLinearForward()
201 { 201 {
202 AutoRangeMapper::CoordMap mappings; 202 AutoRangeMapper::CoordMap mappings;
203 mappings[0.5] = 1; 203 mappings[0.5] = 1;
204 mappings[4.0] = 8; 204 mappings[4.0] = 8;
205 AutoRangeMapper rm1(mappings, "x"); 205 AutoRangeMapper rm1(mappings, "x");
206 QCOMPARE(rm1.getUnit(), QString("x")); 206 QCOMPARE(rm1.getUnit(), QString("x"));
207 QCOMPARE(rm1.getType(), AutoRangeMapper::StraightLine); 207 QCOMPARE(rm1.getType(), AutoRangeMapper::StraightLine);
208 QCOMPARE(rm1.getPositionForValue(0.1), 1); 208 QCOMPARE(rm1.getPositionForValue(0.1), 1);
209 QCOMPARE(rm1.getPositionForValue(0.5), 1); 209 QCOMPARE(rm1.getPositionForValue(0.5), 1);
210 QCOMPARE(rm1.getPositionForValue(4.0), 8); 210 QCOMPARE(rm1.getPositionForValue(4.0), 8);
211 QCOMPARE(rm1.getPositionForValue(4.5), 8); 211 QCOMPARE(rm1.getPositionForValue(4.5), 8);
212 QCOMPARE(rm1.getPositionForValue(3.0), 6); 212 QCOMPARE(rm1.getPositionForValue(3.0), 6);
213 QCOMPARE(rm1.getPositionForValue(3.1), 6); 213 QCOMPARE(rm1.getPositionForValue(3.1), 6);
214 QCOMPARE(rm1.getPositionForValueUnclamped(0.1), 0); 214 QCOMPARE(rm1.getPositionForValueUnclamped(0.1), 0);
215 QCOMPARE(rm1.getPositionForValueUnclamped(3.1), 6); 215 QCOMPARE(rm1.getPositionForValueUnclamped(3.1), 6);
216 QCOMPARE(rm1.getPositionForValueUnclamped(4.5), 9); 216 QCOMPARE(rm1.getPositionForValueUnclamped(4.5), 9);
217 mappings[3.0] = 6; 217 mappings[3.0] = 6;
218 mappings[3.5] = 7; 218 mappings[3.5] = 7;
219 AutoRangeMapper rm2(mappings, "x"); 219 AutoRangeMapper rm2(mappings, "x");
220 QCOMPARE(rm2.getUnit(), QString("x")); 220 QCOMPARE(rm2.getUnit(), QString("x"));
221 QCOMPARE(rm2.getType(), AutoRangeMapper::StraightLine); 221 QCOMPARE(rm2.getType(), AutoRangeMapper::StraightLine);
222 QCOMPARE(rm2.getPositionForValue(0.5), 1); 222 QCOMPARE(rm2.getPositionForValue(0.5), 1);
223 QCOMPARE(rm2.getPositionForValue(4.0), 8); 223 QCOMPARE(rm2.getPositionForValue(4.0), 8);
224 QCOMPARE(rm2.getPositionForValue(3.0), 6); 224 QCOMPARE(rm2.getPositionForValue(3.0), 6);
225 QCOMPARE(rm2.getPositionForValue(3.1), 6); 225 QCOMPARE(rm2.getPositionForValue(3.1), 6);
226 } 226 }
227 227
228 void autoLogForward() 228 void autoLogForward()
229 { 229 {
230 AutoRangeMapper::CoordMap mappings; 230 AutoRangeMapper::CoordMap mappings;
231 mappings[10] = 3; 231 mappings[10] = 3;
232 mappings[1000] = 5; 232 mappings[1000] = 5;
233 mappings[100000] = 7; 233 mappings[100000] = 7;
234 AutoRangeMapper rm1(mappings, "x"); 234 AutoRangeMapper rm1(mappings, "x");
235 QCOMPARE(rm1.getUnit(), QString("x")); 235 QCOMPARE(rm1.getUnit(), QString("x"));
236 QCOMPARE(rm1.getType(), AutoRangeMapper::Logarithmic); 236 QCOMPARE(rm1.getType(), AutoRangeMapper::Logarithmic);
237 QCOMPARE(rm1.getPositionForValue(10.0), 3); 237 QCOMPARE(rm1.getPositionForValue(10.0), 3);
238 QCOMPARE(rm1.getPositionForValue(100000.0), 7); 238 QCOMPARE(rm1.getPositionForValue(100000.0), 7);
239 QCOMPARE(rm1.getPositionForValue(1.0), 3); 239 QCOMPARE(rm1.getPositionForValue(1.0), 3);
240 QCOMPARE(rm1.getPositionForValue(1000000.0), 7); 240 QCOMPARE(rm1.getPositionForValue(1000000.0), 7);
241 QCOMPARE(rm1.getPositionForValue(1000.0), 5); 241 QCOMPARE(rm1.getPositionForValue(1000.0), 5);
242 QCOMPARE(rm1.getPositionForValue(900.0), 5); 242 QCOMPARE(rm1.getPositionForValue(900.0), 5);
243 QCOMPARE(rm1.getPositionForValue(20000), 6); 243 QCOMPARE(rm1.getPositionForValue(20000), 6);
244 QCOMPARE(rm1.getPositionForValueUnclamped(1.0), 2); 244 QCOMPARE(rm1.getPositionForValueUnclamped(1.0), 2);
245 QCOMPARE(rm1.getPositionForValueUnclamped(900.0), 5); 245 QCOMPARE(rm1.getPositionForValueUnclamped(900.0), 5);
246 QCOMPARE(rm1.getPositionForValueUnclamped(1000000.0), 8); 246 QCOMPARE(rm1.getPositionForValueUnclamped(1000000.0), 8);
247 mappings[100] = 4; 247 mappings[100] = 4;
248 AutoRangeMapper rm2(mappings, "x"); 248 AutoRangeMapper rm2(mappings, "x");
249 QCOMPARE(rm2.getUnit(), QString("x")); 249 QCOMPARE(rm2.getUnit(), QString("x"));
250 QCOMPARE(rm2.getType(), AutoRangeMapper::Logarithmic); 250 QCOMPARE(rm2.getType(), AutoRangeMapper::Logarithmic);
251 QCOMPARE(rm2.getPositionForValue(10.0), 3); 251 QCOMPARE(rm2.getPositionForValue(10.0), 3);
252 QCOMPARE(rm2.getPositionForValue(100000.0), 7); 252 QCOMPARE(rm2.getPositionForValue(100000.0), 7);
253 QCOMPARE(rm2.getPositionForValue(1.0), 3); 253 QCOMPARE(rm2.getPositionForValue(1.0), 3);
254 QCOMPARE(rm2.getPositionForValue(1000000.0), 7); 254 QCOMPARE(rm2.getPositionForValue(1000000.0), 7);
255 QCOMPARE(rm2.getPositionForValue(1000.0), 5); 255 QCOMPARE(rm2.getPositionForValue(1000.0), 5);
256 QCOMPARE(rm2.getPositionForValue(900.0), 5); 256 QCOMPARE(rm2.getPositionForValue(900.0), 5);
257 QCOMPARE(rm2.getPositionForValue(20000), 6); 257 QCOMPARE(rm2.getPositionForValue(20000), 6);
258 } 258 }
259 259
260 void autoInterpolatingForward() 260 void autoInterpolatingForward()
261 { 261 {
262 AutoRangeMapper::CoordMap mappings; 262 AutoRangeMapper::CoordMap mappings;
263 mappings[1] = 10; 263 mappings[1] = 10;
264 mappings[3] = 30; 264 mappings[3] = 30;
265 mappings[5] = 70; 265 mappings[5] = 70;
266 AutoRangeMapper rm(mappings, "x"); 266 AutoRangeMapper rm(mappings, "x");
267 QCOMPARE(rm.getUnit(), QString("x")); 267 QCOMPARE(rm.getUnit(), QString("x"));
268 QCOMPARE(rm.getType(), AutoRangeMapper::Interpolating); 268 QCOMPARE(rm.getType(), AutoRangeMapper::Interpolating);
269 QCOMPARE(rm.getPositionForValue(1.0), 10); 269 QCOMPARE(rm.getPositionForValue(1.0), 10);
270 QCOMPARE(rm.getPositionForValue(0.0), 10); 270 QCOMPARE(rm.getPositionForValue(0.0), 10);
271 QCOMPARE(rm.getPositionForValue(5.0), 70); 271 QCOMPARE(rm.getPositionForValue(5.0), 70);
272 QCOMPARE(rm.getPositionForValue(6.0), 70); 272 QCOMPARE(rm.getPositionForValue(6.0), 70);
273 QCOMPARE(rm.getPositionForValue(3.0), 30); 273 QCOMPARE(rm.getPositionForValue(3.0), 30);
274 QCOMPARE(rm.getPositionForValue(2.5), 25); 274 QCOMPARE(rm.getPositionForValue(2.5), 25);
275 QCOMPARE(rm.getPositionForValue(4.5), 60); 275 QCOMPARE(rm.getPositionForValue(4.5), 60);
276 QCOMPARE(rm.getPositionForValueUnclamped(0.0), 0); 276 QCOMPARE(rm.getPositionForValueUnclamped(0.0), 0);
277 QCOMPARE(rm.getPositionForValueUnclamped(5.0), 70); 277 QCOMPARE(rm.getPositionForValueUnclamped(5.0), 70);
278 QCOMPARE(rm.getPositionForValueUnclamped(6.0), 90); 278 QCOMPARE(rm.getPositionForValueUnclamped(6.0), 90);
279 } 279 }
280 }; 280 };
281 281
282 #endif 282 #endif
283 283