To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / TestNoteHypothesis.h @ 33:5f2a57b1a75a
History | View | Annotate | Download (3.54 KB)
| 1 |
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
|---|---|
| 2 |
/* Copyright Chris Cannam - All Rights Reserved */
|
| 3 |
|
| 4 |
#ifndef TEST_NOTE_HYPOTHESIS_H
|
| 5 |
#define TEST_NOTE_HYPOTHESIS_H
|
| 6 |
|
| 7 |
#include "base/NoteHypothesis.h" |
| 8 |
|
| 9 |
#include <QObject> |
| 10 |
#include <QtTest> |
| 11 |
|
| 12 |
namespace Turbot {
|
| 13 |
|
| 14 |
class TestNoteHypothesis : public QObject |
| 15 |
{
|
| 16 |
Q_OBJECT |
| 17 |
|
| 18 |
private slots: |
| 19 |
void emptyAccept() {
|
| 20 |
NoteHypothesis h; |
| 21 |
NoteHypothesis::Estimate e; |
| 22 |
QCOMPARE(h.getState(), NoteHypothesis::New); |
| 23 |
QVERIFY(h.accept(e)); |
| 24 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 25 |
} |
| 26 |
|
| 27 |
void simpleSatisfy() {
|
| 28 |
NoteHypothesis h; |
| 29 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1); |
| 30 |
NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 1); |
| 31 |
NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1); |
| 32 |
NoteHypothesis::Estimate e4(500, RealTime::fromMilliseconds(30), 1); |
| 33 |
NoteHypothesis::Estimate e5(500, RealTime::fromMilliseconds(80), 1); |
| 34 |
NoteHypothesis::Estimate e6(500, RealTime::fromMilliseconds(90), 1); |
| 35 |
QCOMPARE(h.getState(), NoteHypothesis::New); |
| 36 |
QVERIFY(h.accept(e1)); |
| 37 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 38 |
QVERIFY(h.accept(e2)); |
| 39 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 40 |
QVERIFY(h.accept(e3)); |
| 41 |
QCOMPARE(h.getState(), NoteHypothesis::Satisfied); |
| 42 |
QVERIFY(h.accept(e4)); |
| 43 |
QCOMPARE(h.getState(), NoteHypothesis::Satisfied); |
| 44 |
QVERIFY(!h.accept(e5)); |
| 45 |
QCOMPARE(h.getState(), NoteHypothesis::Expired); |
| 46 |
QVERIFY(!h.accept(e6)); |
| 47 |
QCOMPARE(h.getState(), NoteHypothesis::Expired); |
| 48 |
} |
| 49 |
|
| 50 |
void strayReject() {
|
| 51 |
NoteHypothesis h; |
| 52 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1); |
| 53 |
NoteHypothesis::Estimate e2(1000, RealTime::fromMilliseconds(10), 1); |
| 54 |
NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 1); |
| 55 |
NoteHypothesis::Estimate e4(500, RealTime::fromMilliseconds(30), 1); |
| 56 |
QCOMPARE(h.getState(), NoteHypothesis::New); |
| 57 |
QVERIFY(h.accept(e1)); |
| 58 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 59 |
QVERIFY(!h.accept(e2)); |
| 60 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 61 |
QVERIFY(h.accept(e3)); |
| 62 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 63 |
QVERIFY(h.accept(e4)); |
| 64 |
QCOMPARE(h.getState(), NoteHypothesis::Satisfied); |
| 65 |
} |
| 66 |
|
| 67 |
void tooSlow() {
|
| 68 |
NoteHypothesis h; |
| 69 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 1); |
| 70 |
NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(50), 1); |
| 71 |
QCOMPARE(h.getState(), NoteHypothesis::New); |
| 72 |
QVERIFY(h.accept(e1)); |
| 73 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 74 |
QVERIFY(!h.accept(e2)); |
| 75 |
QCOMPARE(h.getState(), NoteHypothesis::Rejected); |
| 76 |
} |
| 77 |
|
| 78 |
void weakSatisfy() {
|
| 79 |
NoteHypothesis h; |
| 80 |
NoteHypothesis::Estimate e1(500, RealTime::fromMilliseconds(0), 0.5); |
| 81 |
NoteHypothesis::Estimate e2(500, RealTime::fromMilliseconds(10), 0.5); |
| 82 |
NoteHypothesis::Estimate e3(500, RealTime::fromMilliseconds(20), 0.5); |
| 83 |
NoteHypothesis::Estimate e4(500, RealTime::fromMilliseconds(30), 0.5); |
| 84 |
NoteHypothesis::Estimate e5(500, RealTime::fromMilliseconds(40), 0.5); |
| 85 |
NoteHypothesis::Estimate e6(500, RealTime::fromMilliseconds(90), 0.5); |
| 86 |
QCOMPARE(h.getState(), NoteHypothesis::New); |
| 87 |
QVERIFY(h.accept(e1)); |
| 88 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 89 |
QVERIFY(h.accept(e2)); |
| 90 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 91 |
QVERIFY(h.accept(e3)); |
| 92 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 93 |
QVERIFY(h.accept(e4)); |
| 94 |
QCOMPARE(h.getState(), NoteHypothesis::Provisional); |
| 95 |
QVERIFY(h.accept(e5)); |
| 96 |
QCOMPARE(h.getState(), NoteHypothesis::Satisfied); |
| 97 |
QVERIFY(!h.accept(e6)); |
| 98 |
QCOMPARE(h.getState(), NoteHypothesis::Expired); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
}; |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
#endif
|