Reversi/Move.pm

filter: Statementstmt 95.0% 38 / 40 Branchbran 90.0% 9 / 10 Conditioncond 69.2% 18 / 26 MC/DCmcdc 46.6% 7 / 15 Subroutinesub 90.0% 9 / 10 Podpod 83.3% 5 / 6 totaltotal 80.3% 86 / 107 CC 16 SCAR 23.3
CC
16
Cov
86%
BUILD
16.3
turned
2.0
stringify
2.0
CRAP 10.3
« Reversi.pm ↑ Summary Reversi/Board.pm »
1 package Game::Reversi::Move;
2  
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 18 ▶use Game::Reversi::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 18 our $VERSION = '0.04';
11  
12 has phase => (
13 is => 'ro',
14 isa => Str
15 18 );
16  
17 has square => (
18 is => 'ro',
19 isa => Int
20 18 );
21  
22 has colour => (
23 is => 'ro',
24 isa => Str
25 18 );
26  
27 has flips => (
28 is => 'ro',
29 isa => ArrayRef
30 18 );
31  
32 203597 ▶sub BUILD {
Subroutine BUILD: called CC=15 SCAR=27.9
Pod undocumented
33 203597 my ($self) = @_;
34 203597 ▶ my $phase = $self->phase // '';
Condition50%1/2
$self->phase // ""
l!l
2035970
MC/DC0%0/1
$self->phase // ""
$self->phase
Truth table50%1/2
A
A= $self->phase
Aresult
11
00
35 203597 ▶ die "Game::Reversi::Move: phase must be place or play, not '$phase'"
Branch: 1 branch
BranchTrueFalseTotal
unless $phase eq "place" or $phase eq "play" 0 203597 203597
Condition66%2/3
$phase eq "place" or $phase eq "play"
l!l&&r!l&&!r
14472021500
MC/DC0%0/2
$phase eq "place" or $phase eq "play"
$phase eq "place" $phase eq "play"
Truth table66%2/3
A or B
A= $phase eq "place"B= $phase eq "play"
ABresult
1X1
011
000
36 unless $phase eq 'place' || $phase eq 'play';
37  
38 203597 ▶ my $colour = $self->colour // '';
Condition50%1/2
$self->colour // ""
l!l
2035970
MC/DC0%0/1
$self->colour // ""
$self->colour
Truth table50%1/2
A
A= $self->colour
Aresult
11
00
39 203597 ▶ die "Game::Reversi::Move: colour must be b or w, not '$colour'"
Branch: 1 branch
BranchTrueFalseTotal
unless $colour eq "b" or $colour eq "w" 1 203596 203597
Condition100%3/3
$colour eq "b" or $colour eq "w"
l!l&&r!l&&!r
104357992391
MC/DC100%2/2
$colour eq "b" or $colour eq "w"
$colour eq "b" $colour eq "w"
Truth table100%3/3
A or B
A= $colour eq "b"B= $colour eq "w"
ABresult
1X1
011
000
40 unless $colour eq 'b' || $colour eq 'w';
41  
42 203596 my $square = $self->square;
43 203596 ▶ die 'Game::Reversi::Move: square must be 0 to 63'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $square and $square =~ /\A\d+\z/ and $square < 64 1 203595 203596
Condition50%3/6
defined $square and $square =~ /\A\d+\z/ and $square < 64
!ll&&!rl&&r
01203595
defined $square and $square =~ /\A\d+\z/
!ll&&!rl&&r
00203596
MC/DC33%1/3
defined $square and $square =~ /\A\d+\z/ and $square < 64
defined $square $square =~ /\A\d+\z/ $square < 64
Truth table50%2/4
A and B and C
A= defined $squareB= $square =~ /\A\d+\z/C= $square < 64
ABCresult
0XX0
10X0
1100
1111
44 unless defined $square && $square =~ /\A\d+\z/ && $square < 64;
45  
46 203595 ▶ my $flips = $self->flips || [];
Condition50%1/2
$self->flips || []
l!l
2035950
MC/DC0%0/1
$self->flips || []
$self->flips
Truth table50%1/2
A
A= $self->flips
Aresult
11
00
47 203595 ▶ die 'Game::Reversi::Move: a placement flips nothing'
Branch: 1 branch
BranchTrueFalseTotal
if $phase eq "place" and @$flips 1 203594 203595
Condition100%3/3
$phase eq "place" and @$flips
!ll&&!rl&&r
20215014441
MC/DC100%2/2
$phase eq "place" and @$flips
$phase eq "place" @$flips
Truth table100%3/3
A and B
A= $phase eq "place"B= @$flips
ABresult
0X0
100
111
48 if $phase eq 'place' && @$flips;
49 203594 ▶ die 'Game::Reversi::Move: a play flips at least one disc'
Branch: 1 branch
BranchTrueFalseTotal
if $phase eq "play" and not @$flips 1 203593 203594
Condition100%3/3
$phase eq "play" and not @$flips
!ll&&!rl&&r
14442021491
MC/DC100%2/2
$phase eq "play" and not @$flips
$phase eq "play" not @$flips
Truth table100%3/3
A and not(B)
A= $phase eq "play"B= not @$flips
ABresult
0X0
100
111
50 if $phase eq 'play' && !@$flips;
51  
52 203593 return $self;
53 }
54  
55 1446 ▶sub place {
Subroutine place: called CC=1 SCAR=0.0
Pod documented
56 1446 my ($class, $square, $colour) = @_;
57 1446 return $class->new(
58 phase => 'place', square => $square, colour => $colour, flips => []);
59 }
60  
61 202150 ▶sub play {
Subroutine play: called CC=1 SCAR=0.0
Pod documented
62 202150 my ($class, $square, $colour, @flips) = @_;
63 202150 return $class->new(
64 phase => 'play', square => $square, colour => $colour, flips => [ @flips ]);
65 }
66  
67 327 ▶sub name { my ($self) = @_; return Game::Reversi::Board->name_of($self->square) }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
68  
69 755 ▶sub turned { my ($self) = @_; return scalar @{ $self->flips || [] } }
Subroutine turned: called CC=2 SCAR=7.1
Pod documented
Condition50%1/2
$self->flips || []
l!l
7550
MC/DC0%0/1
$self->flips || []
$self->flips
Truth table50%1/2
A
A= $self->flips
Aresult
11
00
70  
71 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
72 0 my ($self) = @_;
73 0 return $self->name;
74 }
75  
76 18 1;
77  
78 __END__
« Reversi.pm ↑ Summary Reversi/Board.pm »