Revision 52:4bd0cd3c60f3 Test.cpp

View differences:

Test.cpp
54 54
Test::Test() { }
55 55
Test::~Test() { }
56 56

  
57
using std::cerr;
58
using std::cout;
59
using std::endl;
60
using std::string;
61

  
57 62
Plugin *
58
Test::load(std::string key, float rate)
63
Test::load(string key, float rate)
59 64
{
60 65
    Plugin *p = PluginLoader::getInstance()->loadPlugin
61 66
        (key, rate, PluginLoader::ADAPT_ALL);
......
171 176
}
172 177

  
173 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 198
    for (Plugin::FeatureSet::const_iterator fsi = fs.begin();
177 199
         fsi != fs.end(); ++fsi) {
178 200
        int output = fsi->first;
179
        std::cout << "Output " << output << ":" << std::endl;
201
        cout << "Output " << output << ":" << endl;
180 202
        const Plugin::FeatureList &fl = fsi->second;
181 203
        for (int i = 0; i < (int)fl.size(); ++i) {
182
            std::cout << "  Feature " << i << ":" << std::endl;
204
            cout << "  Feature " << i << ":" << endl;
183 205
            const Plugin::Feature &f = fl[i];
184
            std::cout << "    Timestamp: " << (f.hasTimestamp ? "(none)" : f.timestamp.toText()) << std::endl;
185
            std::cout << "    Duration: " << (f.hasDuration ? "(none)" : f.duration.toText()) << std::endl;
186
            std::cout << "    Label: " << (f.label == "" ? "(none)" : f.label) << std::endl;
187
            std::cout << "    Value: " << (f.values.empty() ? "(none)" : "");
188
            for (int j = 0; j < (int)f.values.size(); ++j) {
189
                std::cout << f.values[j] << " ";
190
            }
191
            std::cout << std::endl;
206
            dumpFeature(f, showValues);
192 207
        }
193 208
    }
194 209
}
195 210

  
196 211
void
197
Test::dump(const Result &r,
198
           const Plugin::FeatureSet &a,
199
           const Plugin::FeatureSet &b)
212
Test::dumpTwo(const Result &r,
213
              const Plugin::FeatureSet &a,
214
              const Plugin::FeatureSet &b)
200 215
{
201 216
    std::cout << r.message() << std::endl;
202 217
    std::cout << "\nFirst result set:" << std::endl;
203
    dump(a);
218
    dump(a, false);
204 219
    std::cout << "\nSecond result set:" << std::endl;
205
    dump(b);
220
    dump(b, false);
206 221
    std::cout << std::endl;
207 222
}
208 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;
297
}
298

  
209 299
bool
210 300
operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
211 301
{

Also available in: Unified diff