Chris@879
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@879
|
2
|
Chris@879
|
3 /*
|
Chris@879
|
4 Sonic Visualiser
|
Chris@879
|
5 An audio file viewer and annotation editor.
|
Chris@879
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@879
|
7
|
Chris@879
|
8 This program is free software; you can redistribute it and/or
|
Chris@879
|
9 modify it under the terms of the GNU General Public License as
|
Chris@879
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@879
|
11 License, or (at your option) any later version. See the file
|
Chris@879
|
12 COPYING included with this distribution for more information.
|
Chris@879
|
13 */
|
Chris@879
|
14
|
Chris@879
|
15 #ifndef TEST_RANGE_MAPPER_H
|
Chris@879
|
16 #define TEST_RANGE_MAPPER_H
|
Chris@879
|
17
|
Chris@879
|
18 #include "../RangeMapper.h"
|
Chris@879
|
19
|
Chris@879
|
20 #include <QObject>
|
Chris@879
|
21 #include <QtTest>
|
Chris@879
|
22 #include <QDir>
|
Chris@879
|
23
|
Chris@879
|
24 #include <iostream>
|
Chris@879
|
25
|
Chris@879
|
26 using namespace std;
|
Chris@879
|
27
|
Chris@884
|
28 class TestRangeMapper : public QObject
|
Chris@879
|
29 {
|
Chris@879
|
30 Q_OBJECT
|
Chris@879
|
31
|
Chris@879
|
32 private slots:
|
Chris@879
|
33 void linearUpForward()
|
Chris@879
|
34 {
|
Chris@879
|
35 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", false);
|
Chris@879
|
36 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@879
|
37 QCOMPARE(rm.getPositionForValue(0.5), 1);
|
Chris@879
|
38 QCOMPARE(rm.getPositionForValue(4.0), 8);
|
Chris@879
|
39 QCOMPARE(rm.getPositionForValue(3.0), 6);
|
Chris@879
|
40 QCOMPARE(rm.getPositionForValue(3.1), 6);
|
Chris@879
|
41 QCOMPARE(rm.getPositionForValue(3.4), 7);
|
Chris@879
|
42 QCOMPARE(rm.getPositionForValue(0.2), 1);
|
Chris@879
|
43 QCOMPARE(rm.getPositionForValue(-12), 1);
|
Chris@879
|
44 QCOMPARE(rm.getPositionForValue(6.1), 8);
|
Chris@879
|
45 }
|
Chris@879
|
46
|
Chris@879
|
47 void linearDownForward()
|
Chris@879
|
48 {
|
Chris@879
|
49 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", true);
|
Chris@879
|
50 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@879
|
51 QCOMPARE(rm.getPositionForValue(0.5), 8);
|
Chris@879
|
52 QCOMPARE(rm.getPositionForValue(4.0), 1);
|
Chris@879
|
53 QCOMPARE(rm.getPositionForValue(3.0), 3);
|
Chris@879
|
54 QCOMPARE(rm.getPositionForValue(3.1), 3);
|
Chris@879
|
55 QCOMPARE(rm.getPositionForValue(3.4), 2);
|
Chris@879
|
56 QCOMPARE(rm.getPositionForValue(0.2), 8);
|
Chris@879
|
57 QCOMPARE(rm.getPositionForValue(-12), 8);
|
Chris@879
|
58 QCOMPARE(rm.getPositionForValue(6.1), 1);
|
Chris@879
|
59 }
|
Chris@879
|
60
|
Chris@879
|
61 void linearUpBackward()
|
Chris@879
|
62 {
|
Chris@879
|
63 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", false);
|
Chris@879
|
64 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@879
|
65 QCOMPARE(rm.getValueForPosition(1), 0.5);
|
Chris@879
|
66 QCOMPARE(rm.getValueForPosition(8), 4.0);
|
Chris@879
|
67 QCOMPARE(rm.getValueForPosition(6), 3.0);
|
Chris@879
|
68 QCOMPARE(rm.getValueForPosition(7), 3.5);
|
Chris@879
|
69 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(1));
|
Chris@879
|
70 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(8));
|
Chris@879
|
71 }
|
Chris@879
|
72
|
Chris@879
|
73 void linearDownBackward()
|
Chris@879
|
74 {
|
Chris@879
|
75 LinearRangeMapper rm(1, 8, 0.5, 4.0, "x", true);
|
Chris@879
|
76 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@879
|
77 QCOMPARE(rm.getValueForPosition(8), 0.5);
|
Chris@879
|
78 QCOMPARE(rm.getValueForPosition(1), 4.0);
|
Chris@879
|
79 QCOMPARE(rm.getValueForPosition(3), 3.0);
|
Chris@879
|
80 QCOMPARE(rm.getValueForPosition(2), 3.5);
|
Chris@879
|
81 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(1));
|
Chris@879
|
82 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(8));
|
Chris@879
|
83 }
|
Chris@879
|
84
|
Chris@879
|
85 void logUpForward()
|
Chris@879
|
86 {
|
Chris@879
|
87 LogRangeMapper rm(3, 7, 10, 100000, "x", false);
|
Chris@879
|
88 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@879
|
89 QCOMPARE(rm.getPositionForValue(10.0), 3);
|
Chris@879
|
90 QCOMPARE(rm.getPositionForValue(100000.0), 7);
|
Chris@879
|
91 QCOMPARE(rm.getPositionForValue(1.0), 3);
|
Chris@879
|
92 QCOMPARE(rm.getPositionForValue(1000000.0), 7);
|
Chris@879
|
93 QCOMPARE(rm.getPositionForValue(1000.0), 5);
|
Chris@879
|
94 QCOMPARE(rm.getPositionForValue(900.0), 5);
|
Chris@879
|
95 QCOMPARE(rm.getPositionForValue(20000), 6);
|
Chris@879
|
96 }
|
Chris@879
|
97
|
Chris@879
|
98 void logDownForward()
|
Chris@879
|
99 {
|
Chris@879
|
100 LogRangeMapper rm(3, 7, 10, 100000, "x", true);
|
Chris@879
|
101 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@879
|
102 QCOMPARE(rm.getPositionForValue(10.0), 7);
|
Chris@879
|
103 QCOMPARE(rm.getPositionForValue(100000.0), 3);
|
Chris@879
|
104 QCOMPARE(rm.getPositionForValue(1.0), 7);
|
Chris@879
|
105 QCOMPARE(rm.getPositionForValue(1000000.0), 3);
|
Chris@879
|
106 QCOMPARE(rm.getPositionForValue(1000.0), 5);
|
Chris@879
|
107 QCOMPARE(rm.getPositionForValue(900.0), 5);
|
Chris@879
|
108 QCOMPARE(rm.getPositionForValue(20000), 4);
|
Chris@879
|
109 }
|
Chris@879
|
110
|
Chris@879
|
111 void logUpBackward()
|
Chris@879
|
112 {
|
Chris@879
|
113 LogRangeMapper rm(3, 7, 10, 100000, "x", false);
|
Chris@879
|
114 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@879
|
115 QCOMPARE(rm.getValueForPosition(3), 10.0);
|
Chris@879
|
116 QCOMPARE(rm.getValueForPosition(7), 100000.0);
|
Chris@879
|
117 QCOMPARE(rm.getValueForPosition(5), 1000.0);
|
Chris@879
|
118 QCOMPARE(rm.getValueForPosition(6), 10000.0);
|
Chris@879
|
119 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3));
|
Chris@879
|
120 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7));
|
Chris@879
|
121 }
|
Chris@879
|
122
|
Chris@879
|
123 void logDownBackward()
|
Chris@879
|
124 {
|
Chris@879
|
125 LogRangeMapper rm(3, 7, 10, 100000, "x", true);
|
Chris@879
|
126 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@879
|
127 QCOMPARE(rm.getValueForPosition(7), 10.0);
|
Chris@879
|
128 QCOMPARE(rm.getValueForPosition(3), 100000.0);
|
Chris@879
|
129 QCOMPARE(rm.getValueForPosition(5), 1000.0);
|
Chris@879
|
130 QCOMPARE(rm.getValueForPosition(4), 10000.0);
|
Chris@879
|
131 QCOMPARE(rm.getValueForPosition(0), rm.getValueForPosition(3));
|
Chris@879
|
132 QCOMPARE(rm.getValueForPosition(9), rm.getValueForPosition(7));
|
Chris@879
|
133 }
|
Chris@880
|
134
|
Chris@880
|
135 void interpolatingForward()
|
Chris@880
|
136 {
|
Chris@880
|
137 InterpolatingRangeMapper::CoordMap mappings;
|
Chris@880
|
138 mappings[1] = 10;
|
Chris@880
|
139 mappings[3] = 30;
|
Chris@880
|
140 mappings[5] = 70;
|
Chris@880
|
141 InterpolatingRangeMapper rm(mappings, "x");
|
Chris@880
|
142 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@880
|
143 QCOMPARE(rm.getPositionForValue(1.0), 10);
|
Chris@880
|
144 QCOMPARE(rm.getPositionForValue(0.0), 10);
|
Chris@880
|
145 QCOMPARE(rm.getPositionForValue(5.0), 70);
|
Chris@880
|
146 QCOMPARE(rm.getPositionForValue(6.0), 70);
|
Chris@880
|
147 QCOMPARE(rm.getPositionForValue(3.0), 30);
|
Chris@880
|
148 QCOMPARE(rm.getPositionForValue(2.5), 25);
|
Chris@880
|
149 QCOMPARE(rm.getPositionForValue(4.5), 60);
|
Chris@880
|
150 }
|
Chris@880
|
151
|
Chris@880
|
152 void interpolatingBackward()
|
Chris@880
|
153 {
|
Chris@880
|
154 InterpolatingRangeMapper::CoordMap mappings;
|
Chris@880
|
155 mappings[1] = 10;
|
Chris@880
|
156 mappings[3] = 30;
|
Chris@880
|
157 mappings[5] = 70;
|
Chris@880
|
158 InterpolatingRangeMapper rm(mappings, "x");
|
Chris@880
|
159 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@880
|
160 QCOMPARE(rm.getValueForPosition(10), 1.0);
|
Chris@880
|
161 QCOMPARE(rm.getValueForPosition(9), 1.0);
|
Chris@880
|
162 QCOMPARE(rm.getValueForPosition(70), 5.0);
|
Chris@880
|
163 QCOMPARE(rm.getValueForPosition(80), 5.0);
|
Chris@880
|
164 QCOMPARE(rm.getValueForPosition(30), 3.0);
|
Chris@880
|
165 QCOMPARE(rm.getValueForPosition(25), 2.5);
|
Chris@880
|
166 QCOMPARE(rm.getValueForPosition(60), 4.5);
|
Chris@880
|
167 }
|
Chris@880
|
168
|
Chris@880
|
169 void autoLinearForward()
|
Chris@880
|
170 {
|
Chris@880
|
171 AutoRangeMapper::CoordMap mappings;
|
Chris@880
|
172 mappings[0.5] = 1;
|
Chris@880
|
173 mappings[4.0] = 8;
|
Chris@880
|
174 AutoRangeMapper rm1(mappings, "x");
|
Chris@880
|
175 QCOMPARE(rm1.getUnit(), QString("x"));
|
Chris@880
|
176 QCOMPARE(rm1.getType(), AutoRangeMapper::StraightLine);
|
Chris@880
|
177 QCOMPARE(rm1.getPositionForValue(0.5), 1);
|
Chris@880
|
178 QCOMPARE(rm1.getPositionForValue(4.0), 8);
|
Chris@880
|
179 QCOMPARE(rm1.getPositionForValue(3.0), 6);
|
Chris@880
|
180 QCOMPARE(rm1.getPositionForValue(3.1), 6);
|
Chris@880
|
181 mappings[3.0] = 6;
|
Chris@880
|
182 mappings[3.5] = 7;
|
Chris@880
|
183 AutoRangeMapper rm2(mappings, "x");
|
Chris@880
|
184 QCOMPARE(rm2.getUnit(), QString("x"));
|
Chris@880
|
185 QCOMPARE(rm2.getType(), AutoRangeMapper::StraightLine);
|
Chris@880
|
186 QCOMPARE(rm2.getPositionForValue(0.5), 1);
|
Chris@880
|
187 QCOMPARE(rm2.getPositionForValue(4.0), 8);
|
Chris@880
|
188 QCOMPARE(rm2.getPositionForValue(3.0), 6);
|
Chris@880
|
189 QCOMPARE(rm2.getPositionForValue(3.1), 6);
|
Chris@880
|
190 }
|
Chris@880
|
191
|
Chris@880
|
192 void autoLogForward()
|
Chris@880
|
193 {
|
Chris@880
|
194 AutoRangeMapper::CoordMap mappings;
|
Chris@880
|
195 mappings[10] = 3;
|
Chris@880
|
196 mappings[1000] = 5;
|
Chris@880
|
197 mappings[100000] = 7;
|
Chris@880
|
198 AutoRangeMapper rm1(mappings, "x");
|
Chris@880
|
199 QCOMPARE(rm1.getUnit(), QString("x"));
|
Chris@880
|
200 QCOMPARE(rm1.getType(), AutoRangeMapper::Logarithmic);
|
Chris@880
|
201 QCOMPARE(rm1.getPositionForValue(10.0), 3);
|
Chris@880
|
202 QCOMPARE(rm1.getPositionForValue(100000.0), 7);
|
Chris@880
|
203 QCOMPARE(rm1.getPositionForValue(1.0), 3);
|
Chris@880
|
204 QCOMPARE(rm1.getPositionForValue(1000000.0), 7);
|
Chris@880
|
205 QCOMPARE(rm1.getPositionForValue(1000.0), 5);
|
Chris@880
|
206 QCOMPARE(rm1.getPositionForValue(900.0), 5);
|
Chris@880
|
207 QCOMPARE(rm1.getPositionForValue(20000), 6);
|
Chris@880
|
208 mappings[100] = 4;
|
Chris@880
|
209 AutoRangeMapper rm2(mappings, "x");
|
Chris@880
|
210 QCOMPARE(rm2.getUnit(), QString("x"));
|
Chris@880
|
211 QCOMPARE(rm2.getType(), AutoRangeMapper::Logarithmic);
|
Chris@880
|
212 QCOMPARE(rm2.getPositionForValue(10.0), 3);
|
Chris@880
|
213 QCOMPARE(rm2.getPositionForValue(100000.0), 7);
|
Chris@880
|
214 QCOMPARE(rm2.getPositionForValue(1.0), 3);
|
Chris@880
|
215 QCOMPARE(rm2.getPositionForValue(1000000.0), 7);
|
Chris@880
|
216 QCOMPARE(rm2.getPositionForValue(1000.0), 5);
|
Chris@880
|
217 QCOMPARE(rm2.getPositionForValue(900.0), 5);
|
Chris@880
|
218 QCOMPARE(rm2.getPositionForValue(20000), 6);
|
Chris@880
|
219 }
|
Chris@880
|
220
|
Chris@880
|
221 void autoInterpolatingForward()
|
Chris@880
|
222 {
|
Chris@880
|
223 AutoRangeMapper::CoordMap mappings;
|
Chris@880
|
224 mappings[1] = 10;
|
Chris@880
|
225 mappings[3] = 30;
|
Chris@880
|
226 mappings[5] = 70;
|
Chris@880
|
227 AutoRangeMapper rm(mappings, "x");
|
Chris@880
|
228 QCOMPARE(rm.getUnit(), QString("x"));
|
Chris@880
|
229 QCOMPARE(rm.getType(), AutoRangeMapper::Interpolating);
|
Chris@880
|
230 QCOMPARE(rm.getPositionForValue(1.0), 10);
|
Chris@880
|
231 QCOMPARE(rm.getPositionForValue(0.0), 10);
|
Chris@880
|
232 QCOMPARE(rm.getPositionForValue(5.0), 70);
|
Chris@880
|
233 QCOMPARE(rm.getPositionForValue(6.0), 70);
|
Chris@880
|
234 QCOMPARE(rm.getPositionForValue(3.0), 30);
|
Chris@880
|
235 QCOMPARE(rm.getPositionForValue(2.5), 25);
|
Chris@880
|
236 QCOMPARE(rm.getPositionForValue(4.5), 60);
|
Chris@880
|
237 }
|
Chris@879
|
238 };
|
Chris@879
|
239
|
Chris@879
|
240 #endif
|
Chris@879
|
241
|
Chris@879
|
242
|