Move HERMITIAN test to MatrixComplex.t
[Math-GSL.git] / t / MatrixComplex.t
blobe513dbd93a2575f83995ed21b20bf08304f78b31
1 package Math::GSL::MatrixComplex::Test;
2 use Test::More tests => 13;
3 use base q{Test::Class};
4 use strict;
6 use Math::GSL                qw/:all/;
7 use Math::GSL::Test          qw/:all/;
8 use Math::GSL::Errno         qw/:all/;
9 use Math::GSL::MatrixComplex qw/:all/;
10 use Math::GSL::Complex       qw/:all/;
11 use Math::Complex;
12 use Data::Dumper;
14 BEGIN{ gsl_set_error_handler_off(); }
16 sub make_fixture : Test(setup) {
17     my $self = shift;
20 sub teardown : Test(teardown) {
21     unlink 'matrix' if -f 'matrix';
24 sub GSL_MATRIX_COMPLEX_NEW: Tests(3) {
25     my $u = Math::GSL::MatrixComplex->new(10,20);
26     isa_ok($u, 'Math::GSL::MatrixComplex');
27     ok( $u->rows ==  10, 'rows');
28     ok( $u->cols ==  20, 'cols');
31 sub GSL_MATRIX_COMPLEX_SET : Tests(1) {
32     my $u = Math::GSL::MatrixComplex->new(2,2);
33     gsl_matrix_complex_set($u->raw, 0, 0, Math::GSL::Complex::gsl_complex_rect(3,5) );
34     warn Dumper [ $u->as_list ];
37 sub GSL_MATRIX_COMPLEX_COL : Tests(3) {
38     my $u = Math::GSL::MatrixComplex->new(2,2);
39     isa_ok( $u->col(0) , 'Math::GSL::MatrixComplex');
40     cmp_ok( $u->col(0)->cols, '==', 1 );
41     cmp_ok( $u->col(0)->rows, '==', 2 );
44 sub GSL_MATRIX_COMPLEX_ROW : Tests(3) {
45     my $u = Math::GSL::MatrixComplex->new(2,2);
46     isa_ok( $u->row(0) , 'Math::GSL::MatrixComplex');
47     cmp_ok( $u->row(0)->cols, '==', 2 );
48     cmp_ok( $u->row(0)->rows, '==', 1 );
50 sub GSL_MATRIX_COMPLEX_SET_OO : Tests(2) {
51     local $TODO = qq{set_row with complex numbers goes boom};
52     my $u = Math::GSL::MatrixComplex->new(2,2);
53     $u->set_row(0, [ 1+7*i, 2*i ] )
54       ->set_row(1, [ 3*i, -4  ] );
55     ok_similar( [ map { Re $_ } $u->as_list ], [ 1, 0, 0, -4 ] );
56     ok_similar( [ map { Im $_ } $u->as_list ], [ 7, 2, 3, 0  ] );
59 sub HERMITIAN : Tests(1) {
60     my $matrix    = gsl_matrix_complex_alloc(2,2);
61     my $transpose = gsl_matrix_complex_alloc(2,2);
62     gsl_matrix_complex_set($matrix, 0, 0, gsl_complex_rect(3,0));
63     gsl_matrix_complex_set($matrix, 0, 1, gsl_complex_rect(2,1));
64     gsl_matrix_complex_set($matrix, 1, 0, gsl_complex_rect(2,-1));
65     gsl_matrix_complex_set($matrix, 1, 1, gsl_complex_rect(1,0));
66     gsl_matrix_complex_memcpy($transpose, $matrix);
67     gsl_matrix_complex_transpose($transpose);
69     for my $row (0..1) {
70         map { gsl_matrix_complex_set($transpose, $row, $_, gsl_complex_conjugate(gsl_matrix_complex_get($transpose, $row, $_))) } (0..1);
71     }
73     my $upper_right = gsl_matrix_complex_get($matrix, 0, 1 );
74     my $lower_left  = gsl_matrix_complex_get($matrix, 1, 0 );
76     ok( gsl_complex_eq( gsl_complex_conjugate($upper_right), $lower_left ), 'hermitian' );
79 Test::Class->runtests;