comparison Test.cpp @ 52:4bd0cd3c60f3

Fix erroneous timestamp printing in verbose feature output (it was printing (none) if there was a timestamp instead of if there wasn't); print only diffs; update SDK subrepo
author Chris Cannam
date Fri, 12 Sep 2014 18:05:52 +0100
parents f1e8e14e9c96
children 86d8a699dfbe
comparison
equal deleted inserted replaced
51:13db8d010367 52:4bd0cd3c60f3
52 #endif 52 #endif
53 53
54 Test::Test() { } 54 Test::Test() { }
55 Test::~Test() { } 55 Test::~Test() { }
56 56
57 using std::cerr;
58 using std::cout;
59 using std::endl;
60 using std::string;
61
57 Plugin * 62 Plugin *
58 Test::load(std::string key, float rate) 63 Test::load(string key, float rate)
59 { 64 {
60 Plugin *p = PluginLoader::getInstance()->loadPlugin 65 Plugin *p = PluginLoader::getInstance()->loadPlugin
61 (key, rate, PluginLoader::ADAPT_ALL); 66 (key, rate, PluginLoader::ADAPT_ALL);
62 if (!p) throw FailedToLoadPlugin(); 67 if (!p) throw FailedToLoadPlugin();
63 return p; 68 return p;
169 } 174 }
170 return true; 175 return true;
171 } 176 }
172 177
173 void 178 void
174 Test::dump(const Plugin::FeatureSet &fs) 179 Test::dumpFeature(const Plugin::Feature &f, bool showValues)
180 {
181 cout << " Timestamp: " << (!f.hasTimestamp ? "(none)" : f.timestamp.toText()) << endl;
182 cout << " Duration: " << (!f.hasDuration ? "(none)" : f.duration.toText()) << endl;
183 cout << " Label: " << (f.label == "" ? "(none)" : f.label) << endl;
184 if (showValues) {
185 cout << " Values (" << f.values.size() << "): " << (f.values.empty() ? "(none)" : "");
186 for (int j = 0; j < (int)f.values.size(); ++j) {
187 cout << f.values[j] << " ";
188 }
189 cout << endl;
190 } else {
191 cout << " Values (" << f.values.size() << "): (elided)" << endl;
192 }
193 }
194
195 void
196 Test::dump(const Plugin::FeatureSet &fs, bool showValues)
175 { 197 {
176 for (Plugin::FeatureSet::const_iterator fsi = fs.begin(); 198 for (Plugin::FeatureSet::const_iterator fsi = fs.begin();
177 fsi != fs.end(); ++fsi) { 199 fsi != fs.end(); ++fsi) {
178 int output = fsi->first; 200 int output = fsi->first;
179 std::cout << "Output " << output << ":" << std::endl; 201 cout << "Output " << output << ":" << endl;
180 const Plugin::FeatureList &fl = fsi->second; 202 const Plugin::FeatureList &fl = fsi->second;
181 for (int i = 0; i < (int)fl.size(); ++i) { 203 for (int i = 0; i < (int)fl.size(); ++i) {
182 std::cout << " Feature " << i << ":" << std::endl; 204 cout << " Feature " << i << ":" << endl;
183 const Plugin::Feature &f = fl[i]; 205 const Plugin::Feature &f = fl[i];
184 std::cout << " Timestamp: " << (f.hasTimestamp ? "(none)" : f.timestamp.toText()) << std::endl; 206 dumpFeature(f, showValues);
185 std::cout << " Duration: " << (f.hasDuration ? "(none)" : f.duration.toText()) << std::endl; 207 }
186 std::cout << " Label: " << (f.label == "" ? "(none)" : f.label) << std::endl; 208 }
187 std::cout << " Value: " << (f.values.empty() ? "(none)" : ""); 209 }
188 for (int j = 0; j < (int)f.values.size(); ++j) { 210
189 std::cout << f.values[j] << " "; 211 void
190 } 212 Test::dumpTwo(const Result &r,
191 std::cout << std::endl; 213 const Plugin::FeatureSet &a,
192 } 214 const Plugin::FeatureSet &b)
193 }
194 }
195
196 void
197 Test::dump(const Result &r,
198 const Plugin::FeatureSet &a,
199 const Plugin::FeatureSet &b)
200 { 215 {
201 std::cout << r.message() << std::endl; 216 std::cout << r.message() << std::endl;
202 std::cout << "\nFirst result set:" << std::endl; 217 std::cout << "\nFirst result set:" << std::endl;
203 dump(a); 218 dump(a, false);
204 std::cout << "\nSecond result set:" << std::endl; 219 std::cout << "\nSecond result set:" << std::endl;
205 dump(b); 220 dump(b, false);
206 std::cout << std::endl; 221 std::cout << std::endl;
222 }
223
224 void
225 Test::dumpDiff(const Result &r,
226 const Plugin::FeatureSet &a,
227 const Plugin::FeatureSet &b)
228 {
229 cout << r.message() << endl;
230 cout << "\nDifferences follow:" << endl;
231 if (a.size() != b.size()) {
232 cout << "*** First result set has features on " << a.size()
233 << " output(s), second has features on " << b.size()
234 << endl;
235 return;
236 }
237 Plugin::FeatureSet::const_iterator ai = a.begin();
238 Plugin::FeatureSet::const_iterator bi = b.begin();
239 while (ai != a.end()) {
240 if (ai->first != bi->first) {
241 cout << "\n*** Output number mismatch: first result set says "
242 << ai->first << " where second says " << bi->first
243 << endl;
244 } else {
245 cout << "\nOutput " << ai->first << ":" << endl;
246 if (ai->second.size() != bi->second.size()) {
247 cout << "*** First result set has " << ai->second.size()
248 << " feature(s) on this output, second has "
249 << bi->second.size() << endl;
250 } else {
251 int fno = 0;
252 int diffcount = 0;
253 Plugin::FeatureList::const_iterator afi = ai->second.begin();
254 Plugin::FeatureList::const_iterator bfi = bi->second.begin();
255 while (afi != ai->second.end()) {
256 if (!(*afi == *bfi)) {
257 if (diffcount == 0) {
258 bool differInValues = (afi->values != bfi->values);
259 if (afi->hasTimestamp != bfi->hasTimestamp) {
260 cout << "*** Feature " << fno << " differs in presence of timestamp (" << afi->hasTimestamp << " vs " << bfi->hasTimestamp << ")" << endl;
261 }
262 if (afi->hasTimestamp && (afi->timestamp != bfi->timestamp)) {
263 cout << "*** Feature " << fno << " differs in timestamp (" << afi->timestamp << " vs " << bfi->timestamp << " )" << endl;
264 }
265 if (afi->hasDuration != bfi->hasDuration) {
266 cout << "*** Feature " << fno << " differs in presence of duration (" << afi->hasDuration << " vs " << bfi->hasDuration << ")" << endl;
267 }
268 if (afi->hasDuration && (afi->duration != bfi->duration)) {
269 cout << "*** Feature " << fno << " differs in duration (" << afi->duration << " vs " << bfi->duration << " )" << endl;
270 }
271 if (afi->label != bfi->label) {
272 cout << "*** Feature " << fno << " differs in label" << endl;
273 }
274 if (differInValues) {
275 cout << "*** Feature " << fno << " differs in values" << endl;
276 }
277 cout << " First output:" << endl;
278 dumpFeature(*afi, differInValues);
279 cout << " Second output:" << endl;
280 dumpFeature(*bfi, differInValues);
281 }
282 ++diffcount;
283 }
284 ++fno;
285 ++afi;
286 ++bfi;
287 }
288 if (diffcount > 1) {
289 cout << diffcount-1 << " subsequent differing feature(s) elided" << endl;
290 }
291 }
292 }
293 ++ai;
294 ++bi;
295 }
296 cout << endl;
207 } 297 }
208 298
209 bool 299 bool
210 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b) 300 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
211 { 301 {