Mercurial > hg > btrack
comparison unit-tests/BTrack Tests/tests/Test_BTrack.cpp @ 56:b6d440942ff6
Added some simple unit tests. Removed the destructor from the BTrack class as it was unnecessary.
author | Adam Stark <adamstark@users.noreply.github.com> |
---|---|
date | Thu, 23 Jan 2014 12:17:06 +0000 |
parents | |
children | baf35f208814 |
comparison
equal
deleted
inserted
replaced
55:5e520f59127f | 56:b6d440942ff6 |
---|---|
1 #ifndef BTRACK_TESTS | |
2 #define BTRACK_TESTS | |
3 | |
4 #define BOOST_TEST_DYN_LINK | |
5 #include <boost/test/unit_test.hpp> | |
6 | |
7 #include <iostream> | |
8 #include "../../../src/BTrack.h" | |
9 | |
10 //====================================================================== | |
11 //=================== PROCESSING SIMPLE VALUES ========================= | |
12 //====================================================================== | |
13 BOOST_AUTO_TEST_SUITE(processingSimpleValues) | |
14 | |
15 //====================================================================== | |
16 BOOST_AUTO_TEST_CASE(processZeroValuedOnsetDetectionFunctionSamples) | |
17 { | |
18 BTrack b(512); | |
19 | |
20 long numSamples = 20000; | |
21 | |
22 std::vector<double> odfSamples; | |
23 | |
24 int maxInterval = 0; | |
25 int currentInterval = 0; | |
26 int numBeats = 0; | |
27 | |
28 for (int i = 0;i < numSamples;i++) | |
29 { | |
30 b.processOnsetDetectionFunctionSample(0.0); | |
31 | |
32 currentInterval++; | |
33 | |
34 if (b.playbeat == 1) | |
35 { | |
36 numBeats++; | |
37 | |
38 if (currentInterval > maxInterval) | |
39 { | |
40 maxInterval = currentInterval; | |
41 } | |
42 | |
43 currentInterval = 0; | |
44 } | |
45 } | |
46 | |
47 // check that the maximum interval between beats does not | |
48 // exceed 100 onset detection function samples (~ 1.3 seconds) | |
49 BOOST_CHECK(maxInterval < 100); | |
50 | |
51 // check that we have at least a beat for every 100 samples | |
52 BOOST_CHECK(numBeats > (numSamples/100)); | |
53 | |
54 } | |
55 | |
56 //====================================================================== | |
57 BOOST_AUTO_TEST_CASE(processRandomOnsetDetectionFunctionSamples) | |
58 { | |
59 BTrack b(512); | |
60 | |
61 long numSamples = 20000; | |
62 | |
63 std::vector<double> odfSamples; | |
64 | |
65 int maxInterval = 0; | |
66 int currentInterval = 0; | |
67 int numBeats = 0; | |
68 | |
69 for (int i = 0;i < numSamples;i++) | |
70 { | |
71 odfSamples.push_back(random() % 1000); | |
72 } | |
73 | |
74 for (int i = 0;i < numSamples;i++) | |
75 { | |
76 b.processOnsetDetectionFunctionSample(odfSamples[i]); | |
77 | |
78 currentInterval++; | |
79 | |
80 if (b.playbeat == 1) | |
81 { | |
82 numBeats++; | |
83 | |
84 if (currentInterval > maxInterval) | |
85 { | |
86 maxInterval = currentInterval; | |
87 } | |
88 | |
89 currentInterval = 0; | |
90 } | |
91 } | |
92 | |
93 // check that the maximum interval between beats does not | |
94 // exceed 100 onset detection function samples (~ 1.3 seconds) | |
95 BOOST_CHECK(maxInterval < 100); | |
96 | |
97 // check that we have at least a beat for every 100 samples | |
98 BOOST_CHECK(numBeats > (numSamples/100)); | |
99 | |
100 } | |
101 | |
102 //====================================================================== | |
103 BOOST_AUTO_TEST_CASE(processNegativeOnsetDetectionFunctionSamples) | |
104 { | |
105 BTrack b(512); | |
106 | |
107 long numSamples = 20000; | |
108 | |
109 std::vector<double> odfSamples; | |
110 | |
111 int maxInterval = 0; | |
112 int currentInterval = 0; | |
113 int numBeats = 0; | |
114 | |
115 for (int i = 0;i < numSamples;i++) | |
116 { | |
117 odfSamples.push_back(-1.0*(random() % 1000)); | |
118 } | |
119 | |
120 for (int i = 0;i < numSamples;i++) | |
121 { | |
122 b.processOnsetDetectionFunctionSample(odfSamples[i]); | |
123 | |
124 currentInterval++; | |
125 | |
126 if (b.playbeat == 1) | |
127 { | |
128 numBeats++; | |
129 | |
130 if (currentInterval > maxInterval) | |
131 { | |
132 maxInterval = currentInterval; | |
133 } | |
134 | |
135 currentInterval = 0; | |
136 } | |
137 } | |
138 | |
139 // check that the maximum interval between beats does not | |
140 // exceed 100 onset detection function samples (~ 1.3 seconds) | |
141 BOOST_CHECK(maxInterval < 100); | |
142 | |
143 // check that we have at least a beat for every 100 samples | |
144 BOOST_CHECK(numBeats > (numSamples/100)); | |
145 | |
146 } | |
147 | |
148 //====================================================================== | |
149 BOOST_AUTO_TEST_CASE(processSeriesOfDeltaFunctions) | |
150 { | |
151 BTrack b(512); | |
152 | |
153 long numSamples = 20000; | |
154 int beatPeriod = 43; | |
155 | |
156 std::vector<double> odfSamples; | |
157 | |
158 int maxInterval = 0; | |
159 int currentInterval = 0; | |
160 int numBeats = 0; | |
161 int correct = 0; | |
162 | |
163 for (int i = 0;i < numSamples;i++) | |
164 { | |
165 if (i % beatPeriod == 0) | |
166 { | |
167 odfSamples.push_back(1000); | |
168 } | |
169 else | |
170 { | |
171 odfSamples.push_back(0.0); | |
172 } | |
173 } | |
174 | |
175 for (int i = 0;i < numSamples;i++) | |
176 { | |
177 b.processOnsetDetectionFunctionSample(odfSamples[i]); | |
178 | |
179 currentInterval++; | |
180 | |
181 if (b.playbeat == 1) | |
182 { | |
183 numBeats++; | |
184 | |
185 if (currentInterval > maxInterval) | |
186 { | |
187 maxInterval = currentInterval; | |
188 } | |
189 | |
190 if (currentInterval == beatPeriod) | |
191 { | |
192 correct++; | |
193 } | |
194 | |
195 currentInterval = 0; | |
196 } | |
197 } | |
198 | |
199 // check that the maximum interval between beats does not | |
200 // exceed 100 onset detection function samples (~ 1.3 seconds) | |
201 BOOST_CHECK(maxInterval < 100); | |
202 | |
203 // check that we have at least a beat for every 100 samples | |
204 BOOST_CHECK(numBeats > (numSamples/100)); | |
205 | |
206 // check that the number of correct beats is larger than 99% | |
207 // of the total number of beats | |
208 BOOST_CHECK(((double)correct) > (((double)numBeats)*0.99)); | |
209 } | |
210 | |
211 | |
212 BOOST_AUTO_TEST_SUITE_END() | |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 #endif |