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/unit_test.hpp>
14 #include <boost/multiprecision/cpp_int.hpp>
15 #include <boost/multiprecision/cpp_bin_float.hpp>
16 #include <boost/multiprecision/cpp_dec_float.hpp>
21 #if !defined(TEST1) && !defined(TEST2) && !defined(TEST3)
27 using namespace boost::math
;
28 using boost::integer::gcd
;
29 using namespace boost::math::tools
;
31 using boost::integer::gcd_detail::Euclid_gcd
;
32 using boost::math::tools::subresultant_gcd
;
37 answer(std::pair
< polynomial
<T
>, polynomial
<T
> > const &x
) :
38 quotient(x
.first
), remainder(x
.second
) {}
40 polynomial
<T
> quotient
;
41 polynomial
<T
> remainder
;
44 std::array
<double, 4> const d3a
= {{10, -6, -4, 3}};
45 std::array
<double, 4> const d3b
= {{-7, 5, 6, 1}};
47 std::array
<double, 2> const d1a
= {{-2, 1}};
48 std::array
<double, 1> const d0a
= {{6}};
49 std::array
<double, 2> const d0a1
= {{0, 6}};
50 std::array
<double, 6> const d0a5
= {{0, 0, 0, 0, 0, 6}};
53 std::array
<int, 9> const d8
= {{-5, 2, 8, -3, -3, 0, 1, 0, 1}};
54 std::array
<int, 9> const d8b
= {{0, 2, 8, -3, -3, 0, 1, 0, 1}};
58 BOOST_AUTO_TEST_CASE(trivial
)
60 /* 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 */
66 std::array
<double, 4> const d3c
= {{10.0/3.0, -2.0, -4.0/3.0, 1.0}};
67 std::array
<double, 3> const d2a
= {{-2, 2, 3}};
68 std::array
<double, 3> const d2b
= {{-7, 5, 6}};
69 std::array
<double, 3> const d2c
= {{31, -21, -22}};
70 std::array
<double, 1> const d0b
= {{3}};
71 std::array
<int, 7> const d6
= {{21, -9, -4, 0, 5, 0, 3}};
72 std::array
<int, 3> const d2
= {{-6, 0, 9}};
73 std::array
<int, 6> const d5
= {{-9, 0, 3, 0, -15}};
76 BOOST_AUTO_TEST_CASE( test_construction
)
78 polynomial
<double> const a(d3a
.begin(), d3a
.end());
79 polynomial
<double> const b(d3a
.begin(), 3);
80 BOOST_CHECK_EQUAL(a
, b
);
83 #ifdef BOOST_MATH_HAS_IS_CONST_ITERABLE
88 BOOST_AUTO_TEST_CASE(test_range_construction
)
90 std::list
<double> l
{ 1, 2, 3, 4 };
91 std::array
<double, 4> a
{ 3, 4, 5, 6 };
92 polynomial
<double> p1
{ 1, 2, 3, 4 };
93 polynomial
<double> p2
{ 3, 4, 5, 6 };
95 polynomial
<double> p3(l
);
96 polynomial
<double> p4(a
);
98 BOOST_CHECK_EQUAL(p1
, p3
);
99 BOOST_CHECK_EQUAL(p2
, p4
);
103 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500)
104 BOOST_AUTO_TEST_CASE( test_initializer_list_construction
)
106 polynomial
<double> a(begin(d3a
), end(d3a
));
107 polynomial
<double> b
= {10, -6, -4, 3};
108 polynomial
<double> c
{10, -6, -4, 3};
109 polynomial
<double> d
{10, -6, -4, 3, 0, 0};
110 BOOST_CHECK_EQUAL(a
, b
);
111 BOOST_CHECK_EQUAL(b
, c
);
112 BOOST_CHECK_EQUAL(d
.degree(), 3u);
115 BOOST_AUTO_TEST_CASE( test_initializer_list_assignment
)
117 polynomial
<double> a(begin(d3a
), end(d3a
));
118 polynomial
<double> b
;
119 b
= {10, -6, -4, 3, 0, 0};
120 BOOST_CHECK_EQUAL(b
.degree(), 3u);
121 BOOST_CHECK_EQUAL(a
, b
);
126 BOOST_AUTO_TEST_CASE( test_degree
)
128 polynomial
<double> const zero
;
129 polynomial
<double> const a(d3a
.begin(), d3a
.end());
130 BOOST_CHECK_THROW(zero
.degree(), std::logic_error
);
131 BOOST_CHECK_EQUAL(a
.degree(), 3u);
135 BOOST_AUTO_TEST_CASE( test_division_over_field
)
137 polynomial
<double> const a(d3a
.begin(), d3a
.end());
138 polynomial
<double> const b(d1a
.begin(), d1a
.end());
139 polynomial
<double> const q(d2a
.begin(), d2a
.end());
140 polynomial
<double> const r(d0a
.begin(), d0a
.end());
141 polynomial
<double> const c(d3b
.begin(), d3b
.end());
142 polynomial
<double> const d(d2b
.begin(), d2b
.end());
143 polynomial
<double> const e(d2c
.begin(), d2c
.end());
144 polynomial
<double> const f(d0b
.begin(), d0b
.end());
145 polynomial
<double> const g(d3c
.begin(), d3c
.end());
146 polynomial
<double> const zero
;
147 polynomial
<double> const one(1.0);
149 answer
<double> result
= quotient_remainder(a
, b
);
150 BOOST_CHECK_EQUAL(result
.quotient
, q
);
151 BOOST_CHECK_EQUAL(result
.remainder
, r
);
152 BOOST_CHECK_EQUAL(a
, q
* b
+ r
); // Sanity check.
154 result
= quotient_remainder(a
, c
);
155 BOOST_CHECK_EQUAL(result
.quotient
, f
);
156 BOOST_CHECK_EQUAL(result
.remainder
, e
);
157 BOOST_CHECK_EQUAL(a
, f
* c
+ e
); // Sanity check.
159 result
= quotient_remainder(a
, f
);
160 BOOST_CHECK_EQUAL(result
.quotient
, g
);
161 BOOST_CHECK_EQUAL(result
.remainder
, zero
);
162 BOOST_CHECK_EQUAL(a
, g
* f
+ zero
); // Sanity check.
163 // Check that division by a regular number gives the same result.
164 BOOST_CHECK_EQUAL(a
/ 3.0, g
);
165 BOOST_CHECK_EQUAL(a
% 3.0, zero
);
168 BOOST_CHECK_EQUAL(a
/ a
, one
);
169 BOOST_CHECK_EQUAL(a
% a
, zero
);
170 // BOOST_CHECK_EQUAL(zero / zero, zero); // TODO
173 BOOST_AUTO_TEST_CASE( test_division_over_ufd
)
175 polynomial
<int> const zero
;
176 polynomial
<int> const one(1);
177 polynomial
<int> const aa(d8
.begin(), d8
.end());
178 polynomial
<int> const bb(d6
.begin(), d6
.end());
179 polynomial
<int> const q(d2
.begin(), d2
.end());
180 polynomial
<int> const r(d5
.begin(), d5
.end());
182 answer
<int> result
= quotient_remainder(aa
, bb
);
183 BOOST_CHECK_EQUAL(result
.quotient
, q
);
184 BOOST_CHECK_EQUAL(result
.remainder
, r
);
187 BOOST_CHECK_EQUAL(aa
/ aa
, one
);
188 BOOST_CHECK_EQUAL(aa
% aa
, zero
);
193 template <typename T
>
194 struct FM2GP_Ex_8_3__1
202 std::array
<T
, 5> const x_data
= {{105, 278, -88, -56, 16}};
203 std::array
<T
, 5> const y_data
= {{70, 232, -44, -64, 16}};
204 std::array
<T
, 3> const z_data
= {{35, -24, 4}};
205 x
= polynomial
<T
>(x_data
.begin(), x_data
.end());
206 y
= polynomial
<T
>(y_data
.begin(), y_data
.end());
207 z
= polynomial
<T
>(z_data
.begin(), z_data
.end());
211 template <typename T
>
212 struct FM2GP_Ex_8_3__2
220 std::array
<T
, 5> const x_data
= {{1, -6, -8, 6, 7}};
221 std::array
<T
, 5> const y_data
= {{1, -5, -2, 15, 11}};
222 std::array
<T
, 3> const z_data
= {{1, 2, 1}};
223 x
= polynomial
<T
>(x_data
.begin(), x_data
.end());
224 y
= polynomial
<T
>(y_data
.begin(), y_data
.end());
225 z
= polynomial
<T
>(z_data
.begin(), z_data
.end());
230 template <typename T
>
239 std::array
<T
, 4> const x_data
= {{-2.2, -3.3, 0, 1}};
240 std::array
<T
, 3> const y_data
= {{-4.4, 0, 1}};
241 std::array
<T
, 2> const z_data
= {{-2, 1}};
242 x
= polynomial
<T
>(x_data
.begin(), x_data
.end());
243 y
= polynomial
<T
>(y_data
.begin(), y_data
.end());
244 z
= polynomial
<T
>(z_data
.begin(), z_data
.end());
249 template <typename T
>
258 std::array
<T
, 4> const x_data
= {{-2, -3, 0, 1}};
259 std::array
<T
, 3> const y_data
= {{-4, 0, 1}};
260 std::array
<T
, 2> const z_data
= {{-2, 1}};
261 x
= polynomial
<T
>(x_data
.begin(), x_data
.end());
262 y
= polynomial
<T
>(y_data
.begin(), y_data
.end());
263 z
= polynomial
<T
>(z_data
.begin(), z_data
.end());
267 // Sanity checks to make sure I didn't break it.
269 typedef boost::mpl::list
<signed char, short, int, long> integral_test_types
;
270 typedef boost::mpl::list
<int, long> large_integral_test_types
;
271 typedef boost::mpl::list
<> mp_integral_test_types
;
273 typedef boost::mpl::list
<
274 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1500)
275 boost::multiprecision::cpp_int
277 > integral_test_types
;
278 typedef integral_test_types large_integral_test_types
;
279 typedef large_integral_test_types mp_integral_test_types
;
281 typedef boost::mpl::list
<> large_integral_test_types
;
282 typedef boost::mpl::list
<> integral_test_types
;
283 typedef large_integral_test_types mp_integral_test_types
;
287 typedef boost::mpl::list
<double, long double> non_integral_test_types
;
289 typedef boost::mpl::list
<
290 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1500)
291 boost::multiprecision::cpp_rational
293 > non_integral_test_types
;
295 typedef boost::mpl::list
<
296 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1500)
297 boost::multiprecision::cpp_bin_float_single
, boost::multiprecision::cpp_dec_float_50
299 > non_integral_test_types
;
302 typedef boost::mpl::joint_view
<integral_test_types
, non_integral_test_types
> all_test_types
;
305 template <typename T
>
306 void normalize(polynomial
<T
> &p
)
308 if (leading_coefficient(p
) < T(0))
309 std::transform(p
.data().begin(), p
.data().end(), p
.data().begin(), std::negate
<T
>());
313 * Note that we do not expect 'pure' gcd algorithms to normalize the result.
314 * However, the usual public interface function gcd() will do that.
317 BOOST_AUTO_TEST_SUITE(test_subresultant_gcd
)
319 // This test is just to show that gcd<polynomial<T>>(u, v) is defined (and works) when T is integral and multiprecision.
320 BOOST_FIXTURE_TEST_CASE_TEMPLATE( gcd_interface
, T
, mp_integral_test_types
, FM2GP_Ex_8_3__1
<T
> )
322 typedef FM2GP_Ex_8_3__1
<T
> fixture_type
;
324 w
= gcd(fixture_type::x
, fixture_type::y
);
326 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
327 w
= gcd(fixture_type::y
, fixture_type::x
);
329 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
332 // This test is just to show that gcd<polynomial<T>>(u, v) is defined (and works) when T is floating point.
333 BOOST_FIXTURE_TEST_CASE_TEMPLATE( gcd_float_interface
, T
, non_integral_test_types
, FM2GP_Ex_8_3__1
<T
> )
335 typedef FM2GP_Ex_8_3__1
<T
> fixture_type
;
337 w
= gcd(fixture_type::x
, fixture_type::y
);
339 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
340 w
= gcd(fixture_type::y
, fixture_type::x
);
342 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
345 // The following tests call subresultant_gcd explicitly to remove any ambiguity
346 // and to permit testing on single-precision integral types.
347 BOOST_FIXTURE_TEST_CASE_TEMPLATE( Ex_8_3__1
, T
, large_integral_test_types
, FM2GP_Ex_8_3__1
<T
> )
349 typedef FM2GP_Ex_8_3__1
<T
> fixture_type
;
351 w
= subresultant_gcd(fixture_type::x
, fixture_type::y
);
353 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
354 w
= subresultant_gcd(fixture_type::y
, fixture_type::x
);
356 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
359 BOOST_FIXTURE_TEST_CASE_TEMPLATE( Ex_8_3__2
, T
, large_integral_test_types
, FM2GP_Ex_8_3__2
<T
> )
361 typedef FM2GP_Ex_8_3__2
<T
> fixture_type
;
363 w
= subresultant_gcd(fixture_type::x
, fixture_type::y
);
365 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
366 w
= subresultant_gcd(fixture_type::y
, fixture_type::x
);
368 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
371 BOOST_FIXTURE_TEST_CASE_TEMPLATE( trivial_int
, T
, large_integral_test_types
, FM2GP_trivial
<T
> )
373 typedef FM2GP_trivial
<T
> fixture_type
;
375 w
= subresultant_gcd(fixture_type::x
, fixture_type::y
);
377 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
378 w
= subresultant_gcd(fixture_type::y
, fixture_type::x
);
380 BOOST_CHECK_EQUAL(w
, fixture_type::z
);
383 BOOST_AUTO_TEST_SUITE_END()
386 BOOST_AUTO_TEST_CASE_TEMPLATE( test_addition
, T
, all_test_types
)
388 polynomial
<T
> const a(d3a
.begin(), d3a
.end());
389 polynomial
<T
> const b(d1a
.begin(), d1a
.end());
390 polynomial
<T
> const zero
;
392 polynomial
<T
> result
= a
+ b
; // different degree
393 std::array
<T
, 4> tmp
= {{8, -5, -4, 3}};
394 polynomial
<T
> expected(tmp
.begin(), tmp
.end());
395 BOOST_CHECK_EQUAL(result
, expected
);
396 BOOST_CHECK_EQUAL(a
+ zero
, a
);
397 BOOST_CHECK_EQUAL(a
+ b
, b
+ a
);
400 BOOST_AUTO_TEST_CASE_TEMPLATE( test_subtraction
, T
, all_test_types
)
402 polynomial
<T
> const a(d3a
.begin(), d3a
.end());
403 polynomial
<T
> const zero
;
405 BOOST_CHECK_EQUAL(a
- T(0), a
);
406 BOOST_CHECK_EQUAL(T(0) - a
, -a
);
407 BOOST_CHECK_EQUAL(a
- zero
, a
);
408 BOOST_CHECK_EQUAL(zero
- a
, -a
);
409 BOOST_CHECK_EQUAL(a
- a
, zero
);
412 BOOST_AUTO_TEST_CASE_TEMPLATE( test_multiplication
, T
, all_test_types
)
414 polynomial
<T
> const a(d3a
.begin(), d3a
.end());
415 polynomial
<T
> const b(d1a
.begin(), d1a
.end());
416 polynomial
<T
> const zero
;
417 std::array
<T
, 7> const d3a_sq
= {{100, -120, -44, 108, -20, -24, 9}};
418 polynomial
<T
> const a_sq(d3a_sq
.begin(), d3a_sq
.end());
420 BOOST_CHECK_EQUAL(a
* T(0), zero
);
421 BOOST_CHECK_EQUAL(a
* zero
, zero
);
422 BOOST_CHECK_EQUAL(zero
* T(0), zero
);
423 BOOST_CHECK_EQUAL(zero
* zero
, zero
);
424 BOOST_CHECK_EQUAL(a
* b
, b
* a
);
427 BOOST_CHECK_EQUAL(aa
, a_sq
);
428 BOOST_CHECK_EQUAL(aa
, a
* a
);
431 BOOST_AUTO_TEST_CASE_TEMPLATE( test_arithmetic_relations
, T
, all_test_types
)
433 polynomial
<T
> const a(d8b
.begin(), d8b
.end());
434 polynomial
<T
> const b(d1a
.begin(), d1a
.end());
436 BOOST_CHECK_EQUAL(a
* T(2), a
+ a
);
437 BOOST_CHECK_EQUAL(a
- b
, -b
+ a
);
438 BOOST_CHECK_EQUAL(a
, (a
* a
) / a
);
439 BOOST_CHECK_EQUAL(a
, (a
/ a
) * a
);
443 BOOST_AUTO_TEST_CASE_TEMPLATE(test_non_integral_arithmetic_relations
, T
, non_integral_test_types
)
445 polynomial
<T
> const a(d8b
.begin(), d8b
.end());
446 polynomial
<T
> const b(d1a
.begin(), d1a
.end());
448 BOOST_CHECK_EQUAL(a
* T(0.5), a
/ T(2));
451 BOOST_AUTO_TEST_CASE_TEMPLATE(test_cont_and_pp
, T
, integral_test_types
)
453 std::array
<polynomial
<T
>, 4> const q
={{
454 polynomial
<T
>(d8
.begin(), d8
.end()),
455 polynomial
<T
>(d8b
.begin(), d8b
.end()),
456 polynomial
<T
>(d3a
.begin(), d3a
.end()),
457 polynomial
<T
>(d3b
.begin(), d3b
.end())
459 for (std::size_t i
= 0; i
< q
.size(); i
++)
461 BOOST_CHECK_EQUAL(q
[i
], content(q
[i
]) * primitive_part(q
[i
]));
462 BOOST_CHECK_EQUAL(primitive_part(q
[i
]), primitive_part(q
[i
], content(q
[i
])));
465 polynomial
<T
> const zero
;
466 BOOST_CHECK_EQUAL(primitive_part(zero
), zero
);
467 BOOST_CHECK_EQUAL(content(zero
), T(0));
470 BOOST_AUTO_TEST_CASE_TEMPLATE( test_self_multiply_assign
, T
, all_test_types
)
472 polynomial
<T
> a(d3a
.begin(), d3a
.end());
473 polynomial
<T
> const b(a
);
474 std::array
<double, 7> const d3a_sq
= {{100, -120, -44, 108, -20, -24, 9}};
475 polynomial
<T
> const asq(d3a_sq
.begin(), d3a_sq
.end());
479 BOOST_CHECK_EQUAL(a
, b
*b
);
480 BOOST_CHECK_EQUAL(a
, asq
);
484 BOOST_CHECK_EQUAL(a
, b
*b
*b
*b
);
488 BOOST_AUTO_TEST_CASE_TEMPLATE(test_right_shift
, T
, all_test_types
)
490 polynomial
<T
> a(d8b
.begin(), d8b
.end());
491 polynomial
<T
> const aa(a
);
492 polynomial
<T
> const b(d8b
.begin() + 1, d8b
.end());
493 polynomial
<T
> const c(d8b
.begin() + 5, d8b
.end());
495 BOOST_CHECK_EQUAL(a
, aa
);
497 BOOST_CHECK_EQUAL(a
, b
);
499 BOOST_CHECK_EQUAL(a
, c
);
503 BOOST_AUTO_TEST_CASE_TEMPLATE(test_left_shift
, T
, all_test_types
)
505 polynomial
<T
> a(d0a
.begin(), d0a
.end());
506 polynomial
<T
> const aa(a
);
507 polynomial
<T
> const b(d0a1
.begin(), d0a1
.end());
508 polynomial
<T
> const c(d0a5
.begin(), d0a5
.end());
510 BOOST_CHECK_EQUAL(a
, aa
);
512 BOOST_CHECK_EQUAL(a
, b
);
514 BOOST_CHECK_EQUAL(a
, c
);
516 // Multiplying zero by x should still be zero.
518 BOOST_CHECK_EQUAL(zero
, zero_element(multiplies
< polynomial
<T
> >()));
522 BOOST_AUTO_TEST_CASE_TEMPLATE(test_odd_even
, T
, all_test_types
)
524 polynomial
<T
> const zero
;
525 BOOST_CHECK_EQUAL(odd(zero
), false);
526 BOOST_CHECK_EQUAL(even(zero
), true);
527 polynomial
<T
> const a(d0a
.begin(), d0a
.end());
528 BOOST_CHECK_EQUAL(odd(a
), true);
529 BOOST_CHECK_EQUAL(even(a
), false);
530 polynomial
<T
> const b(d0a1
.begin(), d0a1
.end());
531 BOOST_CHECK_EQUAL(odd(b
), false);
532 BOOST_CHECK_EQUAL(even(b
), true);
535 // NOTE: Slightly unexpected: this unit test passes even when T = char.
536 BOOST_AUTO_TEST_CASE_TEMPLATE( test_pow
, T
, all_test_types
)
538 if (std::numeric_limits
<T
>::digits
< 32)
539 return; // Invokes undefined behaviour
540 polynomial
<T
> a(d3a
.begin(), d3a
.end());
541 polynomial
<T
> const one(T(1));
542 std::array
<double, 7> const d3a_sqr
= {{100, -120, -44, 108, -20, -24, 9}};
543 std::array
<double, 10> const d3a_cub
=
544 {{1000, -1800, -120, 2124, -1032, -684, 638, -18, -108, 27}};
545 polynomial
<T
> const asqr(d3a_sqr
.begin(), d3a_sqr
.end());
546 polynomial
<T
> const acub(d3a_cub
.begin(), d3a_cub
.end());
548 BOOST_CHECK_EQUAL(pow(a
, 0), one
);
549 BOOST_CHECK_EQUAL(pow(a
, 1), a
);
550 BOOST_CHECK_EQUAL(pow(a
, 2), asqr
);
551 BOOST_CHECK_EQUAL(pow(a
, 3), acub
);
552 BOOST_CHECK_EQUAL(pow(a
, 4), pow(asqr
, 2));
553 BOOST_CHECK_EQUAL(pow(a
, 5), asqr
* acub
);
554 BOOST_CHECK_EQUAL(pow(a
, 6), pow(acub
, 2));
555 BOOST_CHECK_EQUAL(pow(a
, 7), acub
* acub
* a
);
557 BOOST_CHECK_THROW(pow(a
, -1), std::domain_error
);
558 BOOST_CHECK_EQUAL(pow(one
, 137), one
);
562 BOOST_AUTO_TEST_CASE_TEMPLATE(test_bool
, T
, all_test_types
)
564 polynomial
<T
> const zero
;
565 polynomial
<T
> const a(d0a
.begin(), d0a
.end());
566 BOOST_CHECK_EQUAL(bool(zero
), false);
567 BOOST_CHECK_EQUAL(bool(a
), true);
571 BOOST_AUTO_TEST_CASE_TEMPLATE(test_set_zero
, T
, all_test_types
)
573 polynomial
<T
> const zero
;
574 polynomial
<T
> a(d0a
.begin(), d0a
.end());
576 BOOST_CHECK_EQUAL(a
, zero
);
577 a
.set_zero(); // Ensure that setting zero to zero is a no-op.
578 BOOST_CHECK_EQUAL(a
, zero
);
582 BOOST_AUTO_TEST_CASE_TEMPLATE(test_leading_coefficient
, T
, all_test_types
)
584 polynomial
<T
> const zero
;
585 BOOST_CHECK_EQUAL(leading_coefficient(zero
), T(0));
586 polynomial
<T
> a(d0a
.begin(), d0a
.end());
587 BOOST_CHECK_EQUAL(leading_coefficient(a
), T(d0a
.back()));
590 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
591 BOOST_AUTO_TEST_CASE_TEMPLATE(test_prime
, T
, all_test_types
)
593 std::vector
<T
> d
{1,1,1,1,1};
594 polynomial
<T
> p(std::move(d
));
595 polynomial
<T
> q
= p
.prime();
596 BOOST_CHECK_EQUAL(q(0), T(1));
598 for (size_t i
= 0; i
< q
.size(); ++i
)
600 BOOST_CHECK_EQUAL(q
[i
], i
+1);
603 polynomial
<T
> P
= p
.integrate();
604 BOOST_CHECK_EQUAL(P(0), T(0));
605 for (size_t i
= 1; i
< P
.size(); ++i
)
607 BOOST_CHECK_EQUAL(P
[i
], 1/static_cast<T
>(i
));
612 BOOST_CHECK_EQUAL(q
.size(), 0);