The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#use Test::More tests => 5;
use Test::More 'no_plan';

BEGIN { use_ok('Math::Assistant') };

use Math::Assistant qw(:algebra);

my $M = [ [1,4,2,0,-3], [2,9,5,2,1], [1,3,1,-2,9], [3,12,6,0,-8], [2,10,6,4,7] ];
is(Rank($M),3,'Rank of matrix 5x5');

$M = [ [0, 2, 3, 4], [4, 0, 3, 2], [1, 4, 4, 3], [2, 3, 1, 1] ];
is( Rank( $M ), 4, 'Rank of matrix 4x4' );
is( Det( $M, {'int' => 1} ), 88, 'Determinant of matrix 4x4' );

$M = [ 
	    [1,    1,    1,    1,    1,    1,    1, 1], 
	    [2**7, 2**6, 2**5, 2**4, 2**3, 2**2, 2, 1], 
	    [3**7, 3**6, 3**5, 3**4, 3**3, 3**2, 3, 1], 
	    [4**7, 4**6, 4**5, 4**4, 4**3, 4**2, 4, 1], 
	    [5**7, 5**6, 5**5, 5**4, 5**3, 5**2, 5, 1], 
	    [6**7, 6**6, 6**5, 6**4, 6**3, 6**2, 6, 1], 
	    [7**7, 7**6, 7**5, 7**4, 7**3, 7**2, 7, 1], 
	    [8**7, 8**6, 8**5, 8**4, 8**3, 8**2, 8, 1], 
 ];
is(Rank($M),8,'Rank of matrix 8x8');
is(Det($M, {'int' => 1} ),125411328000,'Determinant of matrix 8x8');

$M = [
	[1,1,1,1,1,1,1],
	[64,32,16,8,4,2,1],
	[729,243,81,27,9,3,1],
	[4096,1024,256,64,16,4,1],
	[5**6, 5**5, 5**4, 5**3, 5**2, 5, 1],
	[6**6, 6**5, 6**4, 6**3, 6**2, 6, 1],
	[7**6, 7**5, 7**4, 7**3, 7**2, 7, 1],
    ];

is(Rank( $M ), 7, 'Rank of matrix 7x7');
is(Det( $M, {'int' => 1} ), -24883200, 'Determinant of matrix 7x7');

my $B = [ 7,127,1093,5461,19531,55987,137257 ];

is( scalar(grep $_ eq '1', @{ Solve_Det($M, $B) } ),7,'Solve an equation system');

$M = [ [1.3, 2.5, 3.1, 4.2], [2.1, 4.7, 6.2, 8.7], [34, 8.2, 12, 16], [78,16,24,33] ];
$B = [ 1.1, 2.2, 3.3, 4.4 ];

is( Det( $M ), 34.754, 'Determinant of float matrix 4x4');

my $solve = [ '-20427/173770', '-47993/34754', '317493/86885', '-27401/17377' ];

my $i = 0;
for my $s ( @{ Solve_Det($M, $B) } ) {
    is($s, $solve->[$i++], 'X');
}