Ejemplo n.º 1
0
def test_NamedInterval_01(pitch_a, pitch_b, name):
    pitch_a = NamedPitch(pitch_a)
    pitch_b = NamedPitch(pitch_b)
    interval = NamedInterval.from_pitch_carriers(pitch_a, pitch_b)
    assert str(interval) == name
    assert pitch_a.transpose(interval) == pitch_b
    assert pitch_b.transpose(-interval) == pitch_a
Ejemplo n.º 2
0
def test_init(input_, semitones, name):
    class_ = NamedInterval
    if isinstance(semitones, type) and issubclass(semitones, Exception):
        with pytest.raises(semitones):
            class_(input_)
        return
    instance = class_(input_)
    assert float(instance) == semitones
    assert instance.name == name
    NamedInterval(instance)
    NumberedInterval(instance)
    NamedIntervalClass(instance)
    NumberedIntervalClass(instance)
    if isinstance(input_, str):
        group_dict = constants._interval_name_abbreviation_regex.match(
            input_).groupdict()
        inflected_up = class_("{}{}{}{}".format(
            group_dict["direction"] or "",
            group_dict["quality"],
            "+",
            group_dict["number"],
        ))
        inflected_down = class_("{}{}{}{}".format(
            group_dict["direction"] or "",
            group_dict["quality"],
            "~",
            group_dict["number"],
        ))
        if (mathtools.sign(float(instance))
                == instance.direction_number) and abs(instance.number) != 1:
            direction = mathtools.sign(float(instance))
            assert (float(inflected_up) == (abs(float(instance)) + 0.5) *
                    direction)
            assert (float(inflected_down) == (abs(float(instance)) - 0.5) *
                    direction)
Ejemplo n.º 3
0
def test_init(input_, semitones, name):
    class_ = NamedIntervalClass
    if isinstance(semitones, type) and issubclass(semitones, Exception):
        with pytest.raises(semitones):
            class_(input_)
        return
    instance = class_(input_)
    assert float(instance) == semitones
    assert instance.name == name
    NamedInterval(instance)
    NamedIntervalClass(instance)
    NumberedInterval(instance)
    NumberedIntervalClass(instance)