def test_single_notes(self): for string, fret in it.product(range(5), range(19)): with self.subTest(i=(string, fret)): s = tab.Shape([(string, fret)]) self.assertEqual(s.list_tuples(), [(string, fret)]) temp = [fret if string == i else None for i in range(6)] self.assertEqual(s.list_frets(), temp)
def test_whole_note(self): bar = tab.Bar() bar.add_shape(tab.Shape((0, 0)), 1) try: self.assertEqual(len(bar), 8 + 2) except AssertionError as e: print(f'Dynamic whole notes:\n{bar}') raise e
def test_sixteenth_note(self): bar = tab.Bar() for i in range(16): bar.add_shape(tab.Shape((0, 0)), 1 / 16) try: self.assertEqual(len(bar), 64 + 2) except AssertionError as e: print(f'Dynamic sixteenth notes:\n{bar}') raise e
def test_half_note(self): bar = tab.Bar() for i in range(2): bar.add_shape(tab.Shape((0, 0)), 1 / 2) try: self.assertEqual(len(bar), 8 + 2) except AssertionError as e: print(f'Dynamic half notes:\n{bar}') raise e
def test_quarter_note(self): bar = tab.Bar() for i in range(4): bar.add_shape(tab.Shape((0, 0)), 1 / 4) try: self.assertEqual(len(bar), 16 + 2) except AssertionError as e: print(f'Dynamic quarter notes:\n{bar}') raise e
def test_eighth_note(self): bar = tab.Bar() for i in range(8): bar.add_shape(tab.Shape((0, 0)), 1 / 8) try: self.assertEqual(len(bar), 32 + 2) except AssertionError as e: print(f'Dynamic eighth notes:\n{bar}') raise e
def test_length_limit(self): ''' Ensure notes added beyond 1 bars-length are ignored''' bar_0 = tab.Bar(width=32) bar_0.add_shape(tab.Shape((0, 0)), 1) for line in bar_0.lines: self.assertEqual(len(line), 34) bar_1 = tab.Bar(width=32) bar_1.add_shape(tab.Shape((0, 0)), 1) bar_1.add_shape(tab.Shape((0, 0)), 1) for line in bar_1.lines: self.assertEqual(len(line), 34) bar_4 = tab.Bar(width=32) for i in range(5): bar_4.add_shape(tab.Shape((0, 0)), 1 / 4) for line in bar_4.lines: self.assertEqual(len(line), 34) bar_16 = tab.Bar(width=32) for i in range(17): bar_16.add_shape(tab.Shape((0, 0)), 1 / 16) for line in bar_16.lines: self.assertEqual(len(line), 66)
def test_single_notes(self): arr = tab.Arrangement() for note in [(0, 0), (0, 2), (0, 4), (1, 0), (1, 2), (1, 4), (2, 1), (2, 2)]: arr.add_shape(tab.Shape(note), 1 / 8) # tabs = arr.transcribe() expected = ('|--------------------------------|\n' '|--------------------------------|\n' '|--------------------------------|\n' '|------------------------1---2---|\n' '|------------0---2---4-----------|\n' '|0---2---4-----------------------|\n\n') try: self.assertEqual(arr, expected) except AssertionError as e: print(f'E major scale, one bar:\n{arr}') raise e
def test_E_major_scale(self): ''' Add eighth Notes manually, one by one ''' bar = tab.Bar() for note in ((0, 0), (0, 2), (0, 4), (1, 0), (1, 2), (1, 4), (2, 1), (2, 2)): bar.add_shape(tab.Shape(note), 1 / 8) try: self.assertEqual( bar, '|--------------------------------|\n' '|--------------------------------|\n' '|--------------------------------|\n' '|------------------------1---2---|\n' '|------------0---2---4-----------|\n' '|0---2---4-----------------------|\n') except AssertionError as e: print(f'Static E major, one bar:\n{bar}') raise e
def test_chords(self): arr = tab.Arrangement() sotw = [([(0, 0), (1, 2), (2, 2)], 1 / 4), ([(0, 3), (1, 5), (2, 5)], 1 / 4), ([(0, 5), (1, 7), (2, 7)], 3 / 8), ([(0, 0), (1, 2), (2, 2)], 1 / 4), ([(0, 3), (1, 5), (2, 5)], 1 / 4), ([(0, 7), (1, 9), (2, 9)], 1 / 8), ([(0, 5), (1, 7), (2, 7)], 1 / 2)] for note in sotw: frets, duration = note arr.add_shape(tab.Shape(frets), duration) # tabs = arr.transcribe() try: self.assertEqual(arr, smoke_on_the_water) except AssertionError as e: print(f'Smoke on the Water, two bars, manual:\n{arr}') raise e
def test_mixed_notes(self): ''' Sixth notes? Tab() will need to handle 3/4 time as well ''' arr = tab.Arrangement() bb1 = [([(0, 3), (4, 0)], 1 / 6), ([(3, 0)], 1 / 6), ([(1, 0), (4, 1)], 1 / 6), ([(3, 0)], 1 / 6), ([(1, 2), (4, 3)], 1 / 6), ([(3, 0)], 1 / 6)] bb2 = [([(1, 10), (4, 12)], 1 / 4), ([(3, 0)], 1 / 8), ([(4, 12)], 1 / 8), ([(1, 10)], 1 / 8), ([(4, 12)], 1 / 8), ([(3, 0)], 1 / 4)] for note in bb1 + bb2: frets, duration = note arr.add_shape(tab.Shape(frets), duration) # tabs = arr.transcribe() try: self.assertEqual(arr, blackbird) except AssertionError as e: print(f'Blackbird, two bars, manual:\n{arr}') raise e
def test_open_d_shape(self): lst = [None, 0, 0, 2, 3, 2] self.assertEqual(tab.Shape(open_d).list_frets(), lst) self.assertEqual(tab.Shape(lst).list_tuples(), open_d)
def test_all_open(self): s = tab.Shape() for i in range(6): s += tab.Shape((i, 0)) self.assertEqual(s, tab.Shape([0, 0, 0, 0, 0, 0]))
def test_null_shape(self): self.assertEqual(tab.Shape() + tab.Shape(), tab.Shape())
def test_barre_f_shape(self): lst = [1, 3, 3, 2, 1, 1] self.assertEqual(tab.Shape(barre_f).list_frets(), lst) self.assertEqual(tab.Shape(lst).list_tuples(), barre_f)
def test_null_shape(self): s = tab.Shape() self.assertEqual(s.list_frets(), [None] * 6) self.assertEqual(s.list_tuples(), [])
def test_open_e_shape(self): lst = [0, 2, 2, 1, 0, 0] self.assertEqual(tab.Shape(open_e).list_frets(), lst) self.assertEqual(tab.Shape(lst).list_tuples(), open_e)
def test_open_g_shape(self): lst = [3, 2, 0, 0, 0, 3] self.assertEqual(tab.Shape(open_g).list_frets(), lst) self.assertEqual(tab.Shape(lst).list_tuples(), open_g)
def test_barre_b_shape(self): lst = [2, 2, 4, 4, 4, 2] self.assertEqual(tab.Shape(barre_b).list_frets(), lst) self.assertEqual(tab.Shape(lst).list_tuples(), barre_b)
def test_low_E(self): song = music.Song() song.add('E3') g = player.Guitarist(song) expected = tab.Bar(notes=[(tab.Shape((0, 0)), 1 / 4)]) self.assertEqual(g.arr, str(expected) + '\n')