def notes(): return [ (Note(A, NATURAL), "A", 0), (Note(G, FLAT), "G♭", 9), (Note(A, SHARP), "A♯", 1), (Note(B, FLAT), "B♭", 1), ]
def test_letter_to_str(): assert Tone(Note(A, FLAT), 3).to_str() == "A♭3" assert Tone(Note(G, SHARP), 3).to_str() == "G♯3" assert Tone(Note(A, FLAT), 3).to_str() == "A♭3" assert Tone(Note(A, FLAT), 3).to_str() == "A♭3"
def test_from_int(): assert tone_from_int(0) == Tone(Note(A, NATURAL), 0) assert tone_from_int(-1) == Tone(Note(G, SHARP), -1) assert tone_from_int(120) == Tone(Note(A, NATURAL), 10)
def test_from_str(): assert tone_from_str("G#10") == Tone(Note(G, SHARP), 10) assert tone_from_str("Ab0") == Tone(Note(A, FLAT), 0)
def test_letter_to_int(): assert Tone(Note(A, SHARP), 3).to_int() == 37 assert Tone(Note(G, FLAT), 2).to_int() == 33 assert Tone(Note(B, FLAT), 10).to_int() == 121
def test___eq__(): assert Note(A, SHARP) == Note(B, FLAT) assert Note(B, SHARP) == Note(C, NATURAL) assert Note(C, SHARP) == Note(D, FLAT) assert Note(D, SHARP) == Note(E, FLAT) assert Note(E, SHARP) == Note(F, NATURAL) assert Note(F, SHARP) == Note(G, FLAT) assert Note(G, SHARP) == Note(A, FLAT)
def test___add__(): assert Note(A, NATURAL) + MINOR_SECOND == Note(A, SHARP) assert Note(A, NATURAL) + MAJOR_SEVENTH == Note(A, FLAT) assert Note(G, NATURAL) + PERFECT_FOURTH == Note(C, NATURAL) assert Note(B, NATURAL) + TRITONE == Note(F, NATURAL) assert Note(D, FLAT) + PERFECT_OCTAVE == Note(D, FLAT)
def test___sub__(): assert Note(A, NATURAL) - Note(A, FLAT) == MINOR_SECOND assert Note(A, NATURAL) - Note(A, SHARP) == MAJOR_SEVENTH assert Note(G, NATURAL) - Note(C, NATURAL) == PERFECT_FIFTH assert Note(B, NATURAL) - Note(F, NATURAL) == TRITONE assert Note(D, FLAT) - Note(C, SHARP) == PERFECT_UNISON assert Note(E, SHARP) - Note(F, NATURAL) == PERFECT_UNISON assert Note(F, NATURAL) - Note(E, SHARP) == PERFECT_UNISON
def test_from_str(notes: List[Tuple[Note, str, int]]): for note, symbol, _ in notes: assert note_from_str(symbol) == note assert note_from_str("B#") == Note(B, SHARP) assert note_from_str("Fb") == Note(F, FLAT)