/*
* The Spar Library -
* Copyright (C) 2000,2001 Davide Angelocola <davide178@inwind.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include <spar/sl_test.h>
#include <spar/sl_io.h>
#include <spar/sl_math_library.h>
static sl_size __tests_passed;
static sl_size __tests_failed;
static sl_size __tests;
static bool __is_test_init = false;
int
sl_test_init (void)
{
sl_assert (__is_test_init != true);
__tests_passed = 0;
__tests_failed = 0;
__tests = 0;
__is_test_init = true;
return SL_SUCCESS;
}
int
sl_test_re_init (void)
{
__tests_passed = 0;
__tests_failed = 0;
__tests = 0;
__is_test_init = false;
return sl_test_init ();
}
int
sl_test_double (double result, double expected)
{
__tests += 1;
if (result != expected)
{
__tests_failed += 1;
return SL_ERROR;
}
else
{
__tests_passed += 1;
return SL_SUCCESS;
}
}
int
sl_test_double_with_message (const char *msg, double result, double expected)
{
__tests += 1;
if (result != expected)
{
__tests_failed += 1;
sl_writeln ("TEST '%s': failed.", msg);
return SL_ERROR;
}
else
{
__tests_passed += 1;
sl_writeln ("TEST '%s': passed.", msg);
return SL_SUCCESS;
}
}
int
sl_test_complex (sl_complex result, sl_complex expected)
{
__tests += 1;
if (sl_complex_is_not_equal (result, expected))
{
__tests_failed += 1;
return SL_ERROR;
}
else
{
__tests_passed += 1;
return SL_SUCCESS;
}
}
int
sl_test_complex_with_message (const char *msg, sl_complex result,
sl_complex expected)
{
__tests += 1;
if (sl_complex_is_not_equal (result, expected))
{
__tests_failed += 1;
sl_writeln ("TEST '%s': failed.", msg);
return SL_ERROR;
}
else
{
__tests_passed += 1;
sl_writeln ("TEST '%s': passed.", msg);
return SL_SUCCESS;
}
}
int
sl_test_summary_with_message (const char *msg)
{
sl_assert (msg != NULL);
sl_writeln ("Test summary for '%s'", msg);
sl_writeln ("");
sl_writeln ("Tests : %u", __tests);
sl_writeln ("Tests failed: %u (%g%%)", __tests_failed,
(double) (__tests_failed / __tests) * 100.);
sl_writeln ("Tests passed: %u (%g%%)", __tests_passed,
(double) (__tests_passed / __tests) * 100.);
return sl_test_re_init ();
}
syntax highlighted by Code2HTML, v. 0.9.1