1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
from collections import defaultdict
from quodlibet.formats import AudioFile
from quodlibet.order import OrderInOrder
from quodlibet.order.reorder import OrderWeighted, OrderShuffle
from quodlibet.order.repeat import OneSong
from quodlibet.qltk.songmodel import PlaylistModel
from tests import TestCase
r0 = AudioFile({'~#rating': 0})
r1 = AudioFile({'~#rating': 0.33})
r2 = AudioFile({'~#rating': 0.66})
r3 = AudioFile({'~#rating': 1.0})
class TOrderWeighted(TestCase):
def test_weighted(self):
pl = PlaylistModel()
pl.set([r3, r1, r2, r0])
order = OrderWeighted()
scores = defaultdict(int)
for i in range(500):
order.reset(pl)
cur = pl.current_iter
for j in range(3, -1, -1):
cur = order.next_explicit(pl, cur)
scores[pl[cur][0]] += j
self.failUnless(scores[r1] > scores[r0])
self.failUnless(scores[r2] > scores[r1])
self.failUnless(scores[r3] > scores[r2])
class TOrderShuffle(TestCase):
def test_remaining(self):
order = OrderShuffle()
pl = PlaylistModel()
songs = [r3, r1, r2, r0]
pl.set(songs)
cur = pl.current_iter
for i in range(4, 0, -1):
cur = order.next_explicit(pl, cur)
self.failUnlessEqual(len(order.remaining(pl)), i)
# The playlist should reset after the last song
cur = order.next_explicit(pl, cur)
self.failUnlessEqual(len(order.remaining(pl)), len(songs))
class TOrderOneSong(TestCase):
def test_remaining(self):
order = OneSong(OrderInOrder())
pl = PlaylistModel(OrderInOrder)
pl.set([r0, r1])
for i in range(2):
self.failUnlessEqual(order.next(pl, pl.current_iter), None)
|