def test_compareSongs_y_better(self): zs = ZipfSong() zs.addSong(Song(0, 10, "x")) self.assertEquals(zs.compareSongs( Song(0, 10, "x"), Song(1, 7, "y") ), -1)
def test_compareSongs_same_quality_y_first(self): zs = ZipfSong() zs.addSong(Song(0, 10, "y")) self.assertEquals(zs.compareSongs( Song(1, 5, "x"), Song(0, 10, "y") ), -1)
def test_compareSongs_x_better(self): zs = ZipfSong() zs.addSong(Song(0, 12, "x")) self.assertEquals(zs.compareSongs( Song(0, 12, "x"), Song(1, 5, "y") ), 1)
def test_case_2(): input_str = """15 3 197812 re_hash 78906 5_4 189518 tomorrow_comes_today 39453 new_genious 210492 clint_eastwood 26302 man_research 22544 punk 19727 sound_check 17535 double_bass 18782 rock_the_house 198189 19_2000 13151 latin_simone 12139 starshine 11272 slow_country 10521 m1_a1 """ expected = [Song(11, "19_2000", 198189), Song(5, "clint_eastwood", 210492), Song(3, "tomorrow_comes_today", 189518)] N_TRACKS_TO_SELECT = Parser.parse_input_first_line(input_str.split("\n")[0])[1] TRACKLIST = input_str.split("\n")[1:] TRACKLIST = map(str.strip, TRACKLIST) TRACKLIST = [track for track in TRACKLIST if track != ''] assert ZipfSong.extract_top_k_songs(N_TRACKS_TO_SELECT, TRACKLIST) == expected
def test_topQualitySongs_first_song_no_plays(self): zs = ZipfSong() zs.addSong(Song(0, 0, "Foo")) zs.addSong(Song(1, 10, "Bar")) zs.addSong(Song(2, 5, "Baz")) self.assertEquals(zs.topQualitySongs(3), [ Song(1, 10, "Bar"), Song(2, 5, "Baz"), Song(0, 0, "Foo"), ])
def test_case_1(): input_str = """4 2 30 one 30 two 15 three 25 four """ expected = [Song(4, "four", 25), Song(2, "two", 30)] N_TRACKS_TO_SELECT = Parser.parse_input_first_line(input_str.split("\n")[0])[1] TRACKLIST = input_str.split("\n")[1:] TRACKLIST = map(str.strip, TRACKLIST) TRACKLIST = [track for track in TRACKLIST if track != ''] assert ZipfSong.extract_top_k_songs(N_TRACKS_TO_SELECT, TRACKLIST) == expected
def test_topQualitySongs_three_songs(self): zs = ZipfSong() zs.addSong(Song(0, 10, "Foo")) zs.addSong(Song(1, 7, "Bar")) zs.addSong(Song(2, 5, "Baz")) self.assertEquals(zs.topQualitySongs(3), [ Song(2, 5, "Baz"), Song(1, 7, "Bar"), Song(0, 10, "Foo"), ])
def test_case_4(): input_str = """6 3 60 one 30 two 20 three 15 four 120 five 100 six""" expected = [Song(5, "five", 120), Song(6, "six", 100), Song(1, "one", 60)] N_TRACKS_TO_SELECT = Parser.parse_input_first_line(input_str.split("\n")[0])[1] TRACKLIST = input_str.split("\n")[1:] TRACKLIST = map(str.strip, TRACKLIST) TRACKLIST = [track for track in TRACKLIST if track != ''] assert ZipfSong.extract_top_k_songs(N_TRACKS_TO_SELECT, TRACKLIST) == expected
def test_topQualitySongs_no_songs_added(self): zs = ZipfSong() self.assertEquals(zs.topQualitySongs(3), [])
def test_topQualitySongs_one_song(self): zs = ZipfSong() zs.addSong(Song(0, 1, "Hi")) self.assertEquals(zs.topQualitySongs(1), [Song(0, 1, "Hi")])
def test_topQualitySongs_no_songs_requested(self): zs = ZipfSong() zs.addSong(Song(0, 0, "")) self.assertEquals(zs.topQualitySongs(0), [])