core/playlist: Add dynamic playlist generation unit test
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
73992ed912
commit
7a32fdb982
|
@ -37,7 +37,8 @@ public:
|
|||
queue_add(this, track);
|
||||
if ((name == "Most Played") && (track->tr_count > avg))
|
||||
queue_add(this, track);
|
||||
if ((name == "Least Played") && (track->tr_count < avg))
|
||||
if ((name == "Least Played") && (track->tr_count < avg) &&
|
||||
(track->tr_count > 0))
|
||||
queue_add(this, track);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,41 +109,42 @@ static void test_remove()
|
|||
test_equal(playlist_has("Banned", track), false);
|
||||
test_equal(queue_size(q), 0);
|
||||
test_equal(queue_size(c), 13);
|
||||
|
||||
playlist_deinit();
|
||||
collection_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
}
|
||||
|
||||
static void test_queue()
|
||||
static void test_dynamic()
|
||||
{
|
||||
queue *q = playlist_get_queue();
|
||||
struct queue *q = playlist_get_queue();
|
||||
struct db_entry *track, *next;
|
||||
unsigned int i, average = 0;
|
||||
|
||||
test_cp_data_dir();
|
||||
filter_init();
|
||||
tags_init();
|
||||
collection_init(NULL);
|
||||
playlist_init(NULL);
|
||||
|
||||
playlist_select(NULL);
|
||||
playlist_select("Banned");
|
||||
test_equal(queue_size(q), (unsigned)4);
|
||||
|
||||
playlist_select("Favorites");
|
||||
test_equal(queue_size(q), (unsigned)8);
|
||||
/* Set play count to (track_number - 1) (average = 6) */
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
TRACK(track)->tr_count = TRACK(track)->tr_track - 1;
|
||||
average += TRACK(track)->tr_count;
|
||||
}
|
||||
average /= track_db_get()->db_size;
|
||||
|
||||
/* Only one unplayed track (tr_track == 1) */
|
||||
playlist_select("Unplayed");
|
||||
test_equal(queue_size(q), (unsigned)3);
|
||||
|
||||
playlist_select("Most Played");
|
||||
test_equal(queue_size(q), (unsigned)10);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(queue_at(q, 0)->tr_track, 1);
|
||||
test_equal(queue_at(q, 0)->tr_count, 0);
|
||||
|
||||
/* Five tracks have tr_count < average && tr_count > 0 */
|
||||
playlist_select("Least Played");
|
||||
test_equal(queue_size(q), (unsigned)12);
|
||||
test_equal(queue_size(q), 5);
|
||||
for (i = 0; i < queue_size(q); i++) {
|
||||
test_loop_equal(queue_at(q, i)->tr_track, i + 2, i);
|
||||
test_loop_equal(queue_at(q, i)->tr_count, i + 1, i);
|
||||
} test_loop_passed();
|
||||
|
||||
playlist_select("No Such Playlist");
|
||||
test_equal(queue_size(q), (unsigned)12);
|
||||
/* Six tracks have tr_count > average */
|
||||
playlist_select("Most Played");
|
||||
test_equal(queue_size(q), 6);
|
||||
for (i = 0; i < queue_size(q); i++) {
|
||||
test_loop_equal(queue_at(q, i)->tr_track, i + 8, i);
|
||||
test_loop_equal(queue_at(q, i)->tr_count, i + 7, i);
|
||||
} test_loop_passed();
|
||||
}
|
||||
|
||||
static void test_deinit()
|
||||
|
@ -163,6 +164,6 @@ DECLARE_UNIT_TESTS(
|
|||
UNIT_TEST("Playlist Initialization", test_init),
|
||||
UNIT_TEST("Playlist Add Track", test_add),
|
||||
UNIT_TEST("Playlist Remove Track", test_remove),
|
||||
UNIT_TEST("Playlist Queue", test_queue),
|
||||
UNIT_TEST("Playlist Dynamic Generation", test_dynamic),
|
||||
UNIT_TEST("Playlist Deinit", test_deinit),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue