Acme-Sort-Bogosort
view release on metacpan or search on metacpan
t/00-load.t view on Meta::CPAN
my $caught;
try {
Acme::Sort::Bogosort::compare( 'A' );
} catch {
$caught = $_;
};
like(
$caught,
qr/requires two/,
"compare() throws exception if given other than two args to compare."
);
note( "Testing Acme::Sort::Bogosort::is_ordered() -- Default ascending order." );
my $compare = \&Acme::Sort::Bogosort::compare;
is(
Acme::Sort::Bogosort::is_ordered( $compare, [ qw/ A B C D E / ] ),
1,
"is_ordered( \&compare, [ qw/ A B C D E / ] ) returns true."
);
t/00-load.t view on Meta::CPAN
"is_ordered( \&compare, [ qw/ E D C B A / ] ) returns false."
);
undef $caught;
try {
Acme::Sort::Bogosort::is_ordered( [ qw/ A B C D E / ] );
} catch { $caught = $_ };
like(
$caught,
qr/expects a coderef/,
"is_ordered() throws exception when not handed a coderef as first param."
);
undef $caught;
try {
Acme::Sort::Bogosort::is_ordered( $compare, qw/ A B C D E / );
} catch { $caught = $_ };
like(
$caught,
qr/expects an arrayref/,
"is_ordered() throws an exception when not handed an arrayref as second param."
);
note "Testing Acme::Sort::Bogosort::bogosort().";
my @unsorted = shuffle( 'A' .. 'E' );
my @sorted = bogosort( @unsorted );
is_deeply(
\@sorted,
[ qw/ A B C D E / ],
"bogosort( qw/ A B C D E / ) - Default sort order returns correct results."
);
( run in 0.353 second using v1.01-cache-2.11-cpan-496ff517765 )