ocarina/tests/core/idle.cpp
Anna Schumaker 6c6437c2bd string: Create a utos() function
This function converts unsigned ints into strings.  This allows me to
replace several almost identical functions with one function call.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
2015-01-27 08:37:27 -05:00

62 lines
1.2 KiB
C++

/*
* Copyright 2014 (c) Anna Schumaker.
* Test the idle queue
*/
#include <core/idle.h>
#include <core/string.h>
#include <tests/test.h>
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::string n_str = " (n = " + string :: utos(n) + ")";
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;
}