Mercurial > hg > svcore
comparison base/test/TestScaleTickIntervals.h @ 1411:1f0d071e7ce6 scale-ticks
More tests & fixes
author | Chris Cannam |
---|---|
date | Wed, 03 May 2017 18:26:26 +0100 |
parents | c4af57d59434 |
children | b7a9edee85e0 |
comparison
equal
deleted
inserted
replaced
1410:c4af57d59434 | 1411:1f0d071e7ce6 |
---|---|
32 void printDiff(vector<ScaleTickIntervals::Tick> ticks, | 32 void printDiff(vector<ScaleTickIntervals::Tick> ticks, |
33 vector<ScaleTickIntervals::Tick> expected) { | 33 vector<ScaleTickIntervals::Tick> expected) { |
34 | 34 |
35 cerr << "Have " << ticks.size() << " ticks, expected " | 35 cerr << "Have " << ticks.size() << " ticks, expected " |
36 << expected.size() << endl; | 36 << expected.size() << endl; |
37 for (int i = 0; i < int(expected.size()); ++i) { | 37 for (int i = 0; i < int(ticks.size()); ++i) { |
38 if (i < int(ticks.size())) { | 38 cerr << i << ": have " << ticks[i].value << " \"" |
39 cerr << i << ": have " << ticks[i].value << " \"" | 39 << ticks[i].label << "\", expected "; |
40 << ticks[i].label << "\", expected " | 40 if (i < int(expected.size())) { |
41 << expected[i].value << " \"" << expected[i].label | 41 cerr << expected[i].value << " \"" << expected[i].label |
42 << "\"" << endl; | 42 << "\"" << endl; |
43 } else { | |
44 cerr << "(n/a)" << endl; | |
43 } | 45 } |
44 } | 46 } |
45 } | 47 } |
46 | 48 |
47 void compareTicks(vector<ScaleTickIntervals::Tick> ticks, | 49 void compareTicks(vector<ScaleTickIntervals::Tick> ticks, |
113 { 10, "10.0" } | 115 { 10, "10.0" } |
114 }; | 116 }; |
115 compareTicks(ticks.ticks, expected); | 117 compareTicks(ticks.ticks, expected); |
116 } | 118 } |
117 | 119 |
120 void linear_10_0_5() | |
121 { | |
122 auto ticks = ScaleTickIntervals::linear({ 10, 0, 5 }); | |
123 vector<ScaleTickIntervals::Tick> expected { | |
124 { 0, "0.0" }, | |
125 { 2, "2.0" }, | |
126 { 4, "4.0" }, | |
127 { 6, "6.0" }, | |
128 { 8, "8.0" }, | |
129 { 10, "10.0" } | |
130 }; | |
131 compareTicks(ticks.ticks, expected); | |
132 } | |
133 | |
134 void linear_m10_0_5() | |
135 { | |
136 auto ticks = ScaleTickIntervals::linear({ -10, 0, 5 }); | |
137 vector<ScaleTickIntervals::Tick> expected { | |
138 { -10, "-10.0" }, | |
139 { -8, "-8.0" }, | |
140 { -6, "-6.0" }, | |
141 { -4, "-4.0" }, | |
142 { -2, "-2.0" }, | |
143 { 0, "0.0" } | |
144 }; | |
145 compareTicks(ticks.ticks, expected); | |
146 } | |
147 | |
148 void linear_0_m10_5() | |
149 { | |
150 auto ticks = ScaleTickIntervals::linear({ 0, -10, 5 }); | |
151 vector<ScaleTickIntervals::Tick> expected { | |
152 { -10, "-10.0" }, | |
153 { -8, "-8.0" }, | |
154 { -6, "-6.0" }, | |
155 { -4, "-4.0" }, | |
156 { -2, "-2.0" }, | |
157 { 0, "0.0" } | |
158 }; | |
159 compareTicks(ticks.ticks, expected); | |
160 } | |
161 | |
118 void linear_0_0p1_5() | 162 void linear_0_0p1_5() |
119 { | 163 { |
120 auto ticks = ScaleTickIntervals::linear({ 0, 0.1, 5 }); | 164 auto ticks = ScaleTickIntervals::linear({ 0, 0.1, 5 }); |
121 vector<ScaleTickIntervals::Tick> expected { | 165 vector<ScaleTickIntervals::Tick> expected { |
122 { 0.00, "0.00" }, | 166 { 0.00, "0.00" }, |
229 { 0.8, "0.8" }, | 273 { 0.8, "0.8" }, |
230 { 1.0, "1.0" } | 274 { 1.0, "1.0" } |
231 }; | 275 }; |
232 compareTicks(ticks.ticks, expected); | 276 compareTicks(ticks.ticks, expected); |
233 } | 277 } |
278 | |
279 void linear_221p23_623p7_57p4() | |
280 { | |
281 auto ticks = ScaleTickIntervals::linear({ 221.23, 623.7, 4 }); | |
282 // only 4 ticks, not 5, because none of the rounded tick | |
283 // values lies on an end value | |
284 vector<ScaleTickIntervals::Tick> expected { | |
285 { 230, "230" }, | |
286 { 330, "330" }, | |
287 { 430, "430" }, | |
288 { 530, "530" }, | |
289 }; | |
290 compareTicks(ticks.ticks, expected); | |
291 } | |
292 | |
293 void linear_1_1_10() | |
294 { | |
295 auto ticks = ScaleTickIntervals::linear({ 1, 1, 10 }); | |
296 vector<ScaleTickIntervals::Tick> expected { | |
297 { 1.0, "1.0" } | |
298 }; | |
299 compareTicks(ticks.ticks, expected); | |
300 } | |
301 | |
302 void linear_0_0_10() | |
303 { | |
304 auto ticks = ScaleTickIntervals::linear({ 0, 0, 10 }); | |
305 vector<ScaleTickIntervals::Tick> expected { | |
306 { 0.0, "0.0" } | |
307 }; | |
308 compareTicks(ticks.ticks, expected); | |
309 } | |
310 | |
311 void linear_0_1_1() | |
312 { | |
313 auto ticks = ScaleTickIntervals::linear({ 0, 1, 1 }); | |
314 vector<ScaleTickIntervals::Tick> expected { | |
315 { 0.0, "0.0" }, | |
316 { 1.0, "1.0" } | |
317 }; | |
318 compareTicks(ticks.ticks, expected); | |
319 } | |
320 | |
321 void linear_0_1_0() | |
322 { | |
323 auto ticks = ScaleTickIntervals::linear({ 0, 1, 0 }); | |
324 vector<ScaleTickIntervals::Tick> expected { | |
325 }; | |
326 compareTicks(ticks.ticks, expected); | |
327 } | |
328 | |
329 void linear_0_1_m1() | |
330 { | |
331 auto ticks = ScaleTickIntervals::linear({ 0, 1, -1 }); | |
332 vector<ScaleTickIntervals::Tick> expected { | |
333 }; | |
334 compareTicks(ticks.ticks, expected); | |
335 } | |
234 }; | 336 }; |
235 | 337 |
236 #endif | 338 #endif |
237 | 339 |
238 | 340 |