This repository has been archived by the owner on Sep 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instrument_test.cpp
94 lines (82 loc) · 1.96 KB
/
instrument_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/** \file Unit tests for DefaultInstrument Module
*/
#include "catch.hpp"
#include "signal.hpp"
#include "track.hpp"
#include "instrument.hpp"
TEST_CASE("Tested instrument halt", "[track]") {
Track t(480);
t.addTempoEvent(500000, 0);
t.addNoteEvent(9, 62, 20, 100);
t.addEndEvent(400);
Signal curr(44100);
DefaultInstrument i(t);
double samp;
samp = i.sample(1 / 44100);
REQUIRE(samp == 0);
REQUIRE(i.halted() == false);
}
TEST_CASE("Tested instrument", "[track]") {
Track t(480);
t.addTempoEvent(500000, 0);
t.addNoteEvent(9, 62, 20, 100);
t.addEndEvent(400);
Signal curr(44100);
DefaultInstrument i(t);
double n = 0;
double samp = 0;
samp = i.sample(1 / 44100);
while (!i.halted()) {
double delta = n / 44100;
samp = i.sample(delta);
curr.push_back(samp);
n = n + 1;
}
REQUIRE(i.halted() == true);
}
TEST_CASE("Tested instrument with other notes", "[track]") {
Track t(560);
t.addTempoEvent(500000, 0);
t.addNoteEvent(9, 62, 20, 100);
t.addNoteEvent(8, 62, 20, 200);
t.addNoteEvent(9, 63, 20, 300);
t.addNoteEvent(8, 63, 20, 400);
t.addNoteEvent(9, 64, 20, 500);
t.addNoteEvent(8, 64, 20, 600);
t.addEndEvent(800);
Signal curr(44100);
DefaultInstrument i(t);
double n = 0;
double samp = 0;
samp = i.sample(1 / 44100);
while (!i.halted()) {
double delta = n / 44100;
samp = i.sample(delta);
curr.push_back(samp);
n = n + 1;
}
REQUIRE(i.halted() == true);
}
TEST_CASE("Tested instrument with other notes again", "[track]") {
Track t(480);
t.addTempoEvent(500000, 0);
t.addNoteEvent(9, 62, 20, 100);
t.addNoteEvent(8, 62, 20, 200);
t.addNoteEvent(9, 70, 20, 300);
t.addNoteEvent(8, 70, 20, 400);
t.addNoteEvent(9, 80, 20, 500);
t.addNoteEvent(8, 80, 20, 600);
t.addEndEvent(800);
Signal curr(44100);
DefaultInstrument i(t);
double n = 0;
double samp = 0;
samp = i.sample(1 / 44100);
while (!i.halted()) {
double delta = n / 44100;
samp = i.sample(delta);
curr.push_back(samp);
n = n + 1;
}
REQUIRE(i.halted() == true);
}