summaryrefslogtreecommitdiffstats
path: root/src/base/test/accidentals.cpp
blob: c3ee4f3208d912729e5b653e3eb45782ab654bc2 (plain)
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
#include "NotationTypes.h"

using namespace Rosegarden;
using std::cout;

// Unit test-ish tests for resolving accidentals
// 
// Returns -1 (or crashes :)) on error, 0 on success
void assertHasAccidental(Pitch &pitch, 
	const Accidental& accidental, const Key& key)
{
  	Accidental calculatedAccidental = 
		pitch.getAccidental(key);

	std::cout << "Got " << calculatedAccidental << " for pitch " << pitch.getPerformancePitch() << " in key " << key.getName() << std::endl;

	if (calculatedAccidental != accidental)
	{
		std::cout << "Expected " << accidental << std::endl;
		exit(-1);
	}
}

void testBInEMinor()
{
	// a B, also in E minor, has no accidental
  	Pitch testPitch(59 % 12);
	assertHasAccidental(testPitch,
		Accidentals::NoAccidental, Key("E minor"));
}

/**
 *
 */
void testFInBMinor()
{
  	Pitch testPitch(77);
	assertHasAccidental(testPitch,
		Accidentals::NoAccidental, Key("B minor"));
}

void testInvalidSuggestion()
{
	// If we specify an invalid suggestion,
	// getAccidental() should be robust against that.
  	Pitch testPitch = Pitch(59, Accidentals::Sharp);
	assertHasAccidental(testPitch,
		Accidentals::NoAccidental, Key("E minor"));
}

int main(int argc, char **argv)
{
  testBInEMinor();
  testFInBMinor();
  testInvalidSuggestion();
  std::cout << "Success" << std::endl;
  exit(0);
}