Verify/VariantParams.pm

filter: Statementstmt 88.7% 55 / 62 Branchbran 50.0% 7 / 14 Conditioncond 62.5% 5 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 78.1% 75 / 96 CC 11 SCAR 22.9
CC
11
Cov
80%
_init
13.9
BEGIN
1.0
BEGIN
1.0
CRAP 9.9
« Verify/Golf.pm ↑ Summary Verify/App/CmdLine/From_ShirlHartSolver.pm »
1 package Games::Solitaire::Verify::VariantParams;
2 20 $Games::Solitaire::Verify::VariantParams::VERSION = '0.2601';
3 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 20 ▶use parent 'Games::Solitaire::Verify::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 20 ▶use Games::Solitaire::Verify::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 20 __PACKAGE__->mk_acc_ref(
12 [
13 qw(
14 empty_stacks_filled_by
15 num_columns
16 num_decks
17 num_freecells
18 rules
19 seq_build_by
20 sequence_move
21 )
22 ]
23 );
24  
25  
26 20 my %seqs_build_by = ( map { $_ => 1 } (qw(alt_color suit rank)) );
27 20 my %empty_stacks_filled_by_map = ( map { $_ => 1 } (qw(kings any none)) );
28 20 my %seq_moves = ( map { $_ => 1 } (qw(limited unlimited)) );
29 20 my %rules_collection = ( map { $_ => 1 } (qw(freecell simple_simon)) );
30  
31 sub _init
32 603 ▶{
Subroutine _init: called CC=11 SCAR=26.3
33 603 my ( $self, $args ) = @_;
34  
35 # Set the variant
36 #
37  
38 {
39 603 my $seq_build_by = $args->{seq_build_by};
40  
41 603 ▶ if ( !exists( $seqs_build_by{$seq_build_by} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $seqs_build_by{$seq_build_by}) 0 603 603
42 {
43 0 Games::Solitaire::Verify::Exception::VariantParams::Param::SeqBuildBy
44 ->throw(
45 error => "Unrecognised seq_build_by",
46 value => $seq_build_by,
47 );
48 }
49 603 $self->seq_build_by($seq_build_by);
50 }
51  
52 {
53 603 my $esf = $args->{empty_stacks_filled_by};
54  
55 603 ▶ if ( !exists( $empty_stacks_filled_by_map{$esf} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $empty_stacks_filled_by_map{$esf}) 0 603 603
56 {
57 0 Games::Solitaire::Verify::Exception::VariantParams::Param::EmptyStacksFill
58 ->throw(
59 error => "Unrecognised empty_stacks_filled_by",
60 value => $esf,
61 );
62 }
63  
64 603 $self->empty_stacks_filled_by($esf);
65 }
66  
67 {
68 603 my $num_decks = $args->{num_decks};
69  
70 603 ▶ if ( !( ( $num_decks == 1 ) || ( $num_decks == 2 ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($num_decks == 1 or $num_decks == 2) 0 603 603
Condition66%2/3
$num_decks == 1 or $num_decks == 2
l!l&&r!l&&!r
565380
MC/DC0%0/2
$num_decks == 1 or $num_decks == 2
$num_decks == 1 $num_decks == 2
Truth table66%2/3
A or B
A= $num_decks == 1B= $num_decks == 2
ABresult
1X1
011
000
71 {
72 0 Games::Solitaire::Verify::Exception::VariantParams::Param::NumDecks
73 ->throw(
74 error => "Wrong Number of Decks",
75 value => $num_decks,
76 );
77 }
78 603 $self->num_decks($num_decks);
79 }
80  
81 {
82 603 my $num_columns = $args->{num_columns};
83  
84 603 ▶ if ( ( $num_columns =~ /\D/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($num_columns =~ /\D/ or $num_columns == 0) 0 603 603
Condition33%1/3
$num_columns =~ /\D/ or $num_columns == 0
l!l&&r!l&&!r
00603
MC/DC0%0/2
$num_columns =~ /\D/ or $num_columns == 0
$num_columns =~ /\D/ $num_columns == 0
Truth table33%1/3
A or B
A= $num_columns =~ /\D/B= $num_columns == 0
ABresult
1X1
011
000
85 || ( $num_columns == 0 ) )
86 {
87 0 Games::Solitaire::Verify::Exception::VariantParams::Param::Stacks
88 ->throw(
89 error => "num_columns is not a number",
90 value => $num_columns,
91 );
92 }
93 603 $self->num_columns($num_columns)
94 }
95  
96 {
97 603 my $num_freecells = $args->{num_freecells};
98  
99 603 ▶ if ( $num_freecells =~ /\D/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($num_freecells =~ /\D/) 0 603 603
100 {
101 0 Games::Solitaire::Verify::Exception::VariantParams::Param::Freecells
102 ->throw(
103 error => "num_freecells is not a number",
104 value => $num_freecells,
105 );
106 }
107 603 $self->num_freecells($num_freecells);
108 }
109  
110 {
111 603 my $seq_move = $args->{sequence_move};
112  
113 603 ▶ if ( !exists( $seq_moves{$seq_move} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $seq_moves{$seq_move}) 0 603 603
114 {
115 0 Games::Solitaire::Verify::Exception::VariantParams::Param::SeqMove
116 ->throw(
117 error => "Unrecognised sequence_move",
118 value => $seq_move,
119 );
120 }
121  
122 603 $self->sequence_move($seq_move);
123 }
124  
125 {
126 603 ▶ my $rules = $args->{rules} || "freecell";
Condition100%2/2
$args->{'rules'} || 'freecell'
l!l
315288
MC/DC100%1/1
$args->{'rules'} || 'freecell'
$args->{'rules'}
Truth table100%2/2
A
A= $args->{'rules'}
Aresult
11
00
127  
128 603 ▶ if ( !exists( $rules_collection{$rules} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rules_collection{$rules}) 0 603 603
129 {
130 0 Games::Solitaire::Verify::Exception::VariantParams::Param::Rules
131 ->throw(
132 error => "Unrecognised rules",
133 value => $rules,
134 );
135 }
136 603 $self->rules($rules);
137 }
138  
139 603 return 0;
140 }
141  
142  
143  
144 sub clone
145 296 ▶{
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
146 296 my $self = shift;
147  
148 296 return __PACKAGE__->new(
149 {
150 empty_stacks_filled_by => $self->empty_stacks_filled_by(),
151 num_columns => $self->num_columns(),
152 num_decks => $self->num_decks(),
153 num_freecells => $self->num_freecells(),
154 rules => $self->rules(),
155 seq_build_by => $self->seq_build_by(),
156 sequence_move => $self->sequence_move(),
157 }
158 );
159 }
160  
161 20 1;
162  
163 __END__
« Verify/Golf.pm ↑ Summary Verify/App/CmdLine/From_ShirlHartSolver.pm »