/**
 * @file
 * @brief tests proper stack usage (particularly, right handling
 * of window overflow/underflow on SPARC).
 *
 * @date 14.08.09
 * @author Eldar Abusalimov
 */

#include <embox/test.h>
#include <test/misc.h>

#define RECURSION_DEPTH 32

EMBOX_TEST(run);

static int run(void) {
	return test_misc_recursion(RECURSION_DEPTH);
}

/**
 * @file
 * @brief Tests proper stack usage.
 *
 * @date 14.08.09
 * @author Eldar Abusalimov
 */

#include <embox/test.h>
#include <test/misc.h>

EMBOX_TEST_SUITE("Stack usage tests");

static int fib(int k) {
	if (k < 2) {
		return k;
	} else {
		return fib(k - 1) + fib(k - 2);
	}
}

TEST_CASE("Recursively calculating Fibonacci number") {
	test_assert_equal(fib(0), 0);
	test_assert_equal(fib(1), 1);
	test_assert_equal(fib(2), 1);
	test_assert_equal(fib(3), 2);
	test_assert_equal(fib(4), 3);
	test_assert_equal(fib(5), 5);

	/* This is madness. This is SPARC!!! */
	test_assert_equal(fib(17), 1597);
}

Rewrite recursion test to calculate Fibonacci
Rewrite recursion test to calculate Fibonacci