Mercurial > hg > cepstral-pitchtracker
changeset 33:5f2a57b1a75a
Simple hypothesis test cases
author | Chris Cannam |
---|---|
date | Fri, 13 Jul 2012 22:14:01 +0100 |
parents | c88a9972975b |
children | 3fb9c657d86b |
files | NoteHypothesis.h test/TestNoteHypothesis.h |
diffstat | 2 files changed, 112 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- /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 <QObject> +#include <QtTest> + +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