1 package Math
::GSL
::Poly
::Test
;
2 use Math
::GSL
::Test qw
/:all/;
3 use base
q{Test::Class};
5 use Math
::GSL qw
/:all/;
6 use Math
::GSL
::Poly qw
/:all/;
7 use Math
::GSL
::Complex qw
/:all/;
8 use Math
::GSL
::Errno qw
/:all/;
12 BEGIN{ gsl_set_error_handler_off
(); }
14 sub make_fixture
: Test
(setup
) {
16 sub teardown
: Test
(teardown
) {
19 sub GSL_POLY_EVAL
: Tests
{
20 my $y = gsl_poly_eval
( [ 3.14, 2.72, 5.55 ] , 3, 1.0);
22 ok
( is_similar
($y,3.14+2.72+5.55) );
25 sub GSL_POLY_SOLVE_QUADRATIC
: Tests
{
26 my ($a,$b,$c) = (1, 6, 9);
29 my ($num_roots) = gsl_poly_solve_quadratic
( $a, $b, $c, \
$x0, \
$x1);
30 is_deeply
( [ $num_roots, $x0, $x1], [ 2, -3, -3 ] );
33 sub GSL_POLY_COMPLEX_EVAL
: Tests
{
34 my $z = gsl_complex_rect
(2,1); # 2+i
35 my $got = gsl_poly_complex_eval
( [ 1, 4 ], 2, $z); # 1 + 4 x
37 is_deeply
( [ gsl_parts
($got) ] , [ 9, 4 ], 'gsl_poly_complex_eval' );
40 sub GSL_COMPLEX_POLY_COMPLEX_EVAL
: Tests
{
41 local $TODO = "typemap for array of gsl_complex objects is needed";
42 my $z = gsl_complex_rect
(2,1); # 2+i
43 my $c1 = gsl_complex_rect
(3,2); # 3+2i
44 my $c2 = gsl_complex_rect
(0,5); # 5i
46 my $got = gsl_complex_poly_complex_eval
( [ $c2, $c1 ], 2, $z );
47 is_deeply
( [ gsl_parts
($got) ], [ 4, 16 ],'gsl_complex_poly_complex_eval' );
50 sub GSL_COMPLEX_POLY_COMPLEX_EVAL2
: Tests
{
51 local $TODO = "typemap for array of gsl_complex objects is needed";
52 my $z = gsl_complex_rect
(0.674,-1.423);
53 my $w = gsl_complex_rect
(-1.44, 9.55);
55 my $got = gsl_complex_poly_complex_eval
([ $z ], 1, $w);
56 is_deeply
( [ gsl_parts
($got) ] , [0.674,-1.423], 'gsl_complex_poly_eval2' );
59 sub GSL_POLY_SOLVE_CUBIC
: Tests
{
60 my ($x0, $x1, $x2) = (0, 0, 0);
61 my ($num_roots) = gsl_poly_solve_cubic
(-51.0, 867.0, -4913.0, \
$x0, \
$x1, \
$x2);
63 is_deeply
( [ $num_roots, $x0, $x1, $x2], [ 3, 17.0, 17.0, 17.0] );
66 sub GSL_POLY_COMPLEX_SOLVE_QUADRATIC
: Tests
{
67 my $z0 = gsl_complex_rect
(2,3);
68 my $z1 = gsl_complex_rect
(3,2);
70 my ($num_roots) = gsl_poly_complex_solve_quadratic
( 4.0, -20.0, 26.0 , $z0, $z1);
72 ok_similar
([ $num_roots, gsl_parts
($z0), gsl_parts
($z1) ],
73 [ 2, 2.5, -0.5, 2.5, 0.5 ]