def test__hash__(self): assert {Beat(Beat(1, 2), 4), Beat(Beat(1, 2), 4), Beat(Beat(1, 2), 8)} == { Beat(Beat(1, 2), 4), Beat(Beat(1, 2), 8), }
def test_invalid_direction_raises_value_error(self): with pytest.raises(ValueError): Flag(Beat(1, 8), 0, self.staff) with pytest.raises(ValueError): Flag(Beat(1, 8), 2, self.staff) with pytest.raises(ValueError): Flag(Beat(1, 8), -2, self.staff)
def test_furthest_notehead_with_one_note(self): pitches = ["b'"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4)) assert chord.furthest_notehead.pitch == Pitch("b'") pitches = ["f'''"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4)) assert chord.furthest_notehead.pitch == Pitch("f'''") pitches = ["c,,,,"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4)) assert chord.furthest_notehead.pitch == Pitch("c,,,,")
def test_raises_no_flag_needed_error(self): # Test valid durations Flag(Beat(1, 16), 1, self.staff) Flag(Beat(1, 8), 1, self.staff) # Test invalid durations with pytest.raises(NoFlagNeededError): Flag(Beat(1, 4), 1, self.staff) with pytest.raises(NoFlagNeededError): Flag(Beat(1, 2), 1, self.staff) with pytest.raises(NoFlagNeededError): Flag(Beat(1, 1), 1, self.staff)
def test_vertical_offset_needed(self): self.assertEqual( Flag.vertical_offset_needed(Beat(1, 4), self.staff.unit), self.staff.unit(0)) self.assertEqual( Flag.vertical_offset_needed(Beat(1, 8), self.staff.unit), self.staff.unit(1)) self.assertEqual( Flag.vertical_offset_needed(Beat(1, 16), self.staff.unit), self.staff.unit(1), )
def test_staff_position_with_accidentals(self): self.assertEqual( Notehead(Mm(10), "cf'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(5), ) self.assertEqual( Notehead(Mm(10), "cn'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(5), ) self.assertEqual( Notehead(Mm(10), "cs'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(5), )
def test_stem_direction_override(self): pitches = ["b'"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4), -1) assert chord.stem_direction == -1 # Setting stem_direction = None should revert to default 1 chord.stem_direction = None assert chord.stem_direction == 1
def test_staff_position_high_octaves(self): self.assertEqual( Notehead(Mm(10), "c''", Beat(1, 4), self.staff).staff_pos, self.staff.unit(1.5), ) self.assertEqual( Notehead(Mm(10), "c'''", Beat(1, 4), self.staff).staff_pos, self.staff.unit(-2), ) self.assertEqual( Notehead(Mm(10), "c''''", Beat(1, 4), self.staff).staff_pos, self.staff.unit(-5.5), ) self.assertEqual( Notehead(Mm(10), "c'''''", Beat(1, 4), self.staff).staff_pos, self.staff.unit(-9), )
def test_staff_position_low_octaves(self): self.assertEqual( Notehead(Mm(10), "c", Beat(1, 4), self.staff).staff_pos, self.staff.unit(8.5), ) self.assertEqual( Notehead(Mm(10), "c,", Beat(1, 4), self.staff).staff_pos, self.staff.unit(12), ) self.assertEqual( Notehead(Mm(10), "c,,", Beat(1, 4), self.staff).staff_pos, self.staff.unit(15.5), ) self.assertEqual( Notehead(Mm(10), "c,,,", Beat(1, 4), self.staff).staff_pos, self.staff.unit(19), )
def test_ledger_line_positions_with_different_clef(self): Clef(self.staff, Mm(10), "bass") pitches = ["e,", "d", "e'"] chord = Chordrest(Mm(15), self.staff, pitches, Beat(1, 4)) assert chord.ledger_line_positions == [ self.staff.unit(5), self.staff.unit(-2), self.staff.unit(-1), ]
def test_ledger_line_positions(self): pitches = ["c'", "b'", "f'''"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(1, 4)) assert chord.ledger_line_positions == [ self.staff.unit(5), self.staff.unit(-3), self.staff.unit(-2), self.staff.unit(-1), ]
def test_rhythm_dot_positions_with_rest(self): chord = Chordrest(Mm(1), self.staff, None, Beat(7, 16)) dots = list(chord.rhythm_dot_positions) dots.sort(key=lambda d: d.x) assert_almost_equal( dots[0], Point(self.staff.unit(1.326), self.staff.unit(1.5)) ) assert_almost_equal( dots[1], Point(self.staff.unit(1.826), self.staff.unit(1.5)) )
def test_rhythm_dot_positions_with_noteheads(self): pitches = ["e,", "d", "e'''"] chord = Chordrest(Mm(1), self.staff, pitches, Beat(7, 16)) dots = list(chord.rhythm_dot_positions) dots.sort(key=lambda d: d.x) dots.sort(key=lambda d: d.y) assert_almost_equal( dots[0], Point(self.staff.unit(1.43), self.staff.unit(-3.5)) ) assert_almost_equal( dots[1], Point(self.staff.unit(1.93), self.staff.unit(-3.5)) ) assert_almost_equal(dots[2], Point(self.staff.unit(1.43), self.staff.unit(7.5))) assert_almost_equal(dots[3], Point(self.staff.unit(1.93), self.staff.unit(7.5))) assert_almost_equal( dots[4], Point(self.staff.unit(1.43), self.staff.unit(10.5)) ) assert_almost_equal( dots[5], Point(self.staff.unit(1.93), self.staff.unit(10.5)) )
def test_staff_position_with_all_letter_names(self): self.assertEqual( Notehead(Mm(10), "d'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(4.5), ) self.assertEqual( Notehead(Mm(10), "e'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(4) ) self.assertEqual( Notehead(Mm(10), "f'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(3.5), ) self.assertEqual( Notehead(Mm(10), "g'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(3) ) self.assertEqual( Notehead(Mm(10), "a'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(2.5), ) self.assertEqual( Notehead(Mm(10), "b'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(2) )
def test__lt__with__nested(self): assert Beat(Beat(1, 2), 4) < Beat(Beat(1, 1), 4)
def test_staff_position_middle_c_treble(self): self.assertEqual( Notehead(Mm(10), "c'", Beat(1, 4), self.staff).staff_pos, self.staff.unit(5) )
def test__sub__with_nested(self): assert Beat(Beat(1, 2), 4) - Beat(1, 16) == Beat(1, 16)
def test__sub__with_non_nested(self): assert Beat(3, 4) - Beat(1, 4) == Beat(1, 2)
def test__add__with_nested(self): assert Beat(Beat(1, 2), 4) + Beat(1, 4) == Beat(3, 8)
def test_init_from_numerator_denominator(self): dur = Beat(1, 4) assert dur.numerator == 1 assert dur.denominator == 4
def test__eq__with_nested(self): assert Beat(Beat(1, 2), 4) == Beat(Beat(1, 2), 4)
def tests__lte__with_nested(self): assert Beat(1, 4) <= Beat(Beat(1, 1), 1) assert Beat(1, 4) <= Beat(Beat(1, 2), 2)
def test__ne__with_nested(self): assert Beat(Beat(1, 2), 4) != Beat(Beat(2, 4), 8)
def test__gt__with_non_nested(self): assert Beat(1, 4) > Beat(1, 8)
def test__lt__with_non_nested(self): assert Beat(1, 4) < Beat(1, 2)
def tests__gte__with_non_nested(self): assert Beat(1, 4) >= Beat(1, 8) assert Beat(1, 4) >= Beat(1, 4)
def tests__lte__with_non_nested(self): assert Beat(1, 4) <= Beat(1, 2) assert Beat(1, 4) <= Beat(1, 4)
def tests__gte__with_nested(self): assert Beat(1, 4) >= Beat(Beat(1, 3), 8) assert Beat(1, 4) >= Beat(Beat(1, 1), 4)
def test_staff_position_on_later_flowable_line(self): self.assertEqual( Notehead(Mm(1000), "c", Beat(1, 4), self.staff).staff_pos, self.staff.unit(8.5), )
def test__gt__with_nested(self): assert Beat(Beat(1, 1), 4) > Beat(Beat(1, 2), 4)