1 // (C) Copyright Jeremy Murphy 2015.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/config.hpp>
7 #define BOOST_TEST_MAIN
8 #include <boost/array.hpp>
9 #include <boost/math/tools/polynomial.hpp>
10 #include <boost/integer/common_factor_rt.hpp>
11 #include <boost/mpl/list.hpp>
12 #include <boost/mpl/joint_view.hpp>
13 #include <boost/test/test_case_template.hpp>
14 #include <boost/test/unit_test.hpp>
15 #include <boost/multiprecision/cpp_int.hpp>
16 #include <boost/multiprecision/cpp_bin_float.hpp>
17 #include <boost/multiprecision/cpp_dec_float.hpp>
20 #if !defined(TEST1) && !defined(TEST2) && !defined(TEST3)
26 using namespace boost::math
;
27 using boost::integer::gcd
;
28 using namespace boost::math::tools
;
30 using boost::integer::gcd_detail::Euclid_gcd
;
31 using boost::math::tools::subresultant_gcd
;
36 answer(std::pair
< polynomial
<T
>, polynomial
<T
> > const &x
) :
37 quotient(x
.first
), remainder(x
.second
) {}
39 polynomial
<T
> quotient
;
40 polynomial
<T
> remainder
;
43 boost::array
<double, 4> const d3a
= {{10, -6, -4, 3}};
44 boost::array
<double, 4> const d3b
= {{-7, 5, 6, 1}};
46 boost::array
<double, 2> const d1a
= {{-2, 1}};
47 boost::array
<double, 1> const d0a
= {{6}};
48 boost::array
<double, 2> const d0a1
= {{0, 6}};
49 boost::array
<double, 6> const d0a5
= {{0, 0, 0, 0, 0, 6}};
52 boost::array
<int, 9> const d8
= {{-5, 2, 8, -3, -3, 0, 1, 0, 1}};
53 boost::array
<int, 9> const d8b
= {{0, 2, 8, -3, -3, 0, 1, 0, 1}};
57 BOOST_AUTO_TEST_CASE(trivial
)
59 /* We have one empty test case here, so that there is always something for Boost.Test to do even if the tests below are #if'ed out */
65 boost::array
<double, 4> const d3c
= {{10.0/3.0, -2.0, -4.0/3.0, 1.0}};
66 boost::array
<double, 3> const d2a
= {{-2, 2, 3}};
67 boost::array
<double, 3> const d2b
= {{-7, 5, 6}};
68 boost::array
<double, 3> const d2c
= {{31, -21, -22}};
69 boost::array
<double, 1> const d0b
= {{3}};
70 boost::array
<int, 7> const d6
= {{21, -9, -4, 0, 5, 0, 3}};
71 boost::array
<int, 3> const d2
= {{-6, 0, 9}};
72 boost::array
<int, 6> const d5
= {{-9, 0, 3, 0, -15}};
75 BOOST_AUTO_TEST_CASE( test_construction
)
77 polynomial
<double> const a(d3a
.begin(), d3a
.end());
78 polynomial
<double> const b(d3a
.begin(), 3);
79 BOOST_CHECK_EQUAL(a
, b
);
82 #ifdef BOOST_MATH_HAS_IS_CONST_ITERABLE
87 BOOST_AUTO_TEST_CASE(test_range_construction
)
89 std::list
<double> l
{ 1, 2, 3, 4 };
90 std::array
<double, 4> a
{ 3, 4, 5, 6 };
91 polynomial
<double> p1
{ 1, 2, 3, 4 };
92 polynomial
<double> p2
{ 3, 4, 5, 6 };
94 polynomial
<double> p3(l
);
95 polynomial
<double> p4(a
);
97 BOOST_CHECK_EQUAL(p1
, p3
);
98 BOOST_CHECK_EQUAL(p2
, p4
);
102 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500)
103 BOOST_AUTO_TEST_CASE( test_initializer_list_construction
)
105 polynomial
<double> a(begin(d3a
), end(d3a
));
106 polynomial
<double> b
= {10, -6, -4, 3};
107 polynomial
<double> c
{10, -6, -4, 3};
108 polynomial
<double> d
{10, -6, -4, 3, 0, 0};
109 BOOST_CHECK_EQUAL(a
, b
);
110 BOOST_CHECK_EQUAL(b
, c
);
111 BOOST_CHECK_EQUAL(d
.degree(), 3u);
114 BOOST_AUTO_TEST_CASE( test_initializer_list_assignment
)
116 polynomial
<double> a(begin(d3a
), end(d3a
));
117 polynomial
<double> b
;
118 b
= {10, -6, -4, 3, 0, 0};
119 BOOST_CHECK_EQUAL(b
.degree(), 3u);
120 BOOST_CHECK_EQUAL(a
, b
);
125 BOOST_AUTO_TEST_CASE( test_degree
)
127 polynomial
<double> const zero
;
128 polynomial
<double> const a(d3a
.begin(), d3a
.end());
129 BOOST_CHECK_THROW(zero
.degree(), std::logic_error
);
130 BOOST_CHECK_EQUAL(a
.degree(), 3u);
134 BOOST_AUTO_TEST_CASE( test_division_over_field
)
136 polynomial
<double> const a(d3a
.begin(), d3a
.end());
137 polynomial
<double> const b(d1a
.begin(), d1a
.end());
138 polynomial
<double> const q(d2a
.begin(), d2a
.end());
139 polynomial
<double> const r(d0a
.begin(), d0a
.end());
140 polynomial
<double> const c(d3b
.begin(), d3b
.end());
141 polynomial
<double> const d(d2b
.begin(), d2b
.end());
142 polynomial
<double> const e(d2c
.begin(), d2c
.end());
143 polynomial
<double> const f(d0b
.begin(), d0b
.end());
144 polynomial
<double> const g(d3c
.begin(), d3c
.end());
145 polynomial
<double> const zero
;
146 polynomial
<double> const one(1.0);
148 answer
<double> result
= quotient_remainder(a
, b
);
149 BOOST_CHECK_EQUAL(result
.quotient
, q
);
150 BOOST_CHECK_EQUAL(result
.remainder
, r
);
151 BOOST_CHECK_EQUAL(a
, q
* b
+ r
); // Sanity check.
153 result
= quotient_remainder(a
, c
);
154 BOOST_CHECK_EQUAL(result
.quotient
, f
);
155 BOOST_CHECK_EQUAL(result
.remainder
, e
);
156 BOOST_CHECK_EQUAL(a
, f
* c
+ e
); // Sanity check.
158 result
= quotient_remainder(a
, f
);
159 BOOST_CHECK_EQUAL(result
.quotient
, g
);
160 BOOST_CHECK_EQUAL(result
.remainder
, zero
);
161 BOOST_CHECK_EQUAL(a
, g
* f
+ zero
); // Sanity check.
162 // Check that division by a regular number gives the same result.
163 BOOST_CHECK_EQUAL(a
/ 3.0, g
);
164 BOOST_CHECK_EQUAL(a
% 3.0, zero
);
167 BOOST_CHECK_EQUAL(a
/ a
, one
);
168 BOOST_CHECK_EQUAL(a
% a
, zero
);
169 // BOOST_CHECK_EQUAL(zero / zero, zero); // TODO
172 BOOST_AUTO_TEST_CASE( test_division_over_ufd
)
174 polynomial
<int> const zero
;
175 polynomial
<int> const one(1);
176 polynomial
<int> const aa(d8
.begin(), d8
.end());
177 polynomial
<int> const bb(d6
.begin(), d6
.end());
178 polynomial
<int> const q(d2
.begin(), d2
.end());
179 polynomial
<int> const r(d5
.begin(), d5
.end());
181 answer
<int> result
= quotient_remainder(aa
, bb
);
182 BOOST_CHECK_EQUAL(result
.quotient
, q
);
183 BOOST_CHECK_EQUAL(result
.remainder
, r
);
186 BOOST_CHECK_EQUAL(aa
/ aa
, one
);
187 BOOST_CHECK_EQUAL(aa
% aa
, zero
);
192 template <typename T
>
193 struct FM2GP_Ex_8_3__1
201 boost::array
<T
, 5> const x_data
= {{105, 278, -88, -56, 16}};
202 boost::array
<T
, 5> const y_data
= {{70, 232, -44, -64, 16}};
203 boost::array
<T
, 3> const z_data
= {{35, -24, 4}};
204 x
= polynomial
<T
>(x_data
.begin(), x_data
.end());
205 y
= polynomial
<T
>(y_data
.begin(), y_data
.end());
206 z
= polynomial
<T
>(z_data
.begin(), z_data
.end());
210 template <typename T
>
211 struct FM2GP_Ex_8_3__2
219 boost::array
<T
, 5> const x_data
= {{1, -6, -8, 6, 7}};
220 boost::array
<T
, 5> const y_data
= {{1, -5, -2, 15, 11}};
221 boost::array
<T
, 3> const z_data
= {{1, 2, 1}};
222 x
= polynomial
<T
>(x_data
.begin(), x_data
.end());
223 y
= polynomial
<T
>(y_data
.begin(), y_data
.end());
224 z
= polynomial
<T
>(z_data
.begin(), z_data
.end());
229 template <typename T
>
238 boost::array
<T
, 4> const x_data
= {{-2.2, -3.3, 0, 1}};
239 boost::array
<T
, 3> const y_data
= {{-4.4, 0, 1}};
240 boost::array
<T
, 2> const z_data
= {{-2, 1}};
241 x
= polynomial
<T
>(x_data
.begin(), x_data
.end());
242 y
= polynomial
<T
>(y_data
.begin(), y_data
.end());
243 z
= polynomial
<T
>(z_data
.begin(), z_data
.end());
248 template <typename T
>
257 boost::array
<T
, 4> const x_data
= {{-2, -3, 0, 1}};
258 boost::array
<T
, 3> const y_data
= {{-4, 0, 1}};
259 boost::array
<T
, 2> const z_data
= {{-2, 1}};
260 x
= polynomial
<T
>(x_data
.begin(), x_data
.end());
261 y
= polynomial
<T
>(y_data
.begin(), y_data
.end());
262 z
= polynomial
<T
>(z_data
.begin(), z_data
.end());
266 // Sanity checks to make sure I didn't break it.
268 typedef boost::mpl::list
<signed char, short, int, long> integral_test_types
;
269 typedef boost::mpl::list
<int, long> large_integral_test_types
;
270 typedef boost::mpl::list
<> mp_integral_test_types
;
272 typedef boost::mpl::list
<
273 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1500)
274 boost::multiprecision::cpp_int
276 > integral_test_types
;
277 typedef integral_test_types large_integral_test_types
;
278 typedef large_integral_test_types mp_integral_test_types
;
280 typedef boost::mpl::list
<> large_integral_test_types
;
281 typedef boost::mpl::list
<> integral_test_types
;
282 typedef large_integral_test_types mp_integral_test_types
;
286 typedef boost::mpl::list
<double, long double> non_integral_test_types
;
288 typedef boost::mpl::list
<
289 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1500)
290 boost::multiprecision::cpp_rational
292 > non_integral_test_types
;
294 typedef boost::mpl::list
<
295 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1500)
296 boost::multiprecision::cpp_bin_float_single
, boost::multiprecision::cpp_dec_float_50
298 > non_integral_test_types
;
301 typedef boost::mpl::joint_view
<integral_test_types
, non_integral_test_types
> all_test_types
;
304 template <typename T
>
305 void normalize(polynomial
<T
> &p
)
307 if (leading_coefficient(p
) < T(0))
308 std::transform(p
.data().begin(), p
.data().end(), p
.data().begin(), std::negate
<T
>());
312 * Note that we do not expect 'pure' gcd algorithms to normalize the result.
313 * However, the usual public interface function gcd() will do that.
316 BOOST_AUTO_TEST_SUITE(test_subresultant_gcd
)
318 // This test is just to show that gcd<polynomial<T>>(u, v) is defined (and works) when T is integral and multiprecision.
319 BOOST_FIXTURE_TEST_CASE_TEMPLATE( gcd_interface
, T
, mp_integral_test_types
, FM2GP_Ex_8_3__1
<T
> )
321 typedef FM2GP_Ex_8_3__1
<T
> fixture_type
;
323 w
= gcd(fixture_type::x
, fixture_type::y
);
325 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
326 w
= gcd(fixture_type::y
, fixture_type::x
);
328 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
331 // This test is just to show that gcd<polynomial<T>>(u, v) is defined (and works) when T is floating point.
332 BOOST_FIXTURE_TEST_CASE_TEMPLATE( gcd_float_interface
, T
, non_integral_test_types
, FM2GP_Ex_8_3__1
<T
> )
334 typedef FM2GP_Ex_8_3__1
<T
> fixture_type
;
336 w
= gcd(fixture_type::x
, fixture_type::y
);
338 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
339 w
= gcd(fixture_type::y
, fixture_type::x
);
341 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
344 // The following tests call subresultant_gcd explicitly to remove any ambiguity
345 // and to permit testing on single-precision integral types.
346 BOOST_FIXTURE_TEST_CASE_TEMPLATE( Ex_8_3__1
, T
, large_integral_test_types
, FM2GP_Ex_8_3__1
<T
> )
348 typedef FM2GP_Ex_8_3__1
<T
> fixture_type
;
350 w
= subresultant_gcd(fixture_type::x
, fixture_type::y
);
352 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
353 w
= subresultant_gcd(fixture_type::y
, fixture_type::x
);
355 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
358 BOOST_FIXTURE_TEST_CASE_TEMPLATE( Ex_8_3__2
, T
, large_integral_test_types
, FM2GP_Ex_8_3__2
<T
> )
360 typedef FM2GP_Ex_8_3__2
<T
> fixture_type
;
362 w
= subresultant_gcd(fixture_type::x
, fixture_type::y
);
364 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
365 w
= subresultant_gcd(fixture_type::y
, fixture_type::x
);
367 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
370 BOOST_FIXTURE_TEST_CASE_TEMPLATE( trivial_int
, T
, large_integral_test_types
, FM2GP_trivial
<T
> )
372 typedef FM2GP_trivial
<T
> fixture_type
;
374 w
= subresultant_gcd(fixture_type::x
, fixture_type::y
);
376 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
377 w
= subresultant_gcd(fixture_type::y
, fixture_type::x
);
379 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
382 BOOST_AUTO_TEST_SUITE_END()
385 BOOST_AUTO_TEST_CASE_TEMPLATE( test_addition
, T
, all_test_types
)
387 polynomial
<T
> const a(d3a
.begin(), d3a
.end());
388 polynomial
<T
> const b(d1a
.begin(), d1a
.end());
389 polynomial
<T
> const zero
;
391 polynomial
<T
> result
= a
+ b
; // different degree
392 boost::array
<T
, 4> tmp
= {{8, -5, -4, 3}};
393 polynomial
<T
> expected(tmp
.begin(), tmp
.end());
394 BOOST_CHECK_EQUAL(result
, expected
);
395 BOOST_CHECK_EQUAL(a
+ zero
, a
);
396 BOOST_CHECK_EQUAL(a
+ b
, b
+ a
);
399 BOOST_AUTO_TEST_CASE_TEMPLATE( test_subtraction
, T
, all_test_types
)
401 polynomial
<T
> const a(d3a
.begin(), d3a
.end());
402 polynomial
<T
> const zero
;
404 BOOST_CHECK_EQUAL(a
- T(0), a
);
405 BOOST_CHECK_EQUAL(T(0) - a
, -a
);
406 BOOST_CHECK_EQUAL(a
- zero
, a
);
407 BOOST_CHECK_EQUAL(zero
- a
, -a
);
408 BOOST_CHECK_EQUAL(a
- a
, zero
);
411 BOOST_AUTO_TEST_CASE_TEMPLATE( test_multiplication
, T
, all_test_types
)
413 polynomial
<T
> const a(d3a
.begin(), d3a
.end());
414 polynomial
<T
> const b(d1a
.begin(), d1a
.end());
415 polynomial
<T
> const zero
;
416 boost::array
<T
, 7> const d3a_sq
= {{100, -120, -44, 108, -20, -24, 9}};
417 polynomial
<T
> const a_sq(d3a_sq
.begin(), d3a_sq
.end());
419 BOOST_CHECK_EQUAL(a
* T(0), zero
);
420 BOOST_CHECK_EQUAL(a
* zero
, zero
);
421 BOOST_CHECK_EQUAL(zero
* T(0), zero
);
422 BOOST_CHECK_EQUAL(zero
* zero
, zero
);
423 BOOST_CHECK_EQUAL(a
* b
, b
* a
);
426 BOOST_CHECK_EQUAL(aa
, a_sq
);
427 BOOST_CHECK_EQUAL(aa
, a
* a
);
430 BOOST_AUTO_TEST_CASE_TEMPLATE( test_arithmetic_relations
, T
, all_test_types
)
432 polynomial
<T
> const a(d8b
.begin(), d8b
.end());
433 polynomial
<T
> const b(d1a
.begin(), d1a
.end());
435 BOOST_CHECK_EQUAL(a
* T(2), a
+ a
);
436 BOOST_CHECK_EQUAL(a
- b
, -b
+ a
);
437 BOOST_CHECK_EQUAL(a
, (a
* a
) / a
);
438 BOOST_CHECK_EQUAL(a
, (a
/ a
) * a
);
442 BOOST_AUTO_TEST_CASE_TEMPLATE(test_non_integral_arithmetic_relations
, T
, non_integral_test_types
)
444 polynomial
<T
> const a(d8b
.begin(), d8b
.end());
445 polynomial
<T
> const b(d1a
.begin(), d1a
.end());
447 BOOST_CHECK_EQUAL(a
* T(0.5), a
/ T(2));
450 BOOST_AUTO_TEST_CASE_TEMPLATE(test_cont_and_pp
, T
, integral_test_types
)
452 boost::array
<polynomial
<T
>, 4> const q
={{
453 polynomial
<T
>(d8
.begin(), d8
.end()),
454 polynomial
<T
>(d8b
.begin(), d8b
.end()),
455 polynomial
<T
>(d3a
.begin(), d3a
.end()),
456 polynomial
<T
>(d3b
.begin(), d3b
.end())
458 for (std::size_t i
= 0; i
< q
.size(); i
++)
460 BOOST_CHECK_EQUAL(q
[i
], content(q
[i
]) * primitive_part(q
[i
]));
461 BOOST_CHECK_EQUAL(primitive_part(q
[i
]), primitive_part(q
[i
], content(q
[i
])));
464 polynomial
<T
> const zero
;
465 BOOST_CHECK_EQUAL(primitive_part(zero
), zero
);
466 BOOST_CHECK_EQUAL(content(zero
), T(0));
469 BOOST_AUTO_TEST_CASE_TEMPLATE( test_self_multiply_assign
, T
, all_test_types
)
471 polynomial
<T
> a(d3a
.begin(), d3a
.end());
472 polynomial
<T
> const b(a
);
473 boost::array
<double, 7> const d3a_sq
= {{100, -120, -44, 108, -20, -24, 9}};
474 polynomial
<T
> const asq(d3a_sq
.begin(), d3a_sq
.end());
478 BOOST_CHECK_EQUAL(a
, b
*b
);
479 BOOST_CHECK_EQUAL(a
, asq
);
483 BOOST_CHECK_EQUAL(a
, b
*b
*b
*b
);
487 BOOST_AUTO_TEST_CASE_TEMPLATE(test_right_shift
, T
, all_test_types
)
489 polynomial
<T
> a(d8b
.begin(), d8b
.end());
490 polynomial
<T
> const aa(a
);
491 polynomial
<T
> const b(d8b
.begin() + 1, d8b
.end());
492 polynomial
<T
> const c(d8b
.begin() + 5, d8b
.end());
494 BOOST_CHECK_EQUAL(a
, aa
);
496 BOOST_CHECK_EQUAL(a
, b
);
498 BOOST_CHECK_EQUAL(a
, c
);
502 BOOST_AUTO_TEST_CASE_TEMPLATE(test_left_shift
, T
, all_test_types
)
504 polynomial
<T
> a(d0a
.begin(), d0a
.end());
505 polynomial
<T
> const aa(a
);
506 polynomial
<T
> const b(d0a1
.begin(), d0a1
.end());
507 polynomial
<T
> const c(d0a5
.begin(), d0a5
.end());
509 BOOST_CHECK_EQUAL(a
, aa
);
511 BOOST_CHECK_EQUAL(a
, b
);
513 BOOST_CHECK_EQUAL(a
, c
);
515 // Multiplying zero by x should still be zero.
517 BOOST_CHECK_EQUAL(zero
, zero_element(multiplies
< polynomial
<T
> >()));
521 BOOST_AUTO_TEST_CASE_TEMPLATE(test_odd_even
, T
, all_test_types
)
523 polynomial
<T
> const zero
;
524 BOOST_CHECK_EQUAL(odd(zero
), false);
525 BOOST_CHECK_EQUAL(even(zero
), true);
526 polynomial
<T
> const a(d0a
.begin(), d0a
.end());
527 BOOST_CHECK_EQUAL(odd(a
), true);
528 BOOST_CHECK_EQUAL(even(a
), false);
529 polynomial
<T
> const b(d0a1
.begin(), d0a1
.end());
530 BOOST_CHECK_EQUAL(odd(b
), false);
531 BOOST_CHECK_EQUAL(even(b
), true);
534 // NOTE: Slightly unexpected: this unit test passes even when T = char.
535 BOOST_AUTO_TEST_CASE_TEMPLATE( test_pow
, T
, all_test_types
)
537 if (std::numeric_limits
<T
>::digits
< 32)
538 return; // Invokes undefined behaviour
539 polynomial
<T
> a(d3a
.begin(), d3a
.end());
540 polynomial
<T
> const one(T(1));
541 boost::array
<double, 7> const d3a_sqr
= {{100, -120, -44, 108, -20, -24, 9}};
542 boost::array
<double, 10> const d3a_cub
=
543 {{1000, -1800, -120, 2124, -1032, -684, 638, -18, -108, 27}};
544 polynomial
<T
> const asqr(d3a_sqr
.begin(), d3a_sqr
.end());
545 polynomial
<T
> const acub(d3a_cub
.begin(), d3a_cub
.end());
547 BOOST_CHECK_EQUAL(pow(a
, 0), one
);
548 BOOST_CHECK_EQUAL(pow(a
, 1), a
);
549 BOOST_CHECK_EQUAL(pow(a
, 2), asqr
);
550 BOOST_CHECK_EQUAL(pow(a
, 3), acub
);
551 BOOST_CHECK_EQUAL(pow(a
, 4), pow(asqr
, 2));
552 BOOST_CHECK_EQUAL(pow(a
, 5), asqr
* acub
);
553 BOOST_CHECK_EQUAL(pow(a
, 6), pow(acub
, 2));
554 BOOST_CHECK_EQUAL(pow(a
, 7), acub
* acub
* a
);
556 BOOST_CHECK_THROW(pow(a
, -1), std::domain_error
);
557 BOOST_CHECK_EQUAL(pow(one
, 137), one
);
561 BOOST_AUTO_TEST_CASE_TEMPLATE(test_bool
, T
, all_test_types
)
563 polynomial
<T
> const zero
;
564 polynomial
<T
> const a(d0a
.begin(), d0a
.end());
565 BOOST_CHECK_EQUAL(bool(zero
), false);
566 BOOST_CHECK_EQUAL(bool(a
), true);
570 BOOST_AUTO_TEST_CASE_TEMPLATE(test_set_zero
, T
, all_test_types
)
572 polynomial
<T
> const zero
;
573 polynomial
<T
> a(d0a
.begin(), d0a
.end());
575 BOOST_CHECK_EQUAL(a
, zero
);
576 a
.set_zero(); // Ensure that setting zero to zero is a no-op.
577 BOOST_CHECK_EQUAL(a
, zero
);
581 BOOST_AUTO_TEST_CASE_TEMPLATE(test_leading_coefficient
, T
, all_test_types
)
583 polynomial
<T
> const zero
;
584 BOOST_CHECK_EQUAL(leading_coefficient(zero
), T(0));
585 polynomial
<T
> a(d0a
.begin(), d0a
.end());
586 BOOST_CHECK_EQUAL(leading_coefficient(a
), T(d0a
.back()));
589 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
590 BOOST_AUTO_TEST_CASE_TEMPLATE(test_prime
, T
, all_test_types
)
592 std::vector
<T
> d
{1,1,1,1,1};
593 polynomial
<T
> p(std::move(d
));
594 polynomial
<T
> q
= p
.prime();
595 BOOST_CHECK_EQUAL(q(0), T(1));
597 for (size_t i
= 0; i
< q
.size(); ++i
)
599 BOOST_CHECK_EQUAL(q
[i
], i
+1);
602 polynomial
<T
> P
= p
.integrate();
603 BOOST_CHECK_EQUAL(P(0), T(0));
604 for (size_t i
= 1; i
< P
.size(); ++i
)
606 BOOST_CHECK_EQUAL(P
[i
], 1/static_cast<T
>(i
));
611 BOOST_CHECK_EQUAL(q
.size(), 0);