comparison base/test/TestColumnOp.h @ 1266:dd190086db73 3.0-integration

Tests and fixes for distribute(). Although this version of interpolated distribution passes these tests, it isn't right visually -- the expected values in the tests are offset. To be continued.
author Chris Cannam
date Thu, 17 Nov 2016 14:33:20 +0000
parents e2e66bfd4a88
children 1d8418cca63a
comparison
equal deleted inserted replaced
1265:e2e66bfd4a88 1266:dd190086db73
29 { 29 {
30 Q_OBJECT 30 Q_OBJECT
31 31
32 typedef ColumnOp C; 32 typedef ColumnOp C;
33 typedef ColumnOp::Column Column; 33 typedef ColumnOp::Column Column;
34 34 typedef vector<double> BinMapping;
35
36 template <typename T>
37 void report(vector<T> v) {
38 cerr << "Vector is: [ ";
39 for (int i = 0; i < int(v.size()); ++i) {
40 if (i > 0) cerr << ", ";
41 cerr << v[i];
42 }
43 cerr << " ]\n";
44 }
45
35 private slots: 46 private slots:
36 void applyGain() { 47 void applyGain() {
37 QCOMPARE(C::applyGain({}, 1.0), Column()); 48 QCOMPARE(C::applyGain({}, 1.0), Column());
38 Column c { 1, 2, 3, -4, 5, 6 }; 49 Column c { 1, 2, 3, -4, 5, 6 };
39 Column actual(C::applyGain(c, 1.5)); 50 Column actual(C::applyGain(c, 1.5));
127 void normalize_none() { 138 void normalize_none() {
128 Column c { 1, 2, 3, 4 }; 139 Column c { 1, 2, 3, 4 };
129 QCOMPARE(C::normalize(c, ColumnNormalization::None), c); 140 QCOMPARE(C::normalize(c, ColumnNormalization::None), c);
130 } 141 }
131 142
143 void normalize_none_mixedSign() {
144 Column c { 1, 2, -3, -4 };
145 QCOMPARE(C::normalize(c, ColumnNormalization::None), c);
146 }
147
132 void normalize_sum1() { 148 void normalize_sum1() {
133 Column c { 1, 2, 4, 3 }; 149 Column c { 1, 2, 4, 3 };
134 QCOMPARE(C::normalize(c, ColumnNormalization::Sum1), 150 QCOMPARE(C::normalize(c, ColumnNormalization::Sum1),
135 Column({ 0.1, 0.2, 0.4, 0.3 })); 151 Column({ 0.1, 0.2, 0.4, 0.3 }));
136 } 152 }
137 153
154 void normalize_sum1_mixedSign() {
155 Column c { 1, 2, -4, -3 };
156 QCOMPARE(C::normalize(c, ColumnNormalization::Sum1),
157 Column({ 0.1, 0.2, -0.4, -0.3 }));
158 }
159
138 void normalize_max1() { 160 void normalize_max1() {
139 Column c { 4, 3, 2, 1 }; 161 Column c { 4, 3, 2, 1 };
140 QCOMPARE(C::normalize(c, ColumnNormalization::Max1), 162 QCOMPARE(C::normalize(c, ColumnNormalization::Max1),
141 Column({ 1.0, 0.75, 0.5, 0.25 })); 163 Column({ 1.0, 0.75, 0.5, 0.25 }));
164 }
165
166 void normalize_max1_mixedSign() {
167 Column c { -4, -3, 2, 1 };
168 QCOMPARE(C::normalize(c, ColumnNormalization::Max1),
169 Column({ -1.0, -0.75, 0.5, 0.25 }));
142 } 170 }
143 171
144 void normalize_hybrid() { 172 void normalize_hybrid() {
145 // with max == 99, log10(max+1) == 2 so scale factor will be 2/99 173 // with max == 99, log10(max+1) == 2 so scale factor will be 2/99
146 Column c { 22, 44, 99, 66 }; 174 Column c { 22, 44, 99, 66 };
147 QCOMPARE(C::normalize(c, ColumnNormalization::Hybrid), 175 QCOMPARE(C::normalize(c, ColumnNormalization::Hybrid),
148 Column({ 44.0/99.0, 88.0/99.0, 2.0, 132.0/99.0 })); 176 Column({ 44.0/99.0, 88.0/99.0, 2.0, 132.0/99.0 }));
149 } 177 }
150 178
179 void normalize_hybrid_mixedSign() {
180 // with max == 99, log10(max+1) == 2 so scale factor will be 2/99
181 Column c { 22, 44, -99, -66 };
182 QCOMPARE(C::normalize(c, ColumnNormalization::Hybrid),
183 Column({ 44.0/99.0, 88.0/99.0, -2.0, -132.0/99.0 }));
184 }
185
186 void distribute_simple() {
187 Column in { 1, 2, 3 };
188 BinMapping binfory { 0.0, 0.5, 1.0, 1.5, 2.0, 2.5 };
189 Column expected { 1, 1, 2, 2, 3, 3 };
190 Column actual(C::distribute(in, 6, binfory, 0, false));
191 report(actual);
192 QCOMPARE(actual, expected);
193 }
194
195 void distribute_simple_interpolated() {
196 Column in { 1, 2, 3 };
197 BinMapping binfory { 0.0, 0.5, 1.0, 1.5, 2.0, 2.5 };
198 Column expected { 1, 1.5, 2, 2.5, 3, 3 };
199 Column actual(C::distribute(in, 6, binfory, 0, true));
200 report(actual);
201 QCOMPARE(actual, expected);
202 }
203
204 void distribute_nonlinear() {
205 Column in { 1, 2, 3 };
206 BinMapping binfory { 0.0, 0.2, 0.5, 1.0, 2.0, 2.5 };
207 Column expected { 1, 1, 1, 2, 3, 3 };
208 Column actual(C::distribute(in, 6, binfory, 0, false));
209 report(actual);
210 QCOMPARE(actual, expected);
211 }
212
213 void distribute_nonlinear_interpolated() {
214 Column in { 1, 2, 3 };
215 BinMapping binfory { 0.0, 0.2, 0.5, 1.0, 2.0, 2.5 };
216 Column expected { 1, 1.2, 1.5, 2, 3, 3 };
217 Column actual(C::distribute(in, 6, binfory, 0, true));
218 report(actual);
219 QCOMPARE(actual, expected);
220 }
221
222 void distribute_shrinking() {
223 Column in { 4, 1, 2, 3, 5, 6 };
224 BinMapping binfory { 0.0, 2.0, 4.0 };
225 Column expected { 4, 3, 6 };
226 Column actual(C::distribute(in, 3, binfory, 0, false));
227 report(actual);
228 QCOMPARE(actual, expected);
229 }
230
231 void distribute_shrinking_interpolated() {
232 // should be same as distribute_shrinking, we don't
233 // interpolate when resizing down
234 Column in { 4, 1, 2, 3, 5, 6 };
235 BinMapping binfory { 0.0, 2.0, 4.0 };
236 Column expected { 4, 3, 6 };
237 Column actual(C::distribute(in, 3, binfory, 0, true));
238 report(actual);
239 QCOMPARE(actual, expected);
240 }
151 241
152 242
153 }; 243 };
154 244
155 #endif 245 #endif