From ae1154d0f6e9b6e5b827455eb53e305933586bce Mon Sep 17 00:00:00 2001 From: nivlekp Date: Mon, 12 Aug 2024 21:20:27 +1000 Subject: [PATCH 01/14] adds a unit test for empty sequence --- minamidera/statemapper.py | 2 +- tests/test_statemapper.py | 7 +++++++ tests/test_states.py | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/test_statemapper.py diff --git a/minamidera/statemapper.py b/minamidera/statemapper.py index 59ce287..af95ec9 100644 --- a/minamidera/statemapper.py +++ b/minamidera/statemapper.py @@ -5,7 +5,7 @@ def map_state_sequence(state_sequence: Iterable[npt.NDArray]) -> pang.Sequence: - sequence = pang.Sequence([], 0) + sequence = pang.Sequence.empty_sequence() for state in state_sequence: sequence.extend(map_state(state)) return sequence diff --git a/tests/test_statemapper.py b/tests/test_statemapper.py new file mode 100644 index 0000000..3279a18 --- /dev/null +++ b/tests/test_statemapper.py @@ -0,0 +1,7 @@ +import pang + +from minamidera import statemapper + + +def test_mapping_empty_sequence(): + assert statemapper.map_state_sequence([]) == pang.Sequence.empty_sequence() diff --git a/tests/test_states.py b/tests/test_states.py index 1efc8bf..2afcc20 100644 --- a/tests/test_states.py +++ b/tests/test_states.py @@ -28,6 +28,7 @@ def test_generating_state_sequences(): ) assert len(state_sequences) == number_of_state_vectors assert all([len(sequence) == sequence_length for sequence in state_sequences]) + # TODO: assert statistical properties perhaps def test_enumerating_state_vectors(): From 1f6a23b143de3389b1657ef44b4a95db84efd3de Mon Sep 17 00:00:00 2001 From: nivlekp Date: Mon, 12 Aug 2024 21:22:07 +1000 Subject: [PATCH 02/14] bumps pang --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ad0d0f..dd1ce07 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: env: LILYPOND_VERSION: 2.25.16 - PANG_COMMIT: b5dc6468810789ed8cf79136a7f0a31932904400 + PANG_COMMIT: 63a6320d8bd680feffcb6d22e5743bf9d9ed28af PANG_PATH: /tmp/pang jobs: From e3666dca2c9743e8f2736f3f86d9d9392c8399a0 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Tue, 13 Aug 2024 19:25:22 +1000 Subject: [PATCH 03/14] bumps version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 483b341..2ea5863 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ allow-direct-references = true [project] name = "minamidera" -version = "24.8b0" +version = "24.8b1" authors = [ { name="Tsz Kiu Pang" }, ] From f9a9b66c878a48a2423559ea358212bb826de24c Mon Sep 17 00:00:00 2001 From: nivlekp Date: Tue, 13 Aug 2024 19:38:41 +1000 Subject: [PATCH 04/14] renames module --- minamidera/__init__.py | 4 ++-- minamidera/library.py | 2 ++ minamidera/{states.py => statetransition.py} | 0 tests/test_states.py | 10 +++++----- 4 files changed, 9 insertions(+), 7 deletions(-) rename minamidera/{states.py => statetransition.py} (100%) diff --git a/minamidera/__init__.py b/minamidera/__init__.py index 102afc8..bbf7a80 100644 --- a/minamidera/__init__.py +++ b/minamidera/__init__.py @@ -1,3 +1,3 @@ -from . import library, states +from . import library, statemapper, statetransition -__all__ = ["library", "states"] +__all__ = ["library", "statemapper", "statetransition"] diff --git a/minamidera/library.py b/minamidera/library.py index 5cd711c..742a362 100644 --- a/minamidera/library.py +++ b/minamidera/library.py @@ -5,6 +5,7 @@ FREQUENCY_REGIONS = enum.Enum("FREQUENCY_REGIONS", ["F0", "F1"]) INTENSITY_REGIONS = enum.Enum("INTENSITY_REGIONS", ["G0", "G1"]) DENSITY_REGIONS = enum.Enum("DENSITY_REGIONS", ["D0", "D1"]) +DURATION_REGIONS = enum.Enum("DURATION_REGIONS", ["L0", "L1"]) @dataclasses.dataclass @@ -12,3 +13,4 @@ class State: frequency_region: FREQUENCY_REGIONS intensity_region: INTENSITY_REGIONS density_region: DENSITY_REGIONS + duration_region: DURATION_REGIONS diff --git a/minamidera/states.py b/minamidera/statetransition.py similarity index 100% rename from minamidera/states.py rename to minamidera/statetransition.py diff --git a/tests/test_states.py b/tests/test_states.py index 2afcc20..f3f03f9 100644 --- a/tests/test_states.py +++ b/tests/test_states.py @@ -1,18 +1,18 @@ import numpy as np -from minamidera import states +from minamidera import statetransition def test_getting_next_state(): state = (0, 0, 1, 1) - next_state = states.get_next_state(state, np.random.default_rng()) + next_state = statetransition.get_next_state(state, np.random.default_rng()) assert len(next_state) == 4 def test_generating_state_sequence(): initial_state = (0, 0, 0, 0) sequence_length = 100 - state_sequence = states.generate_state_sequence( + state_sequence = statetransition.generate_state_sequence( initial_state, sequence_length, np.random.default_rng() ) assert len(state_sequence) == sequence_length @@ -23,7 +23,7 @@ def test_generating_state_sequences(): number_of_state_vectors = 100 initial_states = tuple(initial_state for _ in range(number_of_state_vectors)) sequence_length = 10 - state_sequences = states.generate_state_sequences( + state_sequences = statetransition.generate_state_sequences( initial_states, sequence_length, np.random.default_rng() ) assert len(state_sequences) == number_of_state_vectors @@ -32,7 +32,7 @@ def test_generating_state_sequences(): def test_enumerating_state_vectors(): - assert states.enumerate_state_vectors(4, 2) == { + assert statetransition.enumerate_state_vectors(4, 2) == { 0: (0, 0, 0, 0), 1: (0, 0, 0, 1), 2: (0, 0, 1, 0), From a2731614b28428ab36db9d222beaf31d02dfc0c9 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Tue, 13 Aug 2024 19:40:11 +1000 Subject: [PATCH 05/14] renames test --- tests/{test_states.py => test_statetransition.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{test_states.py => test_statetransition.py} (100%) diff --git a/tests/test_states.py b/tests/test_statetransition.py similarity index 100% rename from tests/test_states.py rename to tests/test_statetransition.py From daac77cec1ac3fb8a04ad84a56e89039749940b9 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Tue, 13 Aug 2024 20:10:01 +1000 Subject: [PATCH 06/14] adds a bit more state mapping logic --- minamidera/library.py | 17 +++++++++++++++++ tests/test_library.py | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tests/test_library.py diff --git a/minamidera/library.py b/minamidera/library.py index 742a362..0e4c72b 100644 --- a/minamidera/library.py +++ b/minamidera/library.py @@ -1,6 +1,8 @@ import dataclasses import enum +import numpy.typing as npt + AXIS = enum.Enum("AXIS", ["FREQUENCY", "INTENSITY", "DENSITY"]) FREQUENCY_REGIONS = enum.Enum("FREQUENCY_REGIONS", ["F0", "F1"]) INTENSITY_REGIONS = enum.Enum("INTENSITY_REGIONS", ["G0", "G1"]) @@ -14,3 +16,18 @@ class State: intensity_region: INTENSITY_REGIONS density_region: DENSITY_REGIONS duration_region: DURATION_REGIONS + + @classmethod + def from_state_vector(cls, state_vector: npt.NDArray) -> "State": + if len(dataclasses.fields(cls)) != len(state_vector): + raise ValueError( + f"The shape of the state vector {state_vector} does not match the shape of the state dataclass {dataclasses.fields(cls)}" + ) + if any(state not in (0, 1) for state in state_vector): + raise ValueError(f"The state vector contains value other than 0 and 1") + return cls( + FREQUENCY_REGIONS(state_vector[0] + 1), + INTENSITY_REGIONS(state_vector[1] + 1), + DENSITY_REGIONS(state_vector[2] + 1), + DURATION_REGIONS(state_vector[3] + 1), + ) diff --git a/tests/test_library.py b/tests/test_library.py new file mode 100644 index 0000000..91ad1a2 --- /dev/null +++ b/tests/test_library.py @@ -0,0 +1,25 @@ +import numpy as np +import pytest + +from minamidera import library + + +def test_creating_state_dataclass_from_invalid_state_vector_length(): + with pytest.raises(ValueError) as exception_info: + library.State.from_state_vector(np.array([0, 0, 1, 0, 0])) + assert "does not match" in str(exception_info) + + +def test_creating_state_dataclass_from_invalid_state_vector_value(): + with pytest.raises(ValueError) as exception_info: + library.State.from_state_vector(np.array([0, 1, 0, 2])) + assert "contains value other than 0 and 1" in str(exception_info) + + +def test_creating_state_dataclass_from_state_vector(): + assert library.State.from_state_vector(np.array([0, 1, 0, 1])) == library.State( + library.FREQUENCY_REGIONS.F0, + library.INTENSITY_REGIONS.G1, + library.DENSITY_REGIONS.D0, + library.DURATION_REGIONS.L1, + ) From a05a1500030e53b5050c1eacb179e5784749fc07 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Tue, 13 Aug 2024 20:23:11 +1000 Subject: [PATCH 07/14] fixes error message --- minamidera/library.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/minamidera/library.py b/minamidera/library.py index 0e4c72b..4280c9f 100644 --- a/minamidera/library.py +++ b/minamidera/library.py @@ -24,7 +24,9 @@ def from_state_vector(cls, state_vector: npt.NDArray) -> "State": f"The shape of the state vector {state_vector} does not match the shape of the state dataclass {dataclasses.fields(cls)}" ) if any(state not in (0, 1) for state in state_vector): - raise ValueError(f"The state vector contains value other than 0 and 1") + raise ValueError( + f"The state vector {state_vector} contains value other than 0 and 1" + ) return cls( FREQUENCY_REGIONS(state_vector[0] + 1), INTENSITY_REGIONS(state_vector[1] + 1), From 53c1ae8a8fce30c080d1b95bea07eaaa7aac5bec Mon Sep 17 00:00:00 2001 From: nivlekp Date: Fri, 16 Aug 2024 22:02:18 +1000 Subject: [PATCH 08/14] more unit tests --- minamidera/statemapper.py | 6 ++++++ tests/test_statemapper.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/minamidera/statemapper.py b/minamidera/statemapper.py index af95ec9..3063a13 100644 --- a/minamidera/statemapper.py +++ b/minamidera/statemapper.py @@ -3,6 +3,8 @@ import numpy.typing as npt import pang +from .library import State + def map_state_sequence(state_sequence: Iterable[npt.NDArray]) -> pang.Sequence: sequence = pang.Sequence.empty_sequence() @@ -13,3 +15,7 @@ def map_state_sequence(state_sequence: Iterable[npt.NDArray]) -> pang.Sequence: def map_state(state: npt.NDArray) -> pang.Sequence: raise NotImplementedError + + +def map_state_to_sound_points_generator(state: State) -> pang.SoundPointsGenerator: + raise NotImplementedError diff --git a/tests/test_statemapper.py b/tests/test_statemapper.py index 3279a18..9eeda3a 100644 --- a/tests/test_statemapper.py +++ b/tests/test_statemapper.py @@ -1,7 +1,18 @@ +import numpy as np import pang -from minamidera import statemapper +from minamidera import library, statemapper def test_mapping_empty_sequence(): assert statemapper.map_state_sequence([]) == pang.Sequence.empty_sequence() + + +def test_mapping_state_to_sound_point_generator(): + sound_points_generator = statemapper.map_state_to_sound_points_generator( + library.State.from_state_vector(np.array([0, 1, 0, 1])) + ) + assert sound_points_generator.pitches_set == library.PITCHES_SET_0 + assert sound_points_generator.intensity_set == library.INTENSITY_SET_1 + assert sound_points_generator.density_set == library.DENSITY_SET_0 + assert sound_points_generator.duration_set == library.DURATION_SET_1 From 14f4437a415c4a613a1fe5a5f97e8ca9dc6b45d4 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Fri, 16 Aug 2024 22:03:53 +1000 Subject: [PATCH 09/14] marks test as xfail --- tests/test_statemapper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_statemapper.py b/tests/test_statemapper.py index 9eeda3a..40af495 100644 --- a/tests/test_statemapper.py +++ b/tests/test_statemapper.py @@ -1,5 +1,6 @@ import numpy as np import pang +import pytest from minamidera import library, statemapper @@ -8,6 +9,7 @@ def test_mapping_empty_sequence(): assert statemapper.map_state_sequence([]) == pang.Sequence.empty_sequence() +@pytest.mark.xfail def test_mapping_state_to_sound_point_generator(): sound_points_generator = statemapper.map_state_to_sound_points_generator( library.State.from_state_vector(np.array([0, 1, 0, 1])) From 9a0a3de036370783aa3ba329243c00340e0b66a8 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Fri, 16 Aug 2024 22:25:41 +1000 Subject: [PATCH 10/14] making a unit test passes --- Makefile | 1 + minamidera/__init__.py | 4 ++-- minamidera/library.py | 12 ++++++++++++ minamidera/statemapper.py | 10 ++++++++-- tests/test_statemapper.py | 21 ++++++++++++++++----- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 993b9ba..4ce4dfc 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ check: make black-check make flake8 make isort-check + make mypy test: make black-check diff --git a/minamidera/__init__.py b/minamidera/__init__.py index bbf7a80..5864b0b 100644 --- a/minamidera/__init__.py +++ b/minamidera/__init__.py @@ -1,3 +1,3 @@ -from . import library, statemapper, statetransition +from . import library, soundpointsgenerators, statemapper, statetransition -__all__ = ["library", "statemapper", "statetransition"] +__all__ = ["library", "soundpointsgenerators", "statemapper", "statetransition"] diff --git a/minamidera/library.py b/minamidera/library.py index 4280c9f..dc63089 100644 --- a/minamidera/library.py +++ b/minamidera/library.py @@ -10,6 +10,18 @@ DURATION_REGIONS = enum.Enum("DURATION_REGIONS", ["L0", "L1"]) +PITCHES_MAP = { + FREQUENCY_REGIONS.F0: {-6, -5, -4, 0, (1, 2), 3}, + FREQUENCY_REGIONS.F1: {-32, -30, 24, 27}, +} + +INTENSITY_MAP = {INTENSITY_REGIONS.G0: {-1, 0}, INTENSITY_REGIONS.G1: {-2, 2}} + +DENSITY_MAP = {DENSITY_REGIONS.D0: {0.7}, DENSITY_REGIONS.D1: {3.0}} + +DURATION_MAP = {DURATION_REGIONS.L0: {0.3}, DURATION_REGIONS.L1: {1.0}} + + @dataclasses.dataclass class State: frequency_region: FREQUENCY_REGIONS diff --git a/minamidera/statemapper.py b/minamidera/statemapper.py index 3063a13..edb69a7 100644 --- a/minamidera/statemapper.py +++ b/minamidera/statemapper.py @@ -3,7 +3,8 @@ import numpy.typing as npt import pang -from .library import State +from .library import DENSITY_MAP, DURATION_MAP, INTENSITY_MAP, PITCHES_MAP, State +from .soundpointsgenerators import AtaxicSoundPointsGenerator def map_state_sequence(state_sequence: Iterable[npt.NDArray]) -> pang.Sequence: @@ -18,4 +19,9 @@ def map_state(state: npt.NDArray) -> pang.Sequence: def map_state_to_sound_points_generator(state: State) -> pang.SoundPointsGenerator: - raise NotImplementedError + return AtaxicSoundPointsGenerator( + PITCHES_MAP[state.frequency_region], + INTENSITY_MAP[state.intensity_region], + DENSITY_MAP[state.density_region], + DURATION_MAP[state.duration_region], + ) diff --git a/tests/test_statemapper.py b/tests/test_statemapper.py index 40af495..0b13381 100644 --- a/tests/test_statemapper.py +++ b/tests/test_statemapper.py @@ -9,12 +9,23 @@ def test_mapping_empty_sequence(): assert statemapper.map_state_sequence([]) == pang.Sequence.empty_sequence() -@pytest.mark.xfail def test_mapping_state_to_sound_point_generator(): sound_points_generator = statemapper.map_state_to_sound_points_generator( library.State.from_state_vector(np.array([0, 1, 0, 1])) ) - assert sound_points_generator.pitches_set == library.PITCHES_SET_0 - assert sound_points_generator.intensity_set == library.INTENSITY_SET_1 - assert sound_points_generator.density_set == library.DENSITY_SET_0 - assert sound_points_generator.duration_set == library.DURATION_SET_1 + assert ( + sound_points_generator.pitches_set + == library.PITCHES_MAP[library.FREQUENCY_REGIONS.F0] + ) + assert ( + sound_points_generator.intensity_set + == library.INTENSITY_MAP[library.INTENSITY_REGIONS.G1] + ) + assert ( + sound_points_generator.density_set + == library.DENSITY_MAP[library.DENSITY_REGIONS.D0] + ) + assert ( + sound_points_generator.duration_set + == library.DURATION_MAP[library.DURATION_REGIONS.L1] + ) From 18350b144a08706e1ee2164155bd50b675fe5aae Mon Sep 17 00:00:00 2001 From: nivlekp Date: Fri, 16 Aug 2024 22:30:06 +1000 Subject: [PATCH 11/14] removes unused import --- tests/test_statemapper.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_statemapper.py b/tests/test_statemapper.py index 0b13381..d5fa648 100644 --- a/tests/test_statemapper.py +++ b/tests/test_statemapper.py @@ -1,6 +1,5 @@ import numpy as np import pang -import pytest from minamidera import library, statemapper From 0a942fb413748087df62ba33b17467eb9564e074 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Fri, 16 Aug 2024 22:30:25 +1000 Subject: [PATCH 12/14] adds a sound point generator --- minamidera/soundpointsgenerators.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 minamidera/soundpointsgenerators.py diff --git a/minamidera/soundpointsgenerators.py b/minamidera/soundpointsgenerators.py new file mode 100644 index 0000000..ed00155 --- /dev/null +++ b/minamidera/soundpointsgenerators.py @@ -0,0 +1,9 @@ +import pang + + +class AtaxicSoundPointsGenerator(pang.SoundPointsGenerator): + def __init__(self, pitches_set, intensity_set, density_set, duration_set): + self.pitches_set = pitches_set + self.intensity_set = intensity_set + self.density_set = density_set + self.duration_set = duration_set From 43c312e588c77919b5386b41f12930f4d2f63e58 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Sun, 18 Aug 2024 16:56:15 +1000 Subject: [PATCH 13/14] removes one layer of mapping --- minamidera/library.py | 39 ++++--------------------------------- minamidera/statemapper.py | 22 +++++++++++++++------ tests/test_library.py | 25 ------------------------ tests/test_statemapper.py | 41 +++++++++++++++++++++------------------ 4 files changed, 42 insertions(+), 85 deletions(-) delete mode 100644 tests/test_library.py diff --git a/minamidera/library.py b/minamidera/library.py index dc63089..2e87381 100644 --- a/minamidera/library.py +++ b/minamidera/library.py @@ -1,8 +1,5 @@ -import dataclasses import enum -import numpy.typing as npt - AXIS = enum.Enum("AXIS", ["FREQUENCY", "INTENSITY", "DENSITY"]) FREQUENCY_REGIONS = enum.Enum("FREQUENCY_REGIONS", ["F0", "F1"]) INTENSITY_REGIONS = enum.Enum("INTENSITY_REGIONS", ["G0", "G1"]) @@ -10,38 +7,10 @@ DURATION_REGIONS = enum.Enum("DURATION_REGIONS", ["L0", "L1"]) -PITCHES_MAP = { - FREQUENCY_REGIONS.F0: {-6, -5, -4, 0, (1, 2), 3}, - FREQUENCY_REGIONS.F1: {-32, -30, 24, 27}, -} - -INTENSITY_MAP = {INTENSITY_REGIONS.G0: {-1, 0}, INTENSITY_REGIONS.G1: {-2, 2}} - -DENSITY_MAP = {DENSITY_REGIONS.D0: {0.7}, DENSITY_REGIONS.D1: {3.0}} - -DURATION_MAP = {DURATION_REGIONS.L0: {0.3}, DURATION_REGIONS.L1: {1.0}} +PITCHES_SETS = [{-6, -5, -4, 0, (1, 2), 3}, {-32, -30, 24, 27}] +INTENSITY_SETS = [{-1, 0}, {-2, 2}] -@dataclasses.dataclass -class State: - frequency_region: FREQUENCY_REGIONS - intensity_region: INTENSITY_REGIONS - density_region: DENSITY_REGIONS - duration_region: DURATION_REGIONS +DENSITY_SETS = [{0.7}, {3.0}] - @classmethod - def from_state_vector(cls, state_vector: npt.NDArray) -> "State": - if len(dataclasses.fields(cls)) != len(state_vector): - raise ValueError( - f"The shape of the state vector {state_vector} does not match the shape of the state dataclass {dataclasses.fields(cls)}" - ) - if any(state not in (0, 1) for state in state_vector): - raise ValueError( - f"The state vector {state_vector} contains value other than 0 and 1" - ) - return cls( - FREQUENCY_REGIONS(state_vector[0] + 1), - INTENSITY_REGIONS(state_vector[1] + 1), - DENSITY_REGIONS(state_vector[2] + 1), - DURATION_REGIONS(state_vector[3] + 1), - ) +DURATION_SETS = [{0.3}, {1.0}] diff --git a/minamidera/statemapper.py b/minamidera/statemapper.py index edb69a7..cdffe8c 100644 --- a/minamidera/statemapper.py +++ b/minamidera/statemapper.py @@ -3,7 +3,7 @@ import numpy.typing as npt import pang -from .library import DENSITY_MAP, DURATION_MAP, INTENSITY_MAP, PITCHES_MAP, State +from .library import DENSITY_SETS, DURATION_SETS, INTENSITY_SETS, PITCHES_SETS from .soundpointsgenerators import AtaxicSoundPointsGenerator @@ -18,10 +18,20 @@ def map_state(state: npt.NDArray) -> pang.Sequence: raise NotImplementedError -def map_state_to_sound_points_generator(state: State) -> pang.SoundPointsGenerator: +def map_state_vector_to_sound_points_generator( + state_vector: npt.NDArray, +) -> pang.SoundPointsGenerator: + if len(state_vector) != 4: + raise ValueError( + f"The shape of the state vector {state_vector} does not match the number of state variables" + ) + if any(state not in (0, 1) for state in state_vector): + raise ValueError( + f"The state vector {state_vector} contains value other than 0 and 1" + ) return AtaxicSoundPointsGenerator( - PITCHES_MAP[state.frequency_region], - INTENSITY_MAP[state.intensity_region], - DENSITY_MAP[state.density_region], - DURATION_MAP[state.duration_region], + PITCHES_SETS[state_vector[0]], + INTENSITY_SETS[state_vector[1]], + DENSITY_SETS[state_vector[2]], + DURATION_SETS[state_vector[3]], ) diff --git a/tests/test_library.py b/tests/test_library.py deleted file mode 100644 index 91ad1a2..0000000 --- a/tests/test_library.py +++ /dev/null @@ -1,25 +0,0 @@ -import numpy as np -import pytest - -from minamidera import library - - -def test_creating_state_dataclass_from_invalid_state_vector_length(): - with pytest.raises(ValueError) as exception_info: - library.State.from_state_vector(np.array([0, 0, 1, 0, 0])) - assert "does not match" in str(exception_info) - - -def test_creating_state_dataclass_from_invalid_state_vector_value(): - with pytest.raises(ValueError) as exception_info: - library.State.from_state_vector(np.array([0, 1, 0, 2])) - assert "contains value other than 0 and 1" in str(exception_info) - - -def test_creating_state_dataclass_from_state_vector(): - assert library.State.from_state_vector(np.array([0, 1, 0, 1])) == library.State( - library.FREQUENCY_REGIONS.F0, - library.INTENSITY_REGIONS.G1, - library.DENSITY_REGIONS.D0, - library.DURATION_REGIONS.L1, - ) diff --git a/tests/test_statemapper.py b/tests/test_statemapper.py index d5fa648..bfddd3d 100644 --- a/tests/test_statemapper.py +++ b/tests/test_statemapper.py @@ -1,5 +1,6 @@ import numpy as np import pang +import pytest from minamidera import library, statemapper @@ -8,23 +9,25 @@ def test_mapping_empty_sequence(): assert statemapper.map_state_sequence([]) == pang.Sequence.empty_sequence() -def test_mapping_state_to_sound_point_generator(): - sound_points_generator = statemapper.map_state_to_sound_points_generator( - library.State.from_state_vector(np.array([0, 1, 0, 1])) - ) - assert ( - sound_points_generator.pitches_set - == library.PITCHES_MAP[library.FREQUENCY_REGIONS.F0] - ) - assert ( - sound_points_generator.intensity_set - == library.INTENSITY_MAP[library.INTENSITY_REGIONS.G1] - ) - assert ( - sound_points_generator.density_set - == library.DENSITY_MAP[library.DENSITY_REGIONS.D0] - ) - assert ( - sound_points_generator.duration_set - == library.DURATION_MAP[library.DURATION_REGIONS.L1] +def test_mapping_sound_point_generator_from_invalid_state_vector_length(): + with pytest.raises(ValueError) as exception_info: + statemapper.map_state_vector_to_sound_points_generator( + np.array([0, 0, 1, 0, 0]) + ) + assert "does not match" in str(exception_info) + + +def test_mapping_sound_point_generator_from_invalid_state_vector_value(): + with pytest.raises(ValueError) as exception_info: + statemapper.map_state_vector_to_sound_points_generator(np.array([0, 1, 0, 2])) + assert "contains value other than 0 and 1" in str(exception_info) + + +def test_mapping_state_vector_to_sound_point_generator(): + sound_points_generator = statemapper.map_state_vector_to_sound_points_generator( + np.array([0, 1, 0, 1]) ) + assert sound_points_generator.pitches_set == library.PITCHES_SETS[0] + assert sound_points_generator.intensity_set == library.INTENSITY_SETS[1] + assert sound_points_generator.density_set == library.DENSITY_SETS[0] + assert sound_points_generator.duration_set == library.DURATION_SETS[1] From ad66c3dfba411a830df8c51fe8e66e06d2ba1a37 Mon Sep 17 00:00:00 2001 From: nivlekp Date: Sun, 18 Aug 2024 17:00:41 +1000 Subject: [PATCH 14/14] removes unused enums --- minamidera/library.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/minamidera/library.py b/minamidera/library.py index 2e87381..03d96ec 100644 --- a/minamidera/library.py +++ b/minamidera/library.py @@ -1,12 +1,3 @@ -import enum - -AXIS = enum.Enum("AXIS", ["FREQUENCY", "INTENSITY", "DENSITY"]) -FREQUENCY_REGIONS = enum.Enum("FREQUENCY_REGIONS", ["F0", "F1"]) -INTENSITY_REGIONS = enum.Enum("INTENSITY_REGIONS", ["G0", "G1"]) -DENSITY_REGIONS = enum.Enum("DENSITY_REGIONS", ["D0", "D1"]) -DURATION_REGIONS = enum.Enum("DURATION_REGIONS", ["L0", "L1"]) - - PITCHES_SETS = [{-6, -5, -4, 0, (1, 2), 3}, {-32, -30, 24, 27}] INTENSITY_SETS = [{-1, 0}, {-2, 2}]