File: tridiag.t

package info (click to toggle)
libmath-matrixreal-perl 2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,120 kB
  • sloc: perl: 2,837; makefile: 8
file content (45 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use Test::More tests => 5;
use File::Spec;
use lib File::Spec->catfile("..","lib");
use Math::MatrixReal;
use strict;
do 'funcs.pl';

my $zero = sprintf '%E', 0;
my ($pad) = $zero =~ /E00(\d+)$/;

my $b = Math::MatrixReal->new_from_string(<<XXX);
[ 1 1 0 0 ]
[ 1 2 2 0 ]
[ 0 2 3 3 ]
[ 0 0 3 4 ]
XXX

my $a = Math::MatrixReal->new_tridiag( [1, 2, 3], [1, 2, 3, 4], [1, 2, 3] );
unless ($@){
	ok(1, 'new_tridiag exists');
} else {
	ok(0, 'new_tridiag fails');
}
ok( ref $a eq 'Math::MatrixReal', 'new_tridiag returns correct object' );
ok_matrix( $a, $b, 'new_tridiag seems to work' );
my ($r,$c) = $a->dim;
ok( $r == 4 && $c == 4, 'new_tridiag returns a matrix of the correct size' );

my $matrix = Math::MatrixReal->new_tridiag( [ 6, 4, 2 ], [1,2,3,4], [1, 8, 9] );

my $correct = <<'MAT';
[  1.000000000000E+00  1.000000000000E+00  0.000000000000E+00  0.000000000000E+00 ]
[  6.000000000000E+00  2.000000000000E+00  8.000000000000E+00  0.000000000000E+00 ]
[  0.000000000000E+00  4.000000000000E+00  3.000000000000E+00  9.000000000000E+00 ]
[  0.000000000000E+00  0.000000000000E+00  2.000000000000E+00  4.000000000000E+00 ]
MAT

# Determine number of digits in exponents beyond the libc 'standard' of two
# and pad out the expected result.
my $zero = sprintf '%E', 0;
my ($pad) = $zero =~ m/E\+00(\d+)$/;
$correct =~ s/([eE])([+-])(\d\d)/$1$2$pad$3/g if defined $pad;

ok( "$matrix" eq $correct, 'new_tridiag' );