Fixed bug with subdivisions and added tests

This commit is contained in:
2023-02-23 18:22:43 +02:00
parent 63dab6fbdf
commit 6dd8333007
2 changed files with 21 additions and 1 deletions

View File

@ -87,3 +87,20 @@ def test_subdivisions(pattern: str, expected: list):
def test_repeats(pattern: str, expected: list):
assert zparse(pattern).notes() == expected
@pytest.mark.parametrize(
"pattern,expected",
[
("0 [0 2] 0", [0.25, 0.125, 0.125, 0.25, 0.25, 0.125, 0.125, 0.25, 0.25, 0.125, 0.125, 0.25]),
("w 0 [0 [1 [2 3]] 0] 9", [1.0, 0.3333333333333333, 0.16666666666666666, 0.08333333333333333, 0.08333333333333333, 0.3333333333333333, 1.0, 1.0, 0.3333333333333333, 0.16666666666666666, 0.08333333333333333, 0.08333333333333333]),
("1.0 0 [[2 3] [3 5]] 4", [1.0, 0.25, 0.25, 0.25, 0.25, 1.0, 1.0, 0.25, 0.25, 0.25, 0.25, 1.0]),
("2.0 0 [1[2[3[4 5]6]7]8] 9", [2.0, 0.6666666666666666, 0.2222222222222222, 0.07407407407407407, 0.037037037037037035, 0.037037037037037035, 0.07407407407407407, 0.2222222222222222, 0.6666666666666666, 2.0, 2.0, 0.6666666666666666])
]
)
def test_looping_durations(pattern: str, expected: list):
parsed = zparse(pattern)
durations = []
for i in range(12):
durations.append(parsed[i].duration)
assert durations == expected