Ejemplo n.º 1
0
def test_stackability(fragment: Fragment, n_semitones_to_penalty: dict[int,
                                                                       float],
                      expected: float) -> None:
    """Test `evaluate_stackability` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_stackability(fragment, n_semitones_to_penalty)
    assert result == expected
Ejemplo n.º 2
0
def test_create_lilypond_file_from_fragment(path_to_tmp_file: str,
                                            fragment: Fragment,
                                            expected: str) -> None:
    """Test `create_lilypond_file_from_fragment` function."""
    fragment = override_calculated_attributes(fragment)
    create_lilypond_file_from_fragment(fragment, path_to_tmp_file)
    with open(path_to_tmp_file) as in_file:
        result = in_file.read()
        assert result == expected
Ejemplo n.º 3
0
def test_parse_scoring_sets_registry(fragment: Fragment,
                                     params: list[dict[str, Any]],
                                     scoring_sets: list[str],
                                     expected: float) -> None:
    """Test `parse_scoring_sets_registry` function."""
    fragment = override_calculated_attributes(fragment)
    registry = parse_scoring_sets_registry(params)
    result = evaluate(fragment, scoring_sets, registry)
    assert round(result, 10) == round(expected, 10)
Ejemplo n.º 4
0
def test_evaluate_consistency_of_rhythm_with_meter(fragment: Fragment,
                                                   consistent_patterns: list[
                                                       list[float]],
                                                   expected: float) -> None:
    """Test `evaluate_consistency_of_rhythm_with_meter` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_consistency_of_rhythm_with_meter(fragment,
                                                       consistent_patterns)
    assert result == expected
Ejemplo n.º 5
0
def test_evaluate_smoothness_of_voice_leading(
        fragment: Fragment, penalty_deduction_per_line: float,
        n_semitones_to_penalty: dict[int, float], expected: float) -> None:
    """Test `evaluate_smoothness_of_voice_leading` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_smoothness_of_voice_leading(fragment,
                                                  penalty_deduction_per_line,
                                                  n_semitones_to_penalty)
    assert round(result, 10) == round(expected, 10)
Ejemplo n.º 6
0
def test_evaluate_climax_explicity(fragment: Fragment,
                                   height_penalties: dict[int, float],
                                   duplication_penalty: float,
                                   expected: float) -> None:
    """Test `evaluate_climax_explicity` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_climax_explicity(fragment, height_penalties,
                                       duplication_penalty)
    assert result == expected
Ejemplo n.º 7
0
def test_evaluate_cadence_duration(fragment: Fragment, max_duration: float,
                                   last_sonority_weight: float,
                                   last_notes_weight: float,
                                   expected: float) -> None:
    """Test `evaluate_cadence_duration` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_cadence_duration(fragment, max_duration,
                                       last_sonority_weight, last_notes_weight)
    assert result == expected
Ejemplo n.º 8
0
def test_evaluate_absence_of_simultaneous_skips(fragment: Fragment,
                                                min_skip_in_semitones: int,
                                                max_skips_share: float,
                                                expected: float) -> None:
    """Test `evaluate_absence_of_simultaneous_skips` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_absence_of_simultaneous_skips(fragment,
                                                    min_skip_in_semitones,
                                                    max_skips_share)
    assert result == expected
Ejemplo n.º 9
0
def test_evaluate_harmony_dynamic(fragment: Fragment,
                                  regular_positions: list[dict[str, Any]],
                                  ad_hoc_positions: list[dict[str, Any]],
                                  ranges: dict[str, tuple[float, float]],
                                  n_semitones_to_stability: dict[int, float],
                                  expected: float) -> None:
    """Test `evaluate_harmony_dynamic` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_harmony_dynamic(fragment, regular_positions,
                                      ad_hoc_positions, ranges,
                                      n_semitones_to_stability)
    assert round(result, 10) == expected
Ejemplo n.º 10
0
def test_create_tsv_events_from_fragment(path_to_tmp_file: str,
                                         fragment: Fragment,
                                         expected: str) -> None:
    """Test `create_tsv_events_from_fragment` function."""
    fragment = override_calculated_attributes(fragment)
    create_tsv_events_from_fragment(
        fragment,
        path_to_tmp_file,
        beat_in_seconds=0.5,
        instruments={k: 'additive_mellow_pipe'
                     for k in fragment.line_ids},
        effects={k: ''
                 for k in fragment.line_ids},
        velocity=1.0,
        opening_silence_in_seconds=1.0)
    with open(path_to_tmp_file) as in_file:
        result = in_file.read()
        assert result == expected
Ejemplo n.º 11
0
def test_create_midi_from_fragment(path_to_tmp_file: str, fragment: Fragment,
                                   note_number: int,
                                   expected: dict[str, float]) -> None:
    """Test `create_midi_from_fragment` function."""
    fragment = override_calculated_attributes(fragment)
    create_midi_from_fragment(fragment,
                              path_to_tmp_file,
                              beat_in_seconds=0.5,
                              instruments={k: 0
                                           for k in fragment.line_ids},
                              velocity=100,
                              opening_silence_in_seconds=1,
                              trailing_silence_in_seconds=1)
    midi_data = pretty_midi.PrettyMIDI(path_to_tmp_file)
    instrument = midi_data.instruments[0]
    midi_note = instrument.notes[note_number]
    result = {
        'pitch': midi_note.pitch,
        'start': midi_note.start,
        'end': midi_note.end
    }
    assert result == expected
Ejemplo n.º 12
0
def test_evaluate_absence_of_doubled_pitch_classes(fragment: Fragment,
                                                   expected: float) -> None:
    """Test `evaluate_absence_of_doubled_pitch_classes` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_absence_of_doubled_pitch_classes(fragment)
    assert result == expected
Ejemplo n.º 13
0
def test_evaluate_absence_of_voice_crossing(fragment: Fragment,
                                            expected: float) -> None:
    """Test `evaluate_absence_of_voice_crossing` function."""
    fragment = override_calculated_attributes(fragment)
    result = evaluate_absence_of_voice_crossing(fragment)
    assert result == expected