diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-07-29 12:13:19 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-07-29 12:13:47 -0400 |
commit | a8cd1c76427143baacd77956579d6ac8879cd03c (patch) | |
tree | cdf173493ffbd4d7af6a3c2792c04fe1468505d2 /libdimension | |
parent | 660a6dc83a761c76b1b3a3c6d71c18800e0b47a3 (diff) | |
download | dimension-a8cd1c76427143baacd77956579d6ac8879cd03c.tar.xz |
polynomial: Fix too-small array in test.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/tests/polynomial.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/libdimension/tests/polynomial.c b/libdimension/tests/polynomial.c index cc1d08e..492c22c 100644 --- a/libdimension/tests/polynomial.c +++ b/libdimension/tests/polynomial.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2010-2012 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2010-2014 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Test Suite. * * * @@ -31,7 +31,7 @@ static void dmnsn_assert_roots(const double poly[], size_t degree, size_t nroots_ex, ...) { - double roots[degree - 1]; + double roots[degree]; size_t nroots = dmnsn_polynomial_solve(poly, degree, roots); ck_assert_int_eq(nroots, nroots_ex); @@ -41,18 +41,19 @@ dmnsn_assert_roots(const double poly[], size_t degree, size_t nroots_ex, ...) double root_ex = va_arg(ap, double); bool found = false; for (size_t j = 0; j < nroots; ++j) { - if (fabs(root_ex - roots[j]) >= dmnsn_epsilon) { + double root = roots[j]; + if (fabs(root_ex - root) >= dmnsn_epsilon) { continue; } - found = true; - double evroot = dmnsn_polynomial_evaluate(poly, degree, roots[j]); + double evroot = dmnsn_polynomial_evaluate(poly, degree, root); ck_assert(fabs(evroot) < DMNSN_CLOSE_ENOUGH); - double evmin = dmnsn_polynomial_evaluate(poly, degree, roots[j] - dmnsn_epsilon); - double evmax = dmnsn_polynomial_evaluate(poly, degree, roots[j] + dmnsn_epsilon); + double evmin = dmnsn_polynomial_evaluate(poly, degree, root - dmnsn_epsilon); + double evmax = dmnsn_polynomial_evaluate(poly, degree, root + dmnsn_epsilon); ck_assert(fabs(evroot) <= fabs(evmin) && fabs(evroot) <= fabs(evmax)); + found = true; break; } @@ -60,6 +61,7 @@ dmnsn_assert_roots(const double poly[], size_t degree, size_t nroots_ex, ...) for (size_t j = 0; j < nroots; ++j) { fprintf(stderr, "roots[%zu] == %.17g\n", j, roots[j]); } + fprintf(stderr, "----\n"); ck_abort_msg("Expected root %.17g not found", root_ex); } } |