Verify/App/CmdLine/Expand.pm

filter: Statementstmt 30.0% 24 / 80 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 43.7% 7 / 16 Podpod 100% 1 / 1 totaltotal 26.2% 32 / 122 CC 12 SCAR 20.6
CC
12
Cov
23%
run
20.0
_init
12.0
__ANON__
12.0
CRAP 7.8
« Verify/App/CmdLine/From_ShirlHartSolver.pm ↑ Summary Verify/App/CmdLine.pm »
1 package Games::Solitaire::Verify::App::CmdLine::Expand;
2 2 $Games::Solitaire::Verify::App::CmdLine::Expand::VERSION = '0.2601';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use parent 'Games::Solitaire::Verify::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Data::Dumper qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Games::Solitaire::Verify::VariantsMap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Games::Solitaire::Verify::Solution::ExpandMultiCardMoves ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 __PACKAGE__->mk_acc_ref(
16 [
17 qw(
18 _filename
19 _variant_params
20 )
21 ]
22 );
23  
24 sub _init
25 0 ▶{
Subroutine _init: not called CC=3 SCAR=24.8
26 0 my ( $self, $args ) = @_;
27  
28 0 my $argv = $args->{'argv'};
29  
30 0 my $variant_map = Games::Solitaire::Verify::VariantsMap->new();
31  
32 0 my $variant_params = $variant_map->get_variant_by_id("freecell");
33  
34 GetOptionsFromArray(
35 $argv,
36 0 ▶ 'g|game|variant=s' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
37 0 my ( undef, $game ) = @_;
38  
39 0 $variant_params = $variant_map->get_variant_by_id($game);
40  
41 0 ▶ if ( !defined($variant_params) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $variant_params) 0 0 0
42 {
43 0 die "Unknown variant '$game'!\n";
44 }
45 },
46 0 ▶ 'freecells-num=i' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 my ( undef, $n ) = @_;
48 0 $variant_params->num_freecells($n);
49 },
50 0 ▶ 'stacks-num=i' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 my ( undef, $n ) = @_;
52 0 $variant_params->num_columns($n);
53 },
54 0 ▶ 'decks-num=i' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
55 0 my ( undef, $n ) = @_;
56  
57 0 ▶ if ( !( ( $n == 1 ) || ( $n == 2 ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($n == 1 or $n == 2) 0 0 0
Condition0%0/3
$n == 1 or $n == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$n == 1 or $n == 2
$n == 1 $n == 2
Truth table0%0/3
A or B
A= $n == 1B= $n == 2
ABresult
1X1
011
000
58 {
59 0 die "Decks should be 1 or 2.";
60 }
61  
62 0 $variant_params->num_decks($n);
63 },
64 0 ▶ 'sequences-are-built-by=s' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
65 0 my ( undef, $val ) = @_;
66  
67 my %seqs_build_by = (
68 0 ( map { $_ => $_ } (qw(alt_color suit rank)) ),
69 "alternate_color" => "alt_color",
70 );
71  
72 0 my $proc_val = $seqs_build_by{$val};
73  
74 0 ▶ if ( !defined($proc_val) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proc_val) 0 0 0
75 {
76 0 die "Unknown sequences-are-built-by '$val'!";
77 }
78  
79 0 $variant_params->seqs_build_by($proc_val);
80 },
81 0 ▶ 'empty-stacks-filled-by=s' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
82 0 my ( undef, $val ) = @_;
83  
84 my %empty_stacks_filled_by_map =
85 0 ( map { $_ => 1 } (qw(kings any none)) );
86  
87 0 ▶ if ( !exists( $empty_stacks_filled_by_map{$val} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $empty_stacks_filled_by_map{$val}) 0 0 0
88 {
89 0 die "Unknown empty stacks filled by '$val'!";
90 }
91  
92 0 $variant_params->empty_stacks_filled_by($val);
93 },
94 0 ▶ 'sequence-move=s' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
95 0 my ( undef, $val ) = @_;
96  
97 0 my %seq_moves = ( map { $_ => 1 } (qw(limited unlimited)) );
98  
99 0 ▶ if ( !exists( $seq_moves{$val} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $seq_moves{$val}) 0 0 0
100 {
101 0 die "Unknown sequence move '$val'!";
102 }
103  
104 0 $variant_params->sequence_move($val);
105 },
106 0 ▶ ) or die "Cannot process command line arguments";
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray($argv, "g|game|variant=s", sub { my(undef, $game) = @_; $variant_params = $variant_map->get_variant_by_id($game); if (not defined $variant_params) { die "Unknown variant '${game}'!\n"; } ; } , "freecells-num=i", sub { my(undef, $n) = @_; $variant_params->num_freecells($n); } , "stacks-num=i", sub { my(undef, $n) = @_; $variant_params->num_columns($n); } , "decks-num=i", sub { my(undef, $n) = @_; unless ($n == 1 or $n == 2) { die "Decks should be 1 or 2."; } ; $variant_params->num_decks($n); } , "sequences-are-built-by=s", sub { my(undef, $val) = @_; my(%seqs_build_by) = (map({$_, $_;} "alt_color", "suit", "rank"), "alternate_color", "alt_color"); my $proc_val = $seqs_build_by{$val}; unless (defined $proc_val) { die "Unknown sequences-are-built-by '${val}'!"; } ; $variant_params->seqs_build_by($proc_val); } , "empty-stacks-filled-by=s", sub { my(undef, $val) = @_; my(%empty_stacks_filled_by_map) = map({$_, 1;} "kings", "any", "none"); unless (exists $empty_stacks_filled_by_map{$val}) { die "Unknown empty stacks filled by '${val}'!"; } ; $variant_params->empty_stacks_filled_by($val); } , "sequence-move=s", sub { my(undef, $val) = @_; my(%seq_moves) = map({$_, 1;} "limited", "unlimited"); unless (exists $seq_moves{$val}) { die "Unknown sequence move '${val}'!"; } ; $variant_params->sequence_move($val); } ) or die "Cannot process command line arguments" 0 0 0
107  
108 0 my $filename = shift(@$argv);
109  
110 0 ▶ if ( !defined($filename) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 0 0 0
111 {
112 0 $filename = "-";
113 }
114  
115 0 $self->_variant_params($variant_params);
116 0 $self->_filename($filename);
117  
118 0 return;
119 }
120  
121 sub run
122 0 ▶{
Subroutine run: not called CC=4 SCAR=30.0
Pod documented
123 0 my $self = shift;
124  
125 0 my $filename = $self->_filename();
126 0 my $variant_params = $self->_variant_params();
127  
128 0 my $fh;
129  
130 0 ▶ if ( $filename eq "-" )
Branch: 1 branch
BranchTrueFalseTotal
if ($filename eq '-') { } 0 0 0
131 {
132 0 $fh = *STDIN;
133 }
134 else
135 {
136 0 ▶ open $fh, "<", $filename
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $filename or die "Cannot open '${filename}' - $!" 0 0 0
137 or die "Cannot open '$filename' - $!";
138 }
139  
140 0 my $solution =
141 Games::Solitaire::Verify::Solution::ExpandMultiCardMoves->new(
142 {
143 input_fh => $fh,
144 variant => "custom",
145 variant_params => $variant_params,
146 output_fh => \*STDOUT,
147 },
148 );
149  
150 0 my $verdict = $solution->verify();
151 0 ▶ if ( !$verdict )
Branch: 1 branch
BranchTrueFalseTotal
if (not $verdict) { } 0 0 0
152 {
153 0 exit(0);
154 }
155 else
156 {
157 0 print STDERR Dumper($verdict);
158 0 print STDERR "Solution is Wrong.\n";
159 0 exit(-1);
160 }
161 }
162  
163 2 1;
164  
165 __END__
« Verify/App/CmdLine/From_ShirlHartSolver.pm ↑ Summary Verify/App/CmdLine.pm »