Games-Solitaire-BlackHole-Solver
view release on metacpan or search on metacpan
t/lib/Games/Solitaire/BlackHole/Test.pm view on Meta::CPAN
package Games::Solitaire::BlackHole::Test;
use strict;
use warnings;
use Test::More;
use Dir::Manifest::Slurp qw/ as_lf /;
use Test::Differences qw/ eq_or_diff /;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [qw( _test_multiple_verdict_lines )] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
require Exporter;
# We intend this test subroutine to be used by more than one
# subproject.
sub _test_multiple_verdict_lines
{
my %is_verdict_line = map { $_ => 1, }
( "Solved!", "Unsolved!", "Exceeded max_iters_limit !" );
my ($args) = @_;
my ( $name, $expected_files_checks, $want, $input_lines ) =
@{$args}{qw/ name expected_files_checks expected_results input_lines/};
local $Test::Builder::Level = $Test::Builder::Level + 1;
return subtest $name => sub {
plan tests => 2;
$input_lines =
[ map { my $l = as_lf($_); chomp $l; $l } @$input_lines ];
my @matches;
my $deal_idx = 0;
while (@$input_lines)
{
my $dealstart = shift @$input_lines;
my ($fn) = $dealstart =~ /^\[\= Starting file (\S+) \=\]$/ms
or die "cannot match";
if ( not $expected_files_checks->( $deal_idx, $fn ) )
{
die "filename check";
}
my $dealverdict = shift @$input_lines;
if ( $is_verdict_line{$dealverdict} )
{
push @matches, $dealverdict;
}
else
{
die "mismatch";
}
my $at_most_num_cards__line = 0;
if ( @$input_lines
and $input_lines->[0] =~
/^At most (?:(?:0)|(?:[1-9][0-9]*)) cards could be played\.\z/ms
)
{
$at_most_num_cards__line = 1;
shift @$input_lines;
}
my $traversed_states_count__line = 0;
if ( @$input_lines
and $input_lines->[0] =~
/^Total number of states checked is (?:(?:0)|(?:[1-9][0-9]*))\.\z/ms,
)
{
$traversed_states_count__line = 1;
shift @$input_lines;
}
my $generated_states_count__line = 0;
if ( @$input_lines
( run in 1.666 second using v1.01-cache-2.11-cpan-364913b4093 )