lib/Games/Checkers/Move.pm

filter: Statementstmt 50.0% 20 / 40 Branchbran 20.0% 2 / 10 Conditioncond 10.0% 1 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 7 totaltotal 33.3% 28 / 84 CC 10 SCAR 23.8
CC
10
Cov
38%
dump
30.0
destin
12.0
new
4.4
CRAP 10.8
« lib/Games/Checkers/ExpandMoveList.pm ↑ Summary lib/Games/Checkers/Iterators.pm »
1 # Games::Checkers, Copyright (C) 1996-2012 Mikhael Goikhman, migo@cpan.org
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 package Games::Checkers::Move;
20  
21 1 ▶use Games::Checkers::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶sub new ($$$$) {
Subroutine new: called CC=4 SCAR=14.8
Pod undocumented
24 1 my $class = shift;
25 1 my ($is_beat, $src, $dsts) = @_;
26  
27 1 ▶ die "Games::Checkers::Move constructor, third arg should be array"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dsts eq "ARRAY" 0 1 1
28 unless ref($dsts) eq 'ARRAY';
29 1 ▶ die "No destinations in Move construction" unless $src == NL || @$dsts;
Branch: 1 branch
BranchTrueFalseTotal
unless $src == &NL() or @$dsts 0 1 1
Condition33%1/3
$src == &NL() or @$dsts
l!l&&r!l&&!r
100
MC/DC0%0/2
$src == &NL() or @$dsts
$src == &NL() @$dsts
Truth table33%1/3
A or B
A= $src == &NL()B= @$dsts
ABresult
1X1
011
000
30 1 my $self = [ $is_beat, $src, [@$dsts] ];
31  
32 1 bless $self, $class;
33 1 return $self;
34 }
35  
36 1 ▶use constant NoMove => Games::Checkers::Move->new(0, NL, []);
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 0 ▶sub num_steps ($) {
Subroutine num_steps: not called CC=1 SCAR=6.9
Pod undocumented
39 0 my $self = shift;
40 0 return scalar @{$self->[2]};
41 }
42  
43 0 ▶sub is_beat ($) {
Subroutine is_beat: not called CC=1 SCAR=6.9
Pod undocumented
44 0 my $self = shift;
45 0 return $self->[0];
46 }
47  
48 0 ▶sub source ($) {
Subroutine source: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my $self = shift;
50 0 return $self->[1];
51 }
52  
53 0 ▶sub destin ($$) {
Subroutine destin: not called CC=3 SCAR=24.8
Pod undocumented
54 0 my $self = shift;
55 0 my $num = shift;
56 0 ▶ return $num < 0 || $num >= @{$self->[2]} ? NL : $self->[2]->[$num];
Branch: 1 branch
BranchTrueFalseTotal
$num < 0 || $num >= @{$self->[2];} ? : 0 0 0
Condition0%0/3
$num < 0 or $num >= @{$self->[2];}
l!l&&r!l&&!r
000
MC/DC0%0/2
$num < 0 or $num >= @{$self->[2];}
$num < 0 $num >= @{$self->[2];}
Truth table0%0/3
A or B
A= $num < 0B= $num >= @{$self->[2];}
ABresult
1X1
011
000
57 }
58  
59 0 ▶sub clone ($) {
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my $self = shift;
61 0 return Games::Checkers::Move->new(@$self);
62 }
63  
64 0 ▶sub dump ($$) {
Subroutine dump: not called CC=5 SCAR=34.0
Pod undocumented
65 0 my $self = shift;
66 0 ▶ my $board = shift || die;
Condition0%0/2
shift() || die()
l!l
00
MC/DC0%0/1
shift() || die()
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
67  
68 0 ▶ my $delim = $self->is_beat ? $::RULES{CAPTURE_SEPARATOR} || ":" : "-";
Branch: 1 branch
BranchTrueFalseTotal
$self->is_beat ? : 0 0 0
Condition0%0/2
$main::RULES{"CAPTURE_SEPARATOR"} or ":"
l!l
00
MC/DC0%0/1
$main::RULES{"CAPTURE_SEPARATOR"} or ":"
$main::RULES{"CAPTURE_SEPARATOR"}
Truth table0%0/2
A
A= $main::RULES{"CAPTURE_SEPARATOR"}
Aresult
11
00
69 0 my $str = $board->loc_to_str($self->source);
70 0 ▶ for (my $i = 0; $i < $self->num_steps; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->num_steps) 0 0 0
71 0 $str .= $delim . $board->loc_to_str($self->destin($i));
72 }
73  
74 0 return $str;
75 }
76  
77 1 1;
« lib/Games/Checkers/ExpandMoveList.pm ↑ Summary lib/Games/Checkers/Iterators.pm »