Skip to content

Commit

Permalink
writes a unit test a makes it passes
Browse files Browse the repository at this point in the history
  • Loading branch information
nivlekp committed Aug 18, 2024
1 parent 39befa3 commit b653c7d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
36 changes: 35 additions & 1 deletion minamidera/soundpointsgenerators.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
import statistics

import pang
import numpy as np


class AtaxicSoundPointsGenerator(pang.SoundPointsGenerator):
def __init__(self, pitches_set, intensity_set, density_set, duration_set):
def __init__(self, pitches_set, intensity_set, density_set, duration_set, seed):
self.pitches_set = pitches_set
self.intensity_set = intensity_set
self.density_set = density_set
self.duration_set = duration_set
self._random_number_generator = np.random.default_rng(seed)

def __call__(self, sequence_duration):
instances = self._generate_instances(sequence_duration)
return [
pang.SoundPoint(instance, duration, pitch)
for instance, duration, pitch in zip(
instances,
self._generate_durations(len(instances)),
self._generate_pitches(len(instances)),
)
]

def _generate_instances(self, sequence_duration):
(density,) = self.density_set
return sorted(
self._random_number_generator.uniform(
0.0, sequence_duration, density * sequence_duration
)
)

def _generate_durations(self, number_of_sound_points):
(duration,) = self.duration_set
return self._random_number_generator.exponential(
duration, number_of_sound_points
)

def _generate_pitches(self, number_of_sound_points):
return self._random_number_generator.choice(
tuple(self.pitches_set), number_of_sound_points
).tolist()
1 change: 1 addition & 0 deletions minamidera/statemapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ def map_state_vector_to_sound_points_generator(
INTENSITY_SETS[state_vector[1]],
DENSITY_SETS[state_vector[2]],
DURATION_SETS[state_vector[3]],
238492,
)
10 changes: 10 additions & 0 deletions tests/test_soundpointgenerators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from minamidera import soundpointsgenerators


def test_generated_sound_points_list_is_not_empty():
assert (
soundpointsgenerators.AtaxicSoundPointsGenerator(
{0, 1, 2}, {0}, {1}, {1}, 2984756
)(10)
!= []
)

0 comments on commit b653c7d

Please sign in to comment.