Skip to content

Commit

Permalink
zap pointless use of Test2::V0
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 10, 2024
1 parent d63fcae commit d569b25
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 88 deletions.
1 change: 0 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ my %makefile_hash = (
'IPC::Cmd' => '0.72',
'Test::Exception' => 0,
'Test::Warn' => 0, # for t/pptest.t
'Test2::V0' => 0.000155,
},
BUILD_REQUIRES => {
'ExtUtils::MakeMaker' => 0,
Expand Down
27 changes: 15 additions & 12 deletions t/primitive/append.t
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use strict;
use warnings;
use Test2::V0 '!float';

use Test::More;
use Test::Exception;
use PDL::LiteF;

is(
is_deeply(
append( zeroes( 2, 0 ), zeroes( 3, 0 ) )->shape->unpdl,
[ 5, 0 ],
'multi-dim empty shape'
);

is( append( pdl( 1, 2, 3, 4 ), 2 )->unpdl, [ 1, 2, 3, 4, 2 ], '[4], [1]' );
is_deeply( append( pdl( 1, 2, 3, 4 ), 2 )->unpdl, [ 1, 2, 3, 4, 2 ], '[4], [1]' );

subtest '$output = append (null,null) ' => sub {
my $output = append( null, null );
Expand All @@ -21,27 +21,30 @@ subtest '$output = append (null,null) ' => sub {
subtest 'append(null, null, $output)' => sub {
my $output = zeroes(1);
append( null, null, $output );
is( $output->unpdl, [0], q{user's ndarray is unchanged} );
is_deeply( $output->unpdl, [0], q{user's ndarray is unchanged} );
};

subtest 'output ndarray has different shape' => sub {

todo 'output => [1]; required [2]. SHOULD FAIL, output too small' => sub {
TODO: {
local $TODO = 'not fixed yet';
subtest 'output => [1]; required [2]. output too small' => sub {
my $output = zeroes(1);
like ( dies { append( pdl(1), pdl(2), $output ) },
qr/dim has size 1/ );
};
throws_ok { append( pdl(1), pdl(2), $output ) }
qr/dim has size 1/;
};
}

subtest 'output => [3,1]; required [2]' => sub {
my $output = zeroes(3,1);
like ( dies { append( pdl(1), pdl(2), $output ) },
qr/dim has size 3/ );
throws_ok { append( pdl(1), pdl(2), $output ) }
qr/dim has size 3/;
};

subtest 'output => null; required [2]' => sub {
my $output = null;
append( pdl(1), pdl(2), $output );
is( $output->unpdl, [ 1, 2 ], q{full append } );
is_deeply( $output->unpdl, [ 1, 2 ], q{full append } );
};

};
Expand Down
11 changes: 5 additions & 6 deletions t/primitive/clip.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test2::V0 '!float';
use Test::More;
use PDL::LiteF;

sub IM {
Expand All @@ -11,10 +11,9 @@ sub IM {
[ 10, 10, 2, 2, 2, ]
]
);

}

is(
is_deeply(
IM->hclip(5)->unpdl,
[
[ 1, 2, 3, 3, 5 ],
Expand All @@ -26,7 +25,7 @@ is(
'hclip'
);

is(
is_deeply(
IM->lclip(5)->unpdl,
[
[ 5, 5, 5, 5, 5 ],
Expand All @@ -38,7 +37,7 @@ is(
'lclip'
);

is(
is_deeply(
IM->clip( 5, 7 )->unpdl,
[
[ 5, 5, 5, 5, 5 ],
Expand All @@ -56,7 +55,7 @@ subtest 'with NaN badvalue' => sub {
$im->badflag(1);
$im->set( 1, nan() );
my $clipped = $im->lclip(0);
is $clipped->unpdl, [0, 'BAD', 2], 'ISBAD() works when badvalue is NaN';
is_deeply $clipped->unpdl, [0, 'BAD', 2], 'ISBAD() works when badvalue is NaN';
};

done_testing;
15 changes: 5 additions & 10 deletions t/primitive/interpolate.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;
use Test2::V0 '!float';

use Test::More;
use Test::Exception;
use PDL::LiteF;

subtest interpol => sub {
Expand All @@ -19,17 +19,12 @@ subtest interpol => sub {
my $x = PDL->new(-2);


# this is really awkward, but can be fixed. Test2::V0's is()
# is very strict when comparing objects, Test2::PDL's functionality
# could be brought in.
ok( all( $x->interpol( $xvalues, $yvalues ) == ( -16 - 16 * i ) ),
"result" );

like(
dies { $x->interpol( $xvalues * i(), $yvalues ) },
throws_ok { $x->interpol( $xvalues * i(), $yvalues ) }
qr/must be real/,
"x must be real"
);
"x must be real";
};

};
Expand All @@ -41,7 +36,7 @@ subtest interpND => sub {
->reorder( 2, 0, 1 );
my $z = 73 + xvals( 5, 5 ) * 0.25 + 2.5 * yvals( 5, 5 );
my $y;
ok( lives { $y = $x->interpND($index) }, 'interpND' ) or diag $@;
lives_ok { $y = $x->interpND($index) } 'interpND';
ok !any( $y != $z ), "result";
};

Expand Down
14 changes: 6 additions & 8 deletions t/primitive/matmult.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;
use Test2::V0 '!float';

use Test::More;
use Test::Exception;
use PDL::LiteF;
use lib 't/lib';
use My::Test::Primitive;
Expand All @@ -27,7 +27,7 @@ subtest 'complex' => sub {
my $cm1 = pdl('1 1+i 1');
my $cm2 = pdl('2 3 i')->transpose;
ok tapprox( $cm1 x $cm2, pdl('[[5+4i]]') ), 'complex matmult';
like dies { scalar $cm1->transpose x $cm2 },
throws_ok { scalar $cm1->transpose x $cm2 }
qr/mismatch/,
'good error on mismatch matmult';
};
Expand Down Expand Up @@ -67,13 +67,11 @@ subtest 'output = ones(2,3)' => sub {
ok tapprox( EQ() x PB(), pdl( [ [ 2, 6 ] ] ) ), '([4x1] x [2x4] -> [1x2])';

# Check dimensional exception: mismatched dims should throw an error
like(
dies {
throws_ok {
PB() x EQ();
},
}
qr/mismatch in matmult/,
'[2x4] x [4x1] --> error (2 != 1)'
);
'[2x4] x [4x1] --> error (2 != 1)';

ok tapprox( PB() x 2, PB() * 2, 'ndarray x Perl scalar' );

Expand Down
4 changes: 2 additions & 2 deletions t/primitive/misc.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test2::V0 '!float';
use Test::More;
use PDL::LiteF;
use PDL::Types;

Expand Down Expand Up @@ -46,7 +46,7 @@ subtest glue => sub {
my $y = yvals( 2, 2, 2 );
my $c = zvals( 2, 2, 2 );

is $x->glue( 1, $y, $c )->unpdl,
is_deeply $x->glue( 1, $y, $c )->unpdl,
[
[ [ 0, 1 ], [ 0, 1 ], [ 0, 0 ], [ 1, 1 ], [ 0, 0 ], [ 0, 0 ] ],
[ [ 0, 1 ], [ 0, 1 ], [ 0, 0 ], [ 1, 1 ], [ 1, 1 ], [ 1, 1 ] ]
Expand Down
16 changes: 7 additions & 9 deletions t/primitive/random.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use strict;
use warnings;
use Test2::V0 '!float';

use Test::More;
use Test::Exception;
use PDL::LiteF;
use lib 't/lib';
use My::Test::Primitive;

todo 'Some CPAN Testers fails for OpenBSD' => sub {
TODO: { local $TODO = 'Some CPAN Testers fails for OpenBSD'; subtest 'random' => sub {

# check that our random functions work with Perl's srand
# local $TODO = ;
Expand All @@ -26,21 +26,19 @@ todo 'Some CPAN Testers fails for OpenBSD' => sub {
my $r2 = grandom 10;
ok( tapprox( $r1, $r2 ), "grandom and srand" );
};
};
}; }

subtest 'types' => sub {

subtest 'random' => sub {
my $type;
ok( lives { $type = random()->type }, 'random()' )
or note $@;
lives_ok { $type = random()->type } 'random()';
is( $type, 'double', 'defaults to double' );
};

subtest 'randsym' => sub {
my $type;
ok( lives { $type = randsym()->type }, 'randsym()' )
or note $@;
lives_ok { $type = randsym()->type } 'randsym()';
is( $type, 'double', 'defaults to double' );

};
Expand All @@ -49,7 +47,7 @@ subtest 'types' => sub {
subtest 'regressions' => sub {

# Test some operations with empty ndarrays
ok lives { random( 1, 1, 0 )->type }, 'empty ndarray'; # used to segfault
lives_ok { random( 1, 1, 0 )->type } 'empty ndarray'; # used to segfault
};

done_testing;
26 changes: 13 additions & 13 deletions t/primitive/selector.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;
use Test2::V0 '!float';

use Test::More;
use Test::Exception;
use PDL::LiteF;

use lib 't/lib';
Expand Down Expand Up @@ -29,15 +29,15 @@ subtest 'where' => sub {

subtest 'whereND' => sub {

is( [ zeroes( 2, 3, 1 )->whereND( pdl '0 0' )->dims ], [ 0, 3, 1 ] );
is_deeply( [ zeroes( 2, 3, 1 )->whereND( pdl '0 0' )->dims ], [ 0, 3, 1 ] );

is( [ zeroes( 2, 0 )->whereND( pdl '1 1' )->dims ], [ 2, 0 ] );
is_deeply( [ zeroes( 2, 0 )->whereND( pdl '1 1' )->dims ], [ 2, 0 ] );

subtest '1D' => sub {
my $x = sequence( 4, 3, 2 );
my $y = pdl( 0, 1, 1, 0 );
my $c = whereND( $x, $y );
is( [ $c->dims ], [ 2, 3, 2 ] );
is_deeply( [ $c->dims ], [ 2, 3, 2 ] );
ok tapprox(
$c, pdl q[[[1 2] [5 6] [9 10]] [[13 14] [17 18] [21 22]]]
),
Expand All @@ -49,7 +49,7 @@ subtest 'where' => sub {
my $y = pdl q[ 0 0 1 1 ; 0 1 0 0 ; 1 0 0 0 ];

my $c = whereND( $x, $y );
is( [ $c->dims ], [ 4, 2 ] );
is_deeply( [ $c->dims ], [ 4, 2 ] );
ok tapprox( $c, pdl q[ 2 3 5 8 ; 14 15 17 20 ] ), "[4,3]";
};

Expand All @@ -65,7 +65,7 @@ subtest 'where' => sub {
# Make sure whereND functions as an lvalue:
my $x = sequence( 4, 3 );
my $y = pdl( 0, 1, 1, 1 );
ok( lives { $x->whereND($y) *= -1 }, 'lvalue multiply' );
lives_ok { $x->whereND($y) *= -1 } 'lvalue multiply';
ok( all( $x->slice("1:-1") < 0 ), 'works' );
};

Expand Down Expand Up @@ -118,7 +118,7 @@ subtest 'which' => sub {
my $r = xvals( 10, 10 ) + 10 * yvals( 10, 10 );
my $x = whichND( $r % 12 == 0 );

is(
is_deeply(
$x->unpdl,
[
[ 0, 0 ], [ 2, 1 ], [ 4, 2 ], [ 6, 3 ],
Expand All @@ -133,7 +133,7 @@ subtest 'which' => sub {
my $r = xvals( 10, 10 ) + 10 * yvals( 10, 10 );
my $x = whichND( $r * 0 );
is $x->nelem, 0, "whichND( 0*\$r ) gives an Empty PDL";
is( [ $x->dims ], [ 2, 0 ], "whichND( 0*\$r ) is 2x0" );
is_deeply( [ $x->dims ], [ 2, 0 ], "whichND( 0*\$r ) is 2x0" );
is $x->type, 'indx', "whichND( 0*\$r) type is indx";
};

Expand All @@ -147,7 +147,7 @@ subtest 'which' => sub {
subtest 'Scalar empty case returns a 1-D vector of size 0' => sub {
my $x = whichND( pdl(0) );
is $x->nelem, 0, "whichND of 0 scalar is empty";
is [ $x->dims ], [0], "whichND of 0 scalar: return 0 dim size is 0";
is_deeply [ $x->dims ], [0], "whichND of 0 scalar: return 0 dim size is 0";
is $x->type, 'indx',
"returns indx-type ndarray for scalar empty case";
};
Expand All @@ -160,13 +160,13 @@ subtest 'which' => sub {

subtest 'whichND(Empty[2x0x2]) should return Empty[3x0]' => sub {
my $y = whichND( zeroes( 2, 0, 2 ) );
is [ $y->dims ], [ 3, 0 ];
is_deeply [ $y->dims ], [ 3, 0 ];
};

subtest 'regression' => sub {
my $r = zeroes( 7, 7 );
$r->set( 3, 4, 1 );
is( $r->whichND->unpdl, [ [ 3, 4 ] ], 'was failing on 32-bit' );
is_deeply( $r->whichND->unpdl, [ [ 3, 4 ] ], 'was failing on 32-bit' );
};

subtest 'torture test' => sub {
Expand All @@ -191,7 +191,7 @@ subtest 'uniqind' => sub {

my $x = pdl( [ 0, 1, 2, 2, 0, 1 ] );
my $y = $x->uniqind;
is( $y->unpdl, [ 0, 1, 3 ] );
is_deeply( $y->unpdl, [ 0, 1, 3 ] );
is $y->ndims, 1, "uniqind";

subtest 'SF bug 3076570' => sub {
Expand Down
2 changes: 1 addition & 1 deletion t/primitive/setops.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test2::V0 '!float';
use Test::More;

use PDL::LiteF;
use lib 't/lib';
Expand Down
2 changes: 1 addition & 1 deletion t/primitive/stats.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test2::V0 '!float';
use Test::More;

use PDL::LiteF;
use lib 't/lib';
Expand Down
Loading

0 comments on commit d569b25

Please sign in to comment.