本文整理汇总了Python中song.Song.length方法的典型用法代码示例。如果您正苦于以下问题:Python Song.length方法的具体用法?Python Song.length怎么用?Python Song.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类song.Song
的用法示例。
在下文中一共展示了Song.length方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import length [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.song = Song("Bout Me", "Wiz Khalifa", "Cabin Fever", "3:30")
def test_song_str(self):
self.assertEqual(self.song.__str__(), "Wiz Khalifa - Bout Me from Cabin Fever - 3:30")
def test_song_set_length(self):
self.assertEqual(self.song.set_length(), time(0, 3, 30))
def test_song_length_3(self):
song3 = Song("Bout Me", "Wiz Khalifa", "Cabin Fever", "1:3:30")
self.assertEqual(song3.set_length(), time(1, 3, 30))
def test_song_length_seconds(self):
self.assertEqual(self.song.length(seconds=True), 3*60 + 30)
def test_song_length_minutes(self):
self.assertEqual(self.song.length(minutes=True), 3)
def test_song_length_hours(self):
self.assertEqual(self.song.length(hours=True), 0)
def test_song_length_song(self):
self.assertEqual(self.song.length(), self.song.set_length().strftime("%h:%M:%S"))
示例2: Player
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import length [as 别名]
class Player(object):
"""docstring for Player"""
def __init__(self):
self.chord_count = 0
def play(self):
print("Hooray! I'm so proud of you for practicing!")
self.select_difficulty()
self.start_time = time()
self.play_new_song()
answer = self.play_again_choice()
while answer != 'c':
if answer == 'a':
self.replay()
elif answer == 'b':
self.select_difficulty()
self.play_new_song()
elif answer == 'c':
self.end_practice()
answer = self.play_again_choice()
self.end_practice()
def select_difficulty(self):
answer = raw_input('Please select a difficulty: hard(h) or easy(e): ')
while answer not in ['h', 'e']:
answer = raw_input("I'm afraid that wasn't quite right - try tapping 'h' or 'e' again! Then hit enter: ")
self.difficulty = 'hard' if answer == 'h' else 'easy'
def play_new_song(self):
self.current_song = Song(self.difficulty)
self.current_song.render()
self.chord_count += self.current_song.length()
def replay(self):
self.current_song.render()
self.chord_count += self.current_song.length()
def play_again_choice(self):
answer = raw_input('Would you like to try that song again (a), play a new song (b), or are you done for the day (c)? ')
while answer not in ['a', 'b', 'c']:
answer = raw_input("I'm afraid that wasn't quite right - try tapping a, b, or c again! Then hit enter: ")
return answer
def end_practice(self):
self.end_time = time()
print("Great job practiciting! You played for " + str((self.end_time - self.start_time)/60) + " minutes and played " + str(self.chord_count) + " chords!")
示例3: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import length [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
pass
def test_length_to_sec(self):
self.song = Song("RAndom", "mr.Random", "the best of Random", "1:30")
self.assertEqual(self.song.length(seconds=True), 90)
def test_length_to_min(self):
self.song = Song("RAndom", "mr.Random", "the best of Random", "41:30")
self.assertEqual(self.song.length(minutes=True), 41)
def test_length_to_hour(self):
self.song = Song("RAndom", "mr.Random", "the best of Random", "1:59:60")
self.assertEqual(self.song.length(hours=True), 2)
def test_length_string(self):
self.song = Song("RAndom", "mr.Random", "the best of Random", "1:30")
self.assertEquals(self.song.length(), "1:30")
示例4: TestSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import length [as 别名]
class TestSong(unittest.TestCase):
def setUp(self):
self.song = Song(title="Tra-la-la", artist="Pesho", album="Tarara", length="3:33")
self.second_song = Song(title="Tra-la-la", artist="Pesho", album="Tarara", length="3:33")
def test_getTitle_method(self):
self.assertEqual("Tra-la-la", self.song.getTitle())
def test_getArtist(self):
self.assertEqual("Pesho", self.song.getArtist())
def test_getAlbum(self):
self.assertEqual("Tarara", self.song.getAlbum())
def test_getLength(self):
self.assertEqual("3:33", self.song.getLength())
def test_str_(self):
self.assertEqual("Pesho - Tra-la-la from Tarara - 3:33", str(self.song))
def test_eq_(self):
self.assertTrue(self.song == self.second_song)
def test_hash_(self):
self.assertTrue(type(hash(self.song)) == int)
def test_length_without_arguments(self):
self.assertEqual(self.song.length(), "3:33")
def test_length_with_seconds(self):
self.assertEqual(self.song.length(seconds=True), 213)
def test_length_with_minutes(self):
self.assertEqual(self.song.length(minutes=True), 3)
def test_length_with_hours(self):
self.assertEqual(self.song.length(hours=True), 0)
示例5: test_get_length
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import length [as 别名]
def test_get_length(self):
"""Test the length of the song"""
s = Song("Fields of Gold", "Sting", "Greatest Hits", "3:44")
self.assertEqual(224, s.length(seconds=True))
self.assertEqual(3, s.length(minutes=True))