# HG changeset patch # User Chris Cannam # Date 1342214041 -3600 # Node ID 5f2a57b1a75afc63ee564035b0011853d1c6ab78 # Parent c88a9972975b61e79c57a4dd0188cd1161bc8334 Simple hypothesis test cases diff -r c88a9972975b -r 5f2a57b1a75a NoteHypothesis.h --- a/NoteHypothesis.h Fri Jul 13 21:40:50 2012 +0100 +++ b/NoteHypothesis.h Fri Jul 13 22:14:01 2012 +0100 @@ -49,6 +49,9 @@ ~NoteHypothesis(); struct Estimate { + Estimate() : freq(0), time(), confidence(0) { } + Estimate(double _f, RealTime _t, double _c) : + freq(_f), time(_t), confidence(_c) { } double freq; RealTime time; double confidence; @@ -76,6 +79,9 @@ Estimates getAcceptedEstimates() const; struct Note { + Note() : freq(0), time(), duration() { } + Note(double _f, RealTime _t, RealTime _d) : + freq(_f), time(_t), duration(_d) { } double freq; RealTime time; RealTime duration; diff -r c88a9972975b -r 5f2a57b1a75a test/TestNoteHypothesis.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/TestNoteHypothesis.h Fri Jul 13 22:14:01 2012 +0100 @@ -0,0 +1,106 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ +/* Copyright Chris Cannam - All Rights Reserved */ + +#ifndef TEST_NOTE_HYPOTHESIS_H +#define TEST_NOTE_HYPOTHESIS_H + +#include "base/NoteHypothesis.h" + +#include +#include + +namespace Turbot { + +class TestNoteHypothesis : public QObject +{ + Q_OBJECT + +private slots: + void emptyAccept() { + NoteHypothesis h; + NoteHypothesis::Estimate e; + QCOMPARE(h.getState(), NoteHypothesis::New); + QVERIFY(h.accept(e)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + } + + void simpleSatisfy() { + NoteHypothesis h; + NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1); + NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 1); + NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1); + NoteHypothesis::Estimate e4(500, RealTime::fromMilliseconds(30), 1); + NoteHypothesis::Estimate e5(500, RealTime::fromMilliseconds(80), 1); + NoteHypothesis::Estimate e6(500, RealTime::fromMilliseconds(90), 1); + QCOMPARE(h.getState(), NoteHypothesis::New); + QVERIFY(h.accept(e1)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(h.accept(e2)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(h.accept(e3)); + QCOMPARE(h.getState(), NoteHypothesis::Satisfied); + QVERIFY(h.accept(e4)); + QCOMPARE(h.getState(), NoteHypothesis::Satisfied); + QVERIFY(!h.accept(e5)); + QCOMPARE(h.getState(), NoteHypothesis::Expired); + QVERIFY(!h.accept(e6)); + QCOMPARE(h.getState(), NoteHypothesis::Expired); + } + + void strayReject() { + NoteHypothesis h; + NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1); + NoteHypothesis::Estimate e2(1000, RealTime::fromMilliseconds(10), 1); + NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1); + NoteHypothesis::Estimate e4(500, RealTime::fromMilliseconds(30), 1); + QCOMPARE(h.getState(), NoteHypothesis::New); + QVERIFY(h.accept(e1)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(!h.accept(e2)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(h.accept(e3)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(h.accept(e4)); + QCOMPARE(h.getState(), NoteHypothesis::Satisfied); + } + + void tooSlow() { + NoteHypothesis h; + NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1); + NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(50), 1); + QCOMPARE(h.getState(), NoteHypothesis::New); + QVERIFY(h.accept(e1)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(!h.accept(e2)); + QCOMPARE(h.getState(), NoteHypothesis::Rejected); + } + + void weakSatisfy() { + NoteHypothesis h; + NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 0.5); + NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 0.5); + NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 0.5); + NoteHypothesis::Estimate e4(500, RealTime::fromMilliseconds(30), 0.5); + NoteHypothesis::Estimate e5(500, RealTime::fromMilliseconds(40), 0.5); + NoteHypothesis::Estimate e6(500, RealTime::fromMilliseconds(90), 0.5); + QCOMPARE(h.getState(), NoteHypothesis::New); + QVERIFY(h.accept(e1)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(h.accept(e2)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(h.accept(e3)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(h.accept(e4)); + QCOMPARE(h.getState(), NoteHypothesis::Provisional); + QVERIFY(h.accept(e5)); + QCOMPARE(h.getState(), NoteHypothesis::Satisfied); + QVERIFY(!h.accept(e6)); + QCOMPARE(h.getState(), NoteHypothesis::Expired); + } + + +}; + +} + +#endif