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
|
import pytest
from fixtures import soloTool as uut, songPool, mockPlayer, testSongs
def test_keyPointAndSongSelection(uut, mockPlayer, testSongs):
def checkJump(before, expectedAfter):
mockPlayer.position = before
uut.jump()
assert mockPlayer.position == expectedAfter
# Key point is initially unset
assert uut.keyPoint is None
# If no song is selected, setting the key point has no effect
assert uut.song is None
uut.keyPoint = 0.5
assert uut.keyPoint is None
# With a song selected, key point can be set and jumping works
uut.addSong(testSongs[0])
uut.keyPoints = [0.3, 0.5]
uut.keyPoint = 0.6
assert uut.keyPoint == 0.6
checkJump(0.8, 0.6)
# When another song is selected, the key point is set to 0.0
uut.addSong(testSongs[1])
uut.song = 1
assert uut.keyPoint == 0.0
checkJump(0.5, 0.0)
# If the selected song has stored key points, the key point is set to the first one instead
uut.song = 0
assert uut.keyPoint == 0.3
checkJump(0.5, 0.3)
def test_keyPointListAndSongSelection(uut, testSongs):
# Key point list is initially unset, since no song is selected
assert uut.keyPoint is None
# If no song is selected, setting the key point list has no effect
assert uut.song is None
uut.keyPoints = [0.5]
assert uut.keyPoints is None
# When a song is added, key point list is initialized to empty
uut.addSong(testSongs[0])
assert uut.keyPoints == []
# A new list can be assigned to the song, but it does not affect the current key point
uut.keyPoints = [0.1, 0.3]
assert uut.keyPoints == [0.1, 0.3]
assert uut.keyPoint == 0.0
# Each song has its own list of key points
uut.addSong(testSongs[1])
uut.song = 1
uut.keyPoints = [0.4]
uut.song = 0
assert uut.keyPoints == [0.1, 0.3]
uut.song = 1
assert uut.keyPoints == [0.4]
def test_keyPointEdgeCases(uut, testSongs):
uut.addSong(testSongs[0])
# Key point cannot be unset
uut.keyPoint = None
assert uut.keyPoint == 0.0
# Valid key points are in [0, 1)
uut.keyPoint = -0.1
assert uut.keyPoint == 0.0
uut.keyPoint = 1.0
assert uut.keyPoint == 0.0
uut.keyPoint = 0.999
assert uut.keyPoint == 0.999
def test_keyPointListEdgeCases(uut, testSongs):
uut.addSong(testSongs[0])
# Key point list cannot be unset
uut.keyPoints = None
assert uut.keyPoints == []
# Appending to the list has no effect
uut.keyPoints.append(0.5)
assert uut.keyPoints == []
# Added key points are automatically de-duplicated, sanitized and sorted to ascending order
uut.keyPoints = [0.2, 0.4, 0.1, 0.2, None, -0.5, 1.0, 1.5]
assert uut.keyPoints == [0.1, 0.2, 0.4]
def test_keyPointSelectionNotification(uut, testSongs):
called = False
receivedValue = None
def callback(value):
nonlocal called, receivedValue
called = True
receivedValue = value
uut.registerKeyPointSelectionCallback(callback)
assert not called
# Selecting a song for the first time sets the key point to 0.0
uut.addSong(testSongs[0])
assert called
assert receivedValue == 0.0
called = False
# Changing the key point triggers a notification
uut.keyPoint = 0.5
assert called
assert receivedValue == 0.5
called = False
# Adding list of key points does not trigger a notification
uut.keyPoints = [0.2, 0.4]
assert not called
# Assigning the same key point again does not trigger a notification
uut.keyPoint = 0.5
assert not called
# Changing song triggers the notification
uut.addSong(testSongs[1])
uut.song = 1
assert called
assert receivedValue == 0.0
called = False
# But only if the key point really changes
uut.keyPoint = 0.2
assert called
assert receivedValue == 0.2
called = False
uut.song = 0
assert not called
def test_keyPointListNotification(uut, testSongs):
called = False
receivedValue = None
def callback(value):
nonlocal called, receivedValue
called = True
receivedValue = value
uut.registerKeyPointListCallback(callback)
assert not called
# Adding the first song triggers since the list is now not None
uut.addSong(testSongs[0])
assert called
assert receivedValue == []
called = False
# Adding list of key points triggers
uut.keyPoints = [0.2, 0.4]
assert called
assert receivedValue == [0.2, 0.4]
called = False
# Same list does not trigger
uut.keyPoints = [0.2, 0.4]
assert called
assert receivedValue == [0.2, 0.4]
called = False
# Incrementing list of key points triggers after sanitization
uut.keyPoints += [0.2, None, 0.1]
assert called
assert receivedValue == [0.1, 0.2, 0.4]
called = False
# Changing song triggers
uut.addSong(testSongs[1])
uut.song = 1
assert called
assert receivedValue == []
called = False
# But only if the list really changed
uut.keyPoints = [0.1, 0.2, 0.4]
assert called
assert receivedValue == [0.1, 0.2, 0.4]
called = False
uut.song = 0
assert not called
|