1 package Math::GSL::Poly::Test;
2 use base q{Test::Class};
3 use Test::More tests => 7;
4 use Math::GSL::Test qw/:all/;
5 use Math::GSL::Poly qw/:all/;
6 use Math::GSL::Errno qw/:all/;
7 use Math::GSL::Complex qw/:all/;
11 BEGIN{ gsl_set_error_handler_off(); }
13 sub make_fixture : Test(setup) {
15 sub teardown : Test(teardown) {
18 sub GSL_POLY_EVAL : Tests {
19 my $y = gsl_poly_eval( [ 3.14, 2.72, 5.55 ] , 3, 1.0);
21 ok( is_similar($y,3.14+2.72+5.55) );
24 sub GSL_POLY_SOLVE_QUADRATIC : Tests {
25 my ($a,$b,$c) = (1, 6, 9);
28 my ($num_roots) = gsl_poly_solve_quadratic( $a, $b, $c, \$x0, \$x1);
29 ok_similar( [ $num_roots, $x0, $x1], [ 2, -3, -3 ] );
32 sub GSL_POLY_COMPLEX_EVAL : Tests(1) {
33 my $z = gsl_complex_rect(2,1); # 2+i
34 my $got = gsl_poly_complex_eval( [ 1, 4 ], 2, $z); # 1 + 4 x
36 ok_similar( [ gsl_parts($got) ] , [ 9, 4 ], 'gsl_poly_complex_eval' );
39 sub GSL_COMPLEX_POLY_COMPLEX_EVAL : Tests(1) {
40 local $TODO = "typemap for array of gsl_complex objects is needed";
41 my $z = gsl_complex_rect(2,1); # 2+i
42 my $c1 = gsl_complex_rect(3,2); # 3+2i
43 my $c2 = gsl_complex_rect(0,5); # 5i
45 my $got = gsl_complex_poly_complex_eval( [ $c2, $c1 ], 2, $z );
46 ok_similar( [ gsl_parts($got) ], [ 4, 16 ],'gsl_complex_poly_complex_eval' );
49 sub GSL_COMPLEX_POLY_COMPLEX_EVAL2 : Tests(1) {
50 local $TODO = "typemap for array of gsl_complex objects is needed";
51 my $z = gsl_complex_rect(0.674,-1.423);
52 my $w = gsl_complex_rect(-1.44, 9.55);
54 my $got = gsl_complex_poly_complex_eval ([ $z ], 1, $w);
55 ok_similar( [ gsl_parts($got) ] , [0.674,-1.423], 'gsl_complex_poly_eval2' );
58 sub GSL_POLY_SOLVE_CUBIC : Tests {
59 my ($x0, $x1, $x2) = (0, 0, 0);
60 my ($num_roots) = gsl_poly_solve_cubic (-51.0, 867.0, -4913.0, \$x0, \$x1, \$x2);
62 ok_similar ( [ $num_roots, $x0, $x1, $x2], [ 3, 17.0, 17.0, 17.0] );
65 sub GSL_POLY_COMPLEX_SOLVE_QUADRATIC : Tests {
66 my $z0 = gsl_complex_rect(2,3);
67 my $z1 = gsl_complex_rect(3,2);
69 my ($num_roots) = gsl_poly_complex_solve_quadratic ( 4.0, -20.0, 26.0 , $z0, $z1);
71 ok_similar ([ $num_roots, gsl_parts($z0), gsl_parts($z1) ],
72 [ 2, 2.5, -0.5, 2.5, 0.5 ]
77 Test::Class->runtests;