comparison base/test/TestColumnOp.h @ 1380:bd1eb56df8d5

Fix some initialisers that are causing complaint from msvc (from double-to-float truncation)
author Chris Cannam
date Tue, 21 Feb 2017 21:07:54 +0000
parents 7cff8367d9b1
children 9ef1cc26024c
comparison
equal deleted inserted replaced
1374:8db84bd61eaa 1380:bd1eb56df8d5
53 private slots: 53 private slots:
54 void applyGain() { 54 void applyGain() {
55 QCOMPARE(C::applyGain({}, 1.0), Column()); 55 QCOMPARE(C::applyGain({}, 1.0), Column());
56 Column c { 1, 2, 3, -4, 5, 6 }; 56 Column c { 1, 2, 3, -4, 5, 6 };
57 Column actual(C::applyGain(c, 1.5)); 57 Column actual(C::applyGain(c, 1.5));
58 Column expected { 1.5, 3, 4.5, -6, 7.5, 9 }; 58 Column expected { 1.5f, 3, 4.5f, -6, 7.5f, 9 };
59 QCOMPARE(actual, expected); 59 QCOMPARE(actual, expected);
60 actual = C::applyGain(c, 1.0); 60 actual = C::applyGain(c, 1.0);
61 QCOMPARE(actual, c); 61 QCOMPARE(actual, c);
62 actual = C::applyGain(c, 0.0); 62 actual = C::applyGain(c, 0.0);
63 expected = { 0, 0, 0, 0, 0, 0 }; 63 expected = { 0, 0, 0, 0, 0, 0 };
66 66
67 void fftScale() { 67 void fftScale() {
68 QCOMPARE(C::fftScale({}, 2.0), Column()); 68 QCOMPARE(C::fftScale({}, 2.0), Column());
69 Column c { 1, 2, 3, -4, 5 }; 69 Column c { 1, 2, 3, -4, 5 };
70 Column actual(C::fftScale(c, 8)); 70 Column actual(C::fftScale(c, 8));
71 Column expected { 0.25, 0.5, 0.75, -1, 1.25 }; 71 Column expected { 0.25f, 0.5f, 0.75f, -1, 1.25f };
72 QCOMPARE(actual, expected); 72 QCOMPARE(actual, expected);
73 } 73 }
74 74
75 void isPeak_null() { 75 void isPeak_null() {
76 QVERIFY(!C::isPeak({}, 0)); 76 QVERIFY(!C::isPeak({}, 0));
77 QVERIFY(!C::isPeak({}, 1)); 77 QVERIFY(!C::isPeak({}, 1));
78 QVERIFY(!C::isPeak({}, -1)); 78 QVERIFY(!C::isPeak({}, -1));
79 } 79 }
80 80
81 void isPeak_obvious() { 81 void isPeak_obvious() {
82 Column c { 0.4, 0.5, 0.3 }; 82 Column c { 0.4f, 0.5f, 0.3f };
83 QVERIFY(!C::isPeak(c, 0)); 83 QVERIFY(!C::isPeak(c, 0));
84 QVERIFY(C::isPeak(c, 1)); 84 QVERIFY(C::isPeak(c, 1));
85 QVERIFY(!C::isPeak(c, 2)); 85 QVERIFY(!C::isPeak(c, 2));
86 } 86 }
87 87
88 void isPeak_edges() { 88 void isPeak_edges() {
89 Column c { 0.5, 0.4, 0.3 }; 89 Column c { 0.5f, 0.4f, 0.3f };
90 QVERIFY(C::isPeak(c, 0)); 90 QVERIFY(C::isPeak(c, 0));
91 QVERIFY(!C::isPeak(c, 1)); 91 QVERIFY(!C::isPeak(c, 1));
92 QVERIFY(!C::isPeak(c, 2)); 92 QVERIFY(!C::isPeak(c, 2));
93 QVERIFY(!C::isPeak(c, 3)); 93 QVERIFY(!C::isPeak(c, 3));
94 QVERIFY(!C::isPeak(c, -1)); 94 QVERIFY(!C::isPeak(c, -1));
95 c = { 1.4, 1.5 }; 95 c = { 1.4f, 1.5f };
96 QVERIFY(!C::isPeak(c, 0)); 96 QVERIFY(!C::isPeak(c, 0));
97 QVERIFY(C::isPeak(c, 1)); 97 QVERIFY(C::isPeak(c, 1));
98 } 98 }
99 99
100 void isPeak_flat() { 100 void isPeak_flat() {
101 Column c { 0.0, 0.0, 0.0 }; 101 Column c { 0.0f, 0.0f, 0.0f };
102 QVERIFY(C::isPeak(c, 0)); 102 QVERIFY(C::isPeak(c, 0));
103 QVERIFY(!C::isPeak(c, 1)); 103 QVERIFY(!C::isPeak(c, 1));
104 QVERIFY(!C::isPeak(c, 2)); 104 QVERIFY(!C::isPeak(c, 2));
105 } 105 }
106 106
107 void isPeak_mixedSign() { 107 void isPeak_mixedSign() {
108 Column c { 0.4, -0.5, -0.3, -0.6, 0.1, -0.3 }; 108 Column c { 0.4f, -0.5f, -0.3f, -0.6f, 0.1f, -0.3f };
109 QVERIFY(C::isPeak(c, 0)); 109 QVERIFY(C::isPeak(c, 0));
110 QVERIFY(!C::isPeak(c, 1)); 110 QVERIFY(!C::isPeak(c, 1));
111 QVERIFY(C::isPeak(c, 2)); 111 QVERIFY(C::isPeak(c, 2));
112 QVERIFY(!C::isPeak(c, 3)); 112 QVERIFY(!C::isPeak(c, 3));
113 QVERIFY(C::isPeak(c, 4)); 113 QVERIFY(C::isPeak(c, 4));
114 QVERIFY(!C::isPeak(c, 5)); 114 QVERIFY(!C::isPeak(c, 5));
115 } 115 }
116 116
117 void isPeak_duplicate() { 117 void isPeak_duplicate() {
118 Column c({ 0.5, 0.5, 0.4, 0.4 }); 118 Column c({ 0.5f, 0.5f, 0.4f, 0.4f });
119 QVERIFY(C::isPeak(c, 0)); 119 QVERIFY(C::isPeak(c, 0));
120 QVERIFY(!C::isPeak(c, 1)); 120 QVERIFY(!C::isPeak(c, 1));
121 QVERIFY(!C::isPeak(c, 2)); 121 QVERIFY(!C::isPeak(c, 2));
122 QVERIFY(!C::isPeak(c, 3)); 122 QVERIFY(!C::isPeak(c, 3));
123 c = { 0.4, 0.4, 0.5, 0.5 }; 123 c = { 0.4f, 0.4f, 0.5f, 0.5f };
124 QVERIFY(C::isPeak(c, 0)); // counterintuitive but necessary 124 QVERIFY(C::isPeak(c, 0)); // counterintuitive but necessary
125 QVERIFY(!C::isPeak(c, 1)); 125 QVERIFY(!C::isPeak(c, 1));
126 QVERIFY(C::isPeak(c, 2)); 126 QVERIFY(C::isPeak(c, 2));
127 QVERIFY(!C::isPeak(c, 3)); 127 QVERIFY(!C::isPeak(c, 3));
128 } 128 }
129 129
130 void peakPick() { 130 void peakPick() {
131 QCOMPARE(C::peakPick({}), Column()); 131 QCOMPARE(C::peakPick({}), Column());
132 Column c({ 0.5, 0.5, 0.4, 0.4 }); 132 Column c({ 0.5f, 0.5f, 0.4f, 0.4f });
133 QCOMPARE(C::peakPick(c), Column({ 0.5, 0.0, 0.0, 0.0 })); 133 QCOMPARE(C::peakPick(c), Column({ 0.5f, 0.0f, 0.0f, 0.0f }));
134 c = Column({ 0.4, -0.5, -0.3, -0.6, 0.1, -0.3 }); 134 c = Column({ 0.4f, -0.5f, -0.3f, -0.6f, 0.1f, -0.3f });
135 QCOMPARE(C::peakPick(c), Column({ 0.4, 0.0, -0.3, 0.0, 0.1, 0.0 })); 135 QCOMPARE(C::peakPick(c), Column({ 0.4f, 0.0f, -0.3f, 0.0f, 0.1f, 0.0f }));
136 } 136 }
137 137
138 void normalize_null() { 138 void normalize_null() {
139 QCOMPARE(C::normalize({}, ColumnNormalization::None), Column()); 139 QCOMPARE(C::normalize({}, ColumnNormalization::None), Column());
140 QCOMPARE(C::normalize({}, ColumnNormalization::Sum1), Column()); 140 QCOMPARE(C::normalize({}, ColumnNormalization::Sum1), Column());
153 } 153 }
154 154
155 void normalize_sum1() { 155 void normalize_sum1() {
156 Column c { 1, 2, 4, 3 }; 156 Column c { 1, 2, 4, 3 };
157 QCOMPARE(C::normalize(c, ColumnNormalization::Sum1), 157 QCOMPARE(C::normalize(c, ColumnNormalization::Sum1),
158 Column({ 0.1, 0.2, 0.4, 0.3 })); 158 Column({ 0.1f, 0.2f, 0.4f, 0.3f }));
159 } 159 }
160 160
161 void normalize_sum1_mixedSign() { 161 void normalize_sum1_mixedSign() {
162 Column c { 1, 2, -4, -3 }; 162 Column c { 1, 2, -4, -3 };
163 QCOMPARE(C::normalize(c, ColumnNormalization::Sum1), 163 QCOMPARE(C::normalize(c, ColumnNormalization::Sum1),
164 Column({ 0.1, 0.2, -0.4, -0.3 })); 164 Column({ 0.1f, 0.2f, -0.4f, -0.3f }));
165 } 165 }
166 166
167 void normalize_max1() { 167 void normalize_max1() {
168 Column c { 4, 3, 2, 1 }; 168 Column c { 4, 3, 2, 1 };
169 QCOMPARE(C::normalize(c, ColumnNormalization::Max1), 169 QCOMPARE(C::normalize(c, ColumnNormalization::Max1),
170 Column({ 1.0, 0.75, 0.5, 0.25 })); 170 Column({ 1.0f, 0.75f, 0.5f, 0.25f }));
171 } 171 }
172 172
173 void normalize_max1_mixedSign() { 173 void normalize_max1_mixedSign() {
174 Column c { -4, -3, 2, 1 }; 174 Column c { -4, -3, 2, 1 };
175 QCOMPARE(C::normalize(c, ColumnNormalization::Max1), 175 QCOMPARE(C::normalize(c, ColumnNormalization::Max1),
176 Column({ -1.0, -0.75, 0.5, 0.25 })); 176 Column({ -1.0f, -0.75f, 0.5f, 0.25f }));
177 } 177 }
178 178
179 void normalize_hybrid() { 179 void normalize_hybrid() {
180 // with max == 99, log10(max+1) == 2 so scale factor will be 2/99 180 // with max == 99, log10(max+1) == 2 so scale factor will be 2/99
181 Column c { 22, 44, 99, 66 }; 181 Column c { 22, 44, 99, 66 };
182 QCOMPARE(C::normalize(c, ColumnNormalization::Hybrid), 182 QCOMPARE(C::normalize(c, ColumnNormalization::Hybrid),
183 Column({ 44.0/99.0, 88.0/99.0, 2.0, 132.0/99.0 })); 183 Column({ 44.0f/99.0f, 88.0f/99.0f, 2.0f, 132.0f/99.0f }));
184 } 184 }
185 185
186 void normalize_hybrid_mixedSign() { 186 void normalize_hybrid_mixedSign() {
187 // with max == 99, log10(max+1) == 2 so scale factor will be 2/99 187 // with max == 99, log10(max+1) == 2 so scale factor will be 2/99
188 Column c { 22, 44, -99, -66 }; 188 Column c { 22, 44, -99, -66 };
189 QCOMPARE(C::normalize(c, ColumnNormalization::Hybrid), 189 QCOMPARE(C::normalize(c, ColumnNormalization::Hybrid),
190 Column({ 44.0/99.0, 88.0/99.0, -2.0, -132.0/99.0 })); 190 Column({ 44.0f/99.0f, 88.0f/99.0f, -2.0f, -132.0f/99.0f }));
191 } 191 }
192 192
193 void distribute_simple() { 193 void distribute_simple() {
194 Column in { 1, 2, 3 }; 194 Column in { 1, 2, 3 };
195 BinMapping binfory { 0.0, 0.5, 1.0, 1.5, 2.0, 2.5 }; 195 BinMapping binfory { 0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f };
196 Column expected { 1, 1, 2, 2, 3, 3 }; 196 Column expected { 1, 1, 2, 2, 3, 3 };
197 Column actual(C::distribute(in, 6, binfory, 0, false)); 197 Column actual(C::distribute(in, 6, binfory, 0, false));
198 report(actual); 198 report(actual);
199 QCOMPARE(actual, expected); 199 QCOMPARE(actual, expected);
200 } 200 }
201 201
202 void distribute_simple_interpolated() { 202 void distribute_simple_interpolated() {
203 Column in { 1, 2, 3 }; 203 Column in { 1, 2, 3 };
204 BinMapping binfory { 0.0, 0.5, 1.0, 1.5, 2.0, 2.5 }; 204 BinMapping binfory { 0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f };
205 // There is a 0.5-bin offset from the distribution you might 205 // There is a 0.5-bin offset from the distribution you might
206 // expect, because this corresponds visually to the way that 206 // expect, because this corresponds visually to the way that
207 // bin values are duplicated upwards in simple_distribution. 207 // bin values are duplicated upwards in simple_distribution.
208 // It means that switching between interpolated and 208 // It means that switching between interpolated and
209 // non-interpolated views retains the visual position of each 209 // non-interpolated views retains the visual position of each
210 // bin peak as somewhere in the middle of the scale area for 210 // bin peak as somewhere in the middle of the scale area for
211 // that bin. 211 // that bin.
212 Column expected { 1, 1, 1.5, 2, 2.5, 3 }; 212 Column expected { 1, 1, 1.5f, 2, 2.5f, 3 };
213 Column actual(C::distribute(in, 6, binfory, 0, true)); 213 Column actual(C::distribute(in, 6, binfory, 0, true));
214 report(actual); 214 report(actual);
215 QCOMPARE(actual, expected); 215 QCOMPARE(actual, expected);
216 } 216 }
217 217
218 void distribute_nonlinear() { 218 void distribute_nonlinear() {
219 Column in { 1, 2, 3 }; 219 Column in { 1, 2, 3 };
220 BinMapping binfory { 0.0, 0.2, 0.5, 1.0, 2.0, 2.5 }; 220 BinMapping binfory { 0.0f, 0.2f, 0.5f, 1.0f, 2.0f, 2.5f };
221 Column expected { 1, 1, 1, 2, 3, 3 }; 221 Column expected { 1, 1, 1, 2, 3, 3 };
222 Column actual(C::distribute(in, 6, binfory, 0, false)); 222 Column actual(C::distribute(in, 6, binfory, 0, false));
223 report(actual); 223 report(actual);
224 QCOMPARE(actual, expected); 224 QCOMPARE(actual, expected);
225 } 225 }
226 226
227 void distribute_nonlinear_interpolated() { 227 void distribute_nonlinear_interpolated() {
228 // See distribute_simple_interpolated 228 // See distribute_simple_interpolated
229 Column in { 1, 2, 3 }; 229 Column in { 1, 2, 3 };
230 BinMapping binfory { 0.0, 0.2, 0.5, 1.0, 2.0, 2.5 }; 230 BinMapping binfory { 0.0f, 0.2f, 0.5f, 1.0f, 2.0f, 2.5f };
231 Column expected { 1, 1, 1, 1.5, 2.5, 3 }; 231 Column expected { 1, 1, 1, 1.5, 2.5, 3 };
232 Column actual(C::distribute(in, 6, binfory, 0, true)); 232 Column actual(C::distribute(in, 6, binfory, 0, true));
233 report(actual); 233 report(actual);
234 QCOMPARE(actual, expected); 234 QCOMPARE(actual, expected);
235 } 235 }
236 236
237 void distribute_shrinking() { 237 void distribute_shrinking() {
238 Column in { 4, 1, 2, 3, 5, 6 }; 238 Column in { 4, 1, 2, 3, 5, 6 };
239 BinMapping binfory { 0.0, 2.0, 4.0 }; 239 BinMapping binfory { 0.0f, 2.0f, 4.0f };
240 Column expected { 4, 3, 6 }; 240 Column expected { 4, 3, 6 };
241 Column actual(C::distribute(in, 3, binfory, 0, false)); 241 Column actual(C::distribute(in, 3, binfory, 0, false));
242 report(actual); 242 report(actual);
243 QCOMPARE(actual, expected); 243 QCOMPARE(actual, expected);
244 } 244 }
245 245
246 void distribute_shrinking_interpolated() { 246 void distribute_shrinking_interpolated() {
247 // should be same as distribute_shrinking, we don't 247 // should be same as distribute_shrinking, we don't
248 // interpolate when resizing down 248 // interpolate when resizing down
249 Column in { 4, 1, 2, 3, 5, 6 }; 249 Column in { 4, 1, 2, 3, 5, 6 };
250 BinMapping binfory { 0.0, 2.0, 4.0 }; 250 BinMapping binfory { 0.0f, 2.0f, 4.0f };
251 Column expected { 4, 3, 6 }; 251 Column expected { 4, 3, 6 };
252 Column actual(C::distribute(in, 3, binfory, 0, true)); 252 Column actual(C::distribute(in, 3, binfory, 0, true));
253 report(actual); 253 report(actual);
254 QCOMPARE(actual, expected); 254 QCOMPARE(actual, expected);
255 } 255 }
257 void distribute_nonlinear_someshrinking_interpolated() { 257 void distribute_nonlinear_someshrinking_interpolated() {
258 // But we *should* interpolate if the mapping involves 258 // But we *should* interpolate if the mapping involves
259 // shrinking some bins but expanding others. See 259 // shrinking some bins but expanding others. See
260 // distribute_simple_interpolated for note on 0.5 offset 260 // distribute_simple_interpolated for note on 0.5 offset
261 Column in { 4, 1, 2, 3, 5, 6 }; 261 Column in { 4, 1, 2, 3, 5, 6 };
262 BinMapping binfory { 0.0, 3.0, 4.0, 4.5 }; 262 BinMapping binfory { 0.0f, 3.0f, 4.0f, 4.5f };
263 Column expected { 4.0, 2.5, 4.0, 5.0 }; 263 Column expected { 4.0f, 2.5f, 4.0f, 5.0f };
264 Column actual(C::distribute(in, 4, binfory, 0, true)); 264 Column actual(C::distribute(in, 4, binfory, 0, true));
265 report(actual); 265 report(actual);
266 QCOMPARE(actual, expected); 266 QCOMPARE(actual, expected);
267 binfory = BinMapping { 0.5, 1.0, 2.0, 5.0 }; 267 binfory = BinMapping { 0.5f, 1.0f, 2.0f, 5.0f };
268 expected = { 4.0, 2.5, 1.5, 5.5 }; 268 expected = { 4.0f, 2.5f, 1.5f, 5.5f };
269 actual = (C::distribute(in, 4, binfory, 0, true)); 269 actual = (C::distribute(in, 4, binfory, 0, true));
270 report(actual); 270 report(actual);
271 QCOMPARE(actual, expected); 271 QCOMPARE(actual, expected);
272 } 272 }
273 }; 273 };