eigenmath/src/selftest.cpp

213 lines
2.8 KiB
C++
Raw Permalink Normal View History

2007-05-24 17:26:56 +02:00
// self test functions
2004-03-03 21:24:06 +01:00
#include "stdafx.h"
#include "defs.h"
2007-05-24 17:26:56 +02:00
#include "selftest.h"
2005-10-27 23:18:32 +02:00
2004-03-03 21:24:06 +01:00
static jmp_buf jbuf;
void
selftest(void)
{
2007-08-04 02:36:46 +02:00
// for handling "errout"
2004-03-03 21:24:06 +01:00
if (setjmp(jbuf))
return;
2007-05-24 17:26:56 +02:00
#if SELFTEST
2007-08-04 03:49:16 +02:00
test_low_level();
2007-08-04 02:36:46 +02:00
2004-03-03 21:24:06 +01:00
test_multiply();
test_scan();
test_power();
test_factor_number();
test_test();
test_tensor();
2006-02-10 17:33:41 +01:00
test_bake();
2007-05-24 17:26:56 +02:00
test(__FILE__, s, sizeof (s) / sizeof (char *)); // "s" is in selftest.h
2004-03-03 21:24:06 +01:00
test_abs();
2006-01-06 19:23:09 +01:00
test_adj();
2005-10-08 04:20:34 +02:00
test_arg();
2005-07-30 21:37:29 +02:00
test_besselj();
test_bessely();
2004-03-03 21:24:06 +01:00
test_ceiling();
2006-10-13 17:43:11 +02:00
test_choose();
2006-09-20 18:09:25 +02:00
test_circexp();
2007-05-09 02:06:24 +02:00
test_clock();
2006-01-06 18:26:49 +01:00
test_cofactor();
2004-03-03 21:24:06 +01:00
test_condense();
test_contract();
2007-05-15 18:20:30 +02:00
test_defint();
2005-06-25 21:29:07 +02:00
test_denominator();
2004-03-03 21:24:06 +01:00
test_derivative();
2005-07-30 21:37:29 +02:00
test_dirac();
test_erf();
test_erfc();
2008-04-13 23:36:03 +02:00
test_expand();
2004-06-18 01:02:29 +02:00
test_expcos();
test_expsin();
2004-03-03 21:24:06 +01:00
test_factorpoly();
2006-09-19 23:04:36 +02:00
test_float();
2004-03-03 21:24:06 +01:00
test_floor();
2005-07-30 21:37:29 +02:00
test_gamma();
2006-09-19 23:04:36 +02:00
test_gcd();
2005-10-09 23:24:06 +02:00
test_imag();
test_inner();
2004-03-03 21:24:06 +01:00
test_lcm();
2004-07-16 02:36:18 +02:00
test_log();
2005-10-09 23:24:06 +02:00
test_mag();
2004-03-03 21:24:06 +01:00
test_mod();
2007-11-18 02:08:12 +01:00
test_nroots();
2005-06-25 21:29:07 +02:00
test_numerator();
test_outer();
2006-02-10 20:24:36 +01:00
test_polar();
2006-02-10 01:55:47 +01:00
test_quotient();
2004-03-03 21:24:06 +01:00
test_rationalize();
2005-10-09 23:24:06 +02:00
test_real();
test_rect();
2005-07-30 21:37:29 +02:00
test_sgn();
2004-03-03 21:24:06 +01:00
test_taylor();
test_transpose();
test_zero();
2004-03-03 21:24:06 +01:00
test_hermite();
test_laguerre();
test_legendre();
test_binomial();
test_divisors();
test_coeff();
test_sin();
test_cos();
test_tan();
test_sinh();
test_cosh();
test_tanh();
test_arcsin();
test_arcsinh();
test_arccos();
test_arccosh();
test_arctan();
test_arctanh();
test_index();
test_isprime();
test_integral();
test_simplify();
test_roots();
test_eigen();
2007-05-24 17:26:56 +02:00
#endif
mini_test();
2004-03-03 21:24:06 +01:00
2007-05-24 17:26:56 +02:00
logout("OK, all tests passed.\n");
2004-03-03 21:24:06 +01:00
}
void
logout(char *s)
{
printstr(s);
}
void
errout(void)
{
logout("\n");
longjmp(jbuf, 1);
}
2005-08-07 16:42:42 +02:00
void
test(char *file, char **s, int n)
{
int i;
char *t;
test_flag = 1;
2007-08-04 03:26:29 +02:00
run("clear");
2006-10-06 20:28:26 +02:00
2007-05-23 21:12:43 +02:00
run("e=quote(e)");
2006-10-06 20:28:26 +02:00
2005-08-07 16:42:42 +02:00
for (i = 0; i < n; i++) {
logout(s[i]);
logout("\n");
if (s[i][0] == '#')
continue;
out_count = 0;
run(s[i]);
out_buf[out_count] = 0;
t = out_buf;
// skip leading newlines
while (*t == '\n')
t++;
// remove trailing newlines
while (out_count && out_buf[out_count - 1] == '\n')
out_buf[--out_count] = 0;
i++;
if (strcmp(t, s[i]) == 0)
continue;
// make copy because logout clobbers out_buf
t = strdup(t);
logout("expected to get the following result:\n");
logout(s[i]);
logout("\n");
logout("got this result instead:\n");
logout(t);
logout("\n");
logout(file);
logout("\n");
free(t);
errout();
}
test_flag = 0;
}
2007-08-04 03:49:16 +02:00
// these tests do not use "run" but still need a "stop" context
extern jmp_buf stop_return;
void
test_low_level(void)
{
run("clear"); // to initialize stack and memory
if (setjmp(stop_return)) {
errout();
return;
}
test_madd();
test_msub();
test_mmul();
test_mdiv();
test_mmod();
test_mprime();
test_mgcd();
test_mpow();
test_mroot();
test_quickfactor();
}