c88746d2da
I move all of the core tests into the core/ directory to keep them together. Gui unit tests will be put in new directories. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
58 lines
1.0 KiB
C++
58 lines
1.0 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
* Test the idle queue
|
|
*/
|
|
|
|
#include <core/idle.h>
|
|
#include <tests/test.h>
|
|
|
|
#include <sstream>
|
|
|
|
static float cur = -1;
|
|
|
|
static void inc_cur(float &expected)
|
|
{
|
|
cur++;
|
|
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)
|
|
{
|
|
do_test(10);
|
|
do_test(100);
|
|
do_test(1000);
|
|
do_test(10000);
|
|
do_test(100000);
|
|
return 0;
|
|
}
|