File Coverage

lib/Algorithm/MasterMind/Test_Solver.pm
Criterion Covered Total %
statement 21 40 52.5
branch n/a
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 29 49 59.1


line stmt bran cond sub pod time code
1             package Algorithm::MasterMind::Test_Solver;
2              
3 2     2   1327 use warnings;
  2         3  
  2         89  
4 2     2   12 use strict;
  2         5  
  2         85  
5 2     2   11 use Carp;
  2         3  
  2         142  
6              
7 2     2   11 use lib qw(../../lib ../../../lib);
  2         3  
  2         11  
8              
9             our $VERSION = sprintf "%d.%03d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/g;
10              
11 2     2   508 use base 'Exporter';
  2         3  
  2         177  
12 2     2   11 use Algorithm::MasterMind qw(check_combination);
  2         2  
  2         104  
13              
14 2     2   11 use Test::More;
  2         3  
  2         26  
15              
16             our @EXPORT_OK = qw( solve_mastermind );
17              
18             sub solve_mastermind {
19 0     0 1   my $solver = shift;
20 0           my $secret_code = shift;
21 0           my $length = length( $secret_code );
22 0           my %played;
23 0           my $first_string = $solver->issue_first;
24 0           $played{$first_string} = 1;
25 0           diag( "This might take a while while it finds the code $secret_code" );
26 0           is( length( $first_string), $length, 'Issued first '. $first_string );
27 0           $solver->feedback( check_combination( $secret_code, $first_string) );
28 0           my $played_string = $solver->issue_next;
29 0           my $played = 2;
30 0           while ( $played_string ne $secret_code ) {
31 0           is( $played{ $played_string}, undef, 'Playing '. $played_string ) ;
32 0           $played{$played_string} = 1;
33             # my (%combinations, %fitness);
34             # map ( $combinations{$_->{'_str'}}++, @{$solver->{'_pop'}});
35             # map ( $fitness{$_->{'_str'}} = $_->Fitness(), @{$solver->{'_pop'}});
36             # for my $c ( sort {$combinations{$a} <=> $combinations{$b} } keys %combinations ) {
37             # print "$c => $combinations{$c} $fitness{$c}\n" if $combinations{$c}>1 ;
38             # }
39 0           $solver->feedback( check_combination( $secret_code, $played_string) );
40 0           $played_string = $solver->issue_next;
41 0           $played ++;
42             }
43 0           is( $played_string, $secret_code, "Found code after ".$solver->evaluated()." combinations" );
44 0           return [$solver->evaluated(), $played];
45             }
46              
47             "some blacks, all white"; # Magic true value required at end of module
48              
49             __END__