Revision 33:5f2a57b1a75a

View differences:

NoteHypothesis.h
49 49
    ~NoteHypothesis();
50 50

  
51 51
    struct Estimate {
52
        Estimate() : freq(0), time(), confidence(0) { }
53
        Estimate(double _f, RealTime _t, double _c) :
54
            freq(_f), time(_t), confidence(_c) { }
52 55
	double freq;
53 56
	RealTime time;
54 57
	double confidence;
......
76 79
    Estimates getAcceptedEstimates() const;
77 80

  
78 81
    struct Note {
82
        Note() : freq(0), time(), duration() { }
83
        Note(double _f, RealTime _t, RealTime _d) :
84
            freq(_f), time(_t), duration(_d) { }
79 85
	double freq;
80 86
	RealTime time;
81 87
	RealTime duration;
test/TestNoteHypothesis.h
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

Also available in: Unified diff