当前位置: 首页>>代码示例>>Python>>正文


Python Song.length方法代码示例

本文整理汇总了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"))
开发者ID:Martin95056,项目名称:MusicLibrary,代码行数:27,代码来源:test_song.py

示例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!")
开发者ID:fuchssarahe,项目名称:guiter_practice,代码行数:48,代码来源:player.py

示例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")
开发者ID:ruzhaa,项目名称:Programming101-Python,代码行数:21,代码来源:test_song.py

示例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)
开发者ID:presian,项目名称:HackBulgaria,代码行数:40,代码来源:song_test.py

示例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))
开发者ID:bgvladedivac,项目名称:Projects,代码行数:7,代码来源:tests.py


注:本文中的song.Song.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。