ocarina/tests/core/idle.cpp

66 lines
1.2 KiB
C++
Raw Normal View History

/*
* Copyright 2014 (c) Anna Schumaker.
* Test the idle queue
*/
#include <core/idle.h>
#include <tests/test.h>
#include <sstream>
static float N = 0;
static float cur = -1;
static bool func_passed = false;
static void inc_cur(float &expected)
{
cur++;
func_passed = (cur == expected);
}
static unsigned int _test_idle_queue_step(unsigned int i)
{
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;
}
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++)
idle :: schedule(inc_cur, i);
test_equal(idle :: get_progress(), (float)0.0);
test_for_each(0, N - 1, 1, _test_idle_queue_step);
test_equal(idle :: run_task(), false);
test_equal(idle :: get_progress(), (float)1.0);
}
static void do_test(unsigned int n)
{
std::stringstream ss;
ss << " (n = " << n << ")";
const std::string n_str = ss.str();
N = n;
cur = -1;
test :: run("Idle Queue Test" + n_str, test_idle_queue);
}
int main(int argc, char **argv)
{
do_test(10);
do_test(100);
do_test(1000);
do_test(10000);
do_test(100000);
return 0;
}