-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.c
234 lines (193 loc) · 7.01 KB
/
test.c
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "mahler.h"
#include "macros.h"
// Global Test Variable //
struct Test {
int pass;
int total;
};
struct Test TEST = {0};
enum mah_error ERR = MAH_ERROR_NONE;
// Function Prototypes //
void assert(int val, int line, char* file, char* expr);
bool comp_note(struct mah_note note_a, struct mah_note note_b);
bool comp_notes(struct mah_note const* notes_a, struct mah_note const* notes_b, int size_a, int size_b);
bool comp_interval(struct mah_interval inter_a, struct mah_interval inter_b);
bool comp_inters(struct mah_interval const* inters_a, struct mah_interval const* inters_b, int size_a, int size_b);
bool comp_key_sig(struct mah_key_sig key_a, struct mah_key_sig key_b);
bool comp_chord(struct mah_chord chord_a, struct mah_chord chord_b);
bool comp_chord_result_list(struct mah_chord_result_list list_a, struct mah_chord_result_list list_b);
bool comp_chord_result(struct mah_chord_result result_a, struct mah_chord_result result_b);
bool comp_chord_results(struct mah_chord_result* results_a, struct mah_chord_result* results_b, int size_a, int size_b);
bool comp_chord_base(struct mah_chord_base const* base_a, struct mah_chord_base const* base_b);
bool comp_scale(struct mah_scale scale_a, struct mah_scale scale_b);
bool comp_scale_result_list(struct mah_scale_result_list list_a, struct mah_scale_result_list list_b);
bool comp_scale_result(struct mah_scale_result result_a, struct mah_scale_result result_b);
bool comp_scale_results(struct mah_scale_result* results_a, struct mah_scale_result* results_b, int size_a, int size_b);
bool comp_scale_base(struct mah_scale_base const* base_a, struct mah_scale_base const* base_b);
int
main(void)
{
#include "suites/inter/mah_return_inter.test"
#include "suites/inter/mah_get_inter.test"
#include "suites/key/mah_get_key_sig.test"
#include "suites/key/mah_return_key_sig.test"
#include "suites/key/mah_get_key_relative.test"
#include "suites/key/mah_query_acci.test"
#include "suites/misc/mah_is_enharmonic.test"
#include "suites/misc/mah_write_note.test"
#include "suites/misc/mah_get_error.test"
#include "suites/chord/mah_invert_chord.test"
#include "suites/chord/mah_get_chord.test"
#include "suites/chord/mah_return_chord.test"
#include "suites/scale/mah_get_scale.test"
#include "suites/scale/mah_return_scale.test"
printf("%d / %d Tests Passed", TEST.pass, TEST.total);
if (TEST.pass != TEST.total) {
return EXIT_FAILURE;
}
}
// Function Definitions //
void
assert(int val, int line, char* file, char* expr)
{
TEST.total++;
if (val) {
TEST.pass++;
} else {
fprintf(stderr, "%s @ LINE %d | %s\n", file, line, expr);
}
ERR = MAH_ERROR_NONE;
}
bool
comp_note(struct mah_note note_a, struct mah_note note_b)
{
return note_a.tone == note_b.tone &&
note_a.acci == note_b.acci &&
note_a.pitch == note_b.pitch;
}
bool
comp_notes(struct mah_note const* notes_a, struct mah_note const* notes_b, int size_a, int size_b)
{
if (size_a != size_b) {
return false;
}
for (int i = 0; i < size_a; i++) {
if (!comp_note(notes_a[i], notes_b[i])) {
return false;
}
}
return true;
}
bool
comp_interval(struct mah_interval inter_a, struct mah_interval inter_b)
{
return inter_a.steps == inter_b.steps &&
inter_a.qual == inter_b.qual;
}
bool
comp_inters(struct mah_interval const* inters_a, struct mah_interval const* inters_b, int size_a, int size_b)
{
if (size_a != size_b) {
return false;
}
for (int i = 0; i < size_a; i++) {
if (!comp_interval(inters_a[i], inters_b[i])) {
return false;
}
}
return true;
}
bool
comp_key_sig(struct mah_key_sig key_a, struct mah_key_sig key_b)
{
return key_a.type == key_b.type &&
key_a.alter == key_b.alter &&
key_a.size == key_b.size &&
comp_note(key_a.key, key_b.key) &&
comp_notes(key_a.notes, key_b.notes, key_a.size, key_b.size);
}
bool
comp_chord(struct mah_chord chord_a, struct mah_chord chord_b)
{
return chord_a.size == chord_b.size &&
chord_a.inv == chord_b.inv &&
comp_notes(chord_a.notes, chord_b.notes, chord_a.size, chord_b.size) &&
comp_notes(chord_a.base, chord_b.base, chord_a.size, chord_b.size);
}
bool
comp_chord_base(struct mah_chord_base const* base_a, struct mah_chord_base const* base_b)
{
return !strcmp(base_a->name, base_b->name) &&
base_a->size == base_b->size &&
comp_inters(base_a->steps, base_b->steps, base_a->size, base_b->size);
}
bool
comp_chord_result(struct mah_chord_result result_a, struct mah_chord_result result_b)
{
return comp_note(result_a.key, result_b.key) &&
comp_chord_base(result_a.chord, result_b.chord);
}
bool
comp_chord_result_list(struct mah_chord_result_list list_a, struct mah_chord_result_list list_b)
{
return list_a.max == list_b.max &&
list_a.size == list_b.size &&
comp_chord_results(list_a.results, list_b.results, list_a.size, list_b.size);
}
bool
comp_chord_results(struct mah_chord_result* results_a, struct mah_chord_result* results_b, int size_a, int size_b)
{
if (size_a != size_b) {
return false;
}
for (int i = 0; i < size_a; i++) {
if (!comp_chord_result(results_a[i], results_b[i])) {
return false;
}
}
return true;
}
bool
comp_scale(struct mah_scale scale_a, struct mah_scale scale_b)
{
return scale_a.size == scale_b.size &&
scale_a.type == scale_b.type &&
comp_notes(scale_a.notes, scale_b.notes, scale_a.size, scale_b.size);
}
bool
comp_scale_base(struct mah_scale_base const* base_a, struct mah_scale_base const* base_b)
{
return !strcmp(base_a->name, base_b->name) &&
base_a->size == base_b->size &&
comp_inters(base_a->steps, base_b->steps, base_a->size, base_b->size);
}
bool
comp_scale_result(struct mah_scale_result result_a, struct mah_scale_result result_b)
{
return comp_note(result_a.key, result_b.key) &&
comp_scale_base(result_a.scale, result_b.scale);
}
bool
comp_scale_result_list(struct mah_scale_result_list list_a, struct mah_scale_result_list list_b)
{
return list_a.max == list_b.max &&
list_a.size == list_b.size &&
comp_scale_results(list_a.results, list_b.results, list_a.size, list_b.size);
}
bool
comp_scale_results(struct mah_scale_result* results_a, struct mah_scale_result* results_b, int size_a, int size_b)
{
if (size_a != size_b) {
return false;
}
for (int i = 0; i < size_a; i++) {
if (!comp_scale_result(results_a[i], results_b[i])) {
return false;
}
}
return true;
}