idle: Update test for new system
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
70067a89cb
commit
1f19987c53
|
@ -14,8 +14,8 @@ for arg in sys.argv:
|
|||
|
||||
src = SConscript("src/Sconscript")
|
||||
|
||||
tests = [ "version" , "file", "database", "index", "filter" ]
|
||||
# "filter", "idle", "tag_db",
|
||||
tests = [ "version" , "file", "database", "index", "filter", "idle" ]
|
||||
# "tag_db",
|
||||
# "queue" ]
|
||||
#scripts = [ "playlist", "library", "deck", "audio", "gui" ]
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Copyright 2014 (c) Anna Schumaker
|
||||
|
||||
. $(dirname $0)/_functions
|
||||
|
||||
new_test "Idle Queue Test"
|
||||
src/idle.run
|
|
@ -4,57 +4,54 @@
|
|||
*/
|
||||
|
||||
#include <idle.h>
|
||||
#include <print.h>
|
||||
#include "test.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sstream>
|
||||
|
||||
static unsigned int test_num = 0;
|
||||
static unsigned int cur = -1;
|
||||
static float cur = -1;
|
||||
|
||||
void test_results(bool success, unsigned int line)
|
||||
{
|
||||
print(" %u: ", test_num);
|
||||
if (success)
|
||||
print("Success!\n");
|
||||
else {
|
||||
print("FAILED (%u) =(", line);
|
||||
exit(1);
|
||||
}
|
||||
test_num++;
|
||||
}
|
||||
|
||||
void test_progress(unsigned int expected, unsigned int multiplier,
|
||||
unsigned int line)
|
||||
{
|
||||
unsigned int prog = (idle :: get_progress() * multiplier);
|
||||
test_results(prog == expected, line);
|
||||
}
|
||||
|
||||
void inc_cur(unsigned int &expected)
|
||||
static void inc_cur(float &expected)
|
||||
{
|
||||
cur++;
|
||||
test_results(cur == expected, __LINE__);
|
||||
check_equal(cur, expected);
|
||||
}
|
||||
|
||||
static void test_idle_queue(float n)
|
||||
{
|
||||
test_equal(idle :: get_progress(), (float)1.0);
|
||||
test_equal(idle :: run_task(), false);
|
||||
|
||||
for (float i = 0; i < n; i++)
|
||||
idle :: schedule(inc_cur, i);
|
||||
test_equal(idle :: get_progress(), (float)0.0);
|
||||
|
||||
test :: begin();
|
||||
for (float i = 0; i < (n - 1); i++) {
|
||||
check_equal(idle :: run_task(), true);
|
||||
check_equal(idle :: get_progress(), (i + 1) / n);
|
||||
}
|
||||
test :: success();
|
||||
|
||||
test_equal(idle :: run_task(), false);
|
||||
test_equal(idle :: get_progress(), (float)1.0);
|
||||
}
|
||||
|
||||
static void do_test(float n)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << " (n = " << n << ")";
|
||||
const std::string n_str = ss.str();
|
||||
|
||||
cur = -1;
|
||||
run_test("Idle Queue Test" + n_str, test_idle_queue, n);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned int i, num = 10;
|
||||
|
||||
test_progress(num, num, __LINE__);
|
||||
for (i = 0; i < num; i++)
|
||||
idle :: schedule(inc_cur, i);
|
||||
test_progress(0, num, __LINE__);
|
||||
test_results(idle :: get_progress() == 0.0, __LINE__);
|
||||
|
||||
for (i = 0; i < (num - 1); i++) {
|
||||
test_results(idle :: run_task(), __LINE__);
|
||||
test_progress(i + 1, num, __LINE__);
|
||||
}
|
||||
|
||||
test_results(idle :: run_task() == false, __LINE__);
|
||||
test_progress(i + 1, num, __LINE__);
|
||||
|
||||
test_results(idle :: run_task() == false, __LINE__);
|
||||
test_progress(num, num, __LINE__);
|
||||
do_test(10);
|
||||
do_test(100);
|
||||
do_test(1000);
|
||||
do_test(10000);
|
||||
do_test(100000);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue