-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_writer.py
171 lines (132 loc) · 6.28 KB
/
test_writer.py
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
#!/usr/bin/env python3
from unittest import TestCase
from unittest.mock import patch
from writer import *
class TestGenerateNote(TestCase):
@patch('reader.Note')
@patch('reader.Attributes')
def setUp(self, MockNote, MockAttributes):
attributes = MockAttributes()
attributes.getKeySignature.return_value = 'C'
note = MockNote()
note.isRest.return_value = False
note.getPitch.return_value = ('C', 4)
note.getDisplayedDuration.return_value = (2, 2)
note.isTuplet.return_value = False
note.isTupletStart.return_value = False
note.isTupletStop.return_value = False
note.isSlide.return_value = False
note.isSlideStart.return_value = False
note.isSlideStop.return_value = False
note.isTieStart.return_value = False
note.isTieStop.return_value = False
note.getAttributes.return_value = attributes
note.getTremolo.return_value = 0
self.note = note
self.writer = Jianpu99Writer()
def test_pitches(self):
note = self.note
note.getPitch.return_value = ('C', 4)
self.assertEqual(self.writer.generateNote(note), "1")
note.getPitch.return_value = ('D', 4)
self.assertEqual(self.writer.generateNote(note), "2")
note.getPitch.return_value = ('E', 4)
self.assertEqual(self.writer.generateNote(note), "3")
note.getPitch.return_value = ('F', 4)
self.assertEqual(self.writer.generateNote(note), "4")
note.getPitch.return_value = ('G', 4)
self.assertEqual(self.writer.generateNote(note), "5")
note.getPitch.return_value = ('A', 4)
self.assertEqual(self.writer.generateNote(note), "6")
note.getPitch.return_value = ('B', 4)
self.assertEqual(self.writer.generateNote(note), "7")
note.getPitch.return_value = ('C', 5)
# dot over note
self.assertEqual(self.writer.generateNote(note), "1'")
note.getPitch.return_value = ('D', 5)
self.assertEqual(self.writer.generateNote(note), "2'")
note.getPitch.return_value = ('E', 5)
self.assertEqual(self.writer.generateNote(note), "3'")
note.getPitch.return_value = ('C', 6)
self.assertEqual(self.writer.generateNote(note), "1''")
# dot under note
note.getPitch.return_value = ('B', 3)
self.assertEqual(self.writer.generateNote(note), "7,")
note.getPitch.return_value = ('A', 3)
self.assertEqual(self.writer.generateNote(note), "6,")
def test_accidentals(self):
note = self.note
note.getPitch.return_value = ('A#', 5)
self.assertEqual(self.writer.generateNote(note), "6#'")
note.getPitch.return_value = ('Eb', 3)
self.assertEqual(self.writer.generateNote(note), "3$,")
def test_durations(self):
note = self.note
note.getDisplayedDuration.return_value = (2, 2)
self.assertEqual(self.writer.generateNote(note), "1")
note.getDisplayedDuration.return_value = (4, 2)
self.assertEqual(self.writer.generateNote(note), "1 -")
note.getDisplayedDuration.return_value = (6, 2)
self.assertEqual(self.writer.generateNote(note), "1 - -")
note.getDisplayedDuration.return_value = (8, 2)
self.assertEqual(self.writer.generateNote(note), "1 - - -")
note.getDisplayedDuration.return_value = (1, 2)
self.assertEqual(self.writer.generateNote(note), "1/")
note.getDisplayedDuration.return_value = (1, 4)
self.assertEqual(self.writer.generateNote(note), "1//")
note.getDisplayedDuration.return_value = (1, 8)
self.assertEqual(self.writer.generateNote(note), "1///")
# syncopated notes
note.getDisplayedDuration.return_value = (3, 2)
self.assertEqual(self.writer.generateNote(note), "1.")
note.getDisplayedDuration.return_value = (3, 4)
self.assertEqual(self.writer.generateNote(note), "1./")
def test_rest(self):
note = self.note
note.isRest.return_value = True
self.assertEqual(self.writer.generateNote(note), "0")
note.getDisplayedDuration.return_value = (4, 2)
self.assertEqual(self.writer.generateNote(note), "0 -")
note.getDisplayedDuration.return_value = (1, 2)
self.assertEqual(self.writer.generateNote(note), "0/")
def test_tie(self):
note = self.note
note.getDisplayedDuration.return_value = (6, 6)
note.isTieStart.return_value = True
self.assertEqual(self.writer.generateNote(note), "( 1")
note.isTieStart.return_value = False
note.isTieStop.return_value = True
self.assertEqual(self.writer.generateNote(note), "1 )")
note.getDisplayedDuration.return_value = (12, 6)
self.assertEqual(self.writer.generateNote(note), "1 ) -")
def test_tuplet(self):
note = self.note
note.isTuplet.return_value = True
note.getDisplayedDuration.return_value = (3, 6)
# tuplet start
note.isTupletStart.return_value = True
note.isTupletStop.return_value = False
self.assertEqual(self.writer.generateNote(note), "(y1/")
# tuplet middle notes
note.isTupletStart.return_value = False
note.isTupletStop.return_value = False
self.assertEqual(self.writer.generateNote(note), "1/")
# tuplet stop
note.isTupletStart.return_value = False
note.isTupletStop.return_value = True
self.assertEqual(self.writer.generateNote(note), "1/)")
# 3 notes in 2 beats, should be displayed as quarter notes
note.getDisplayedDuration.return_value = (6, 6)
note.isTupletStart.return_value = False
note.isTupletStop.return_value = False
self.assertEqual(self.writer.generateNote(note), "1")
class TestTranspose(TestCase):
def test_transpose_pitch(self):
self.assertEqual(getTransposedPitch('C', 4, offset=3), ('D#', 4))
self.assertEqual(getTransposedPitch('D', 4, offset=-3), ('B', 3))
self.assertEqual(getTransposedPitch('Bb', 4, offset=2), ('C', 5))
def test_transpose_offset(self):
self.assertEqual(getTransposeOffsetToC('F'), -5)
self.assertEqual(getTransposeOffsetToC('C'), 0)
self.assertEqual(getTransposeOffsetToC('G'), 5)
self.assertEqual(getTransposeOffsetToC('F#'), -6)