tests/core: Update idle queue test to the new framework
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
583bb5d84b
commit
0dd91e25c7
|
@ -18,9 +18,9 @@ res += [ CoreTest("file", "file.cpp") ]
|
|||
res += [ CoreTest("database", "database.cpp") ]
|
||||
res += [ CoreTest("index", "index.cpp") ]
|
||||
res += [ CoreTest("filter", "filter.cpp") ]
|
||||
res += [ CoreTest("idle", "idle.cpp") ]
|
||||
Return("res")
|
||||
|
||||
#test( "idle" )
|
||||
#
|
||||
#test( "tags/generic" )
|
||||
#test( "tags/artist" )
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
*/
|
||||
#include <core/idle.h>
|
||||
#include <core/string.h>
|
||||
#include <tests/test.h>
|
||||
#include "test.h"
|
||||
|
||||
static float N = 0;
|
||||
static float cur = -1;
|
||||
static bool func_passed = false;
|
||||
|
||||
|
@ -17,45 +16,39 @@ static void inc_cur(float &expected)
|
|||
}
|
||||
|
||||
|
||||
static unsigned int _test_idle_queue_step(unsigned int i)
|
||||
static void test_idle_queue(unsigned int n)
|
||||
{
|
||||
if (idle :: run_task() == false)
|
||||
return LOOP_FAILED;
|
||||
if (idle :: get_progress() != ((i + 1) / N))
|
||||
return LOOP_FAILED;
|
||||
return func_passed ? LOOP_PASSED : LOOP_FAILED;
|
||||
}
|
||||
cur = -1;
|
||||
|
||||
static void test_idle_queue()
|
||||
{
|
||||
test_equal(idle :: get_progress(), (float)1.0);
|
||||
test_equal(idle :: run_task(), false);
|
||||
|
||||
for (float i = 0; i < N; i++)
|
||||
for (float i = 0; i < n; i++)
|
||||
idle :: schedule(inc_cur, i);
|
||||
test_equal(idle :: get_progress(), (float)0.0);
|
||||
|
||||
test_for_each(0, N - 1, 1, _test_idle_queue_step);
|
||||
for (unsigned int i = 0; i < (n - 1); i++) {
|
||||
test_loop_equal(idle :: run_task(), true, i);
|
||||
test_loop_equal(idle :: get_progress(), ((i + 1) / (float)n), i);
|
||||
test_loop_equal(func_passed, true, i);
|
||||
} test_loop_passed();
|
||||
|
||||
test_equal(idle :: run_task(), false);
|
||||
test_equal(idle :: get_progress(), (float)1.0);
|
||||
}
|
||||
|
||||
static void do_test(unsigned int n)
|
||||
{
|
||||
std::string n_str = " (n = " + string :: utos(n) + ")";
|
||||
|
||||
N = n;
|
||||
cur = -1;
|
||||
test :: run("Idle Queue Test" + n_str, test_idle_queue);
|
||||
}
|
||||
static void test_idle_queue_10() { test_idle_queue(10); }
|
||||
static void test_idle_queue_100() { test_idle_queue(100); }
|
||||
static void test_idle_queue_1000() { test_idle_queue(1000); }
|
||||
static void test_idle_queue_10000() { test_idle_queue(10000); }
|
||||
static void test_idle_queue_100000() { test_idle_queue(100000); }
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
do_test(10);
|
||||
do_test(100);
|
||||
do_test(1000);
|
||||
do_test(10000);
|
||||
do_test(100000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Idle Queue (n = 10)", test_idle_queue_10),
|
||||
UNIT_TEST("Idle Queue (n = 100)", test_idle_queue_100),
|
||||
UNIT_TEST("Idle Queue (n = 1000)", test_idle_queue_1000),
|
||||
UNIT_TEST("Idle Queue (n = 10000)", test_idle_queue_10000),
|
||||
UNIT_TEST("Idle Queue (n = 100000)", test_idle_queue_100000),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue