blib/lib/Game/Sternhalma/Layout.pm

filter: Statementstmt 100% 34 / 34 Branchbran 81.8% 18 / 22 Conditioncond 66.6% 14 / 21 MC/DCmcdc 53.8% 7 / 13 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 83.6% 87 / 104 CC 19 SCAR 20.6
CC
19
Cov
86%
why_not
13.2
home_of
5.2
points
3.2
CRAP 7.8
« blib/lib/Game/Sternhalma.pm ↑ Summary blib/lib/Game/Sternhalma/Engine.pm »
1 package Game::Sternhalma::Layout;
2  
3 31 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 31 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 31 our $VERSION = '0.01';
10  
11 31 our @EXPORT_OK = qw(seat_counts points home_of pieces_ok why_not);
12  
13 # W's layouts. Points are 0 to 5 clockwise from the top tip; seat order is
14 # turn order, which is clockwise too. t/24-layout.t holds this table to the
15 # engine's own.
16 31 my %POINTS = (
17 1 => [0],
18 2 => [0, 3],
19 3 => [0, 2, 4],
20 4 => [0, 1, 3, 4],
21 6 => [0, 1, 2, 3, 4, 5],
22 );
23  
24 1 ▶sub seat_counts { (2, 3, 4, 6) }
Subroutine seat_counts: called CC=1 SCAR=0.0
Pod documented
25  
26 23161 ▶sub points {
Subroutine points: called CC=3 SCAR=11.7
Pod documented
27 23161 my ($seats) = @_;
28 23161 ▶ my $p = defined $seats ? $POINTS{$seats} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $seats ? : 23161 0 23161
29 23161 ▶ return $p ? @$p : ();
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 23161 0 23161
30 }
31  
32 1718 ▶sub home_of {
Subroutine home_of: called CC=4 SCAR=16.4
Pod documented
33 1718 my ($seats, $seat) = @_;
34 1718 my @p = points($seats);
35 1718 ▶ return undef unless defined $seat && $seat =~ /\A[0-9]+\z/ && $seat < @p;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < @p 0 1718 1718
Condition33%2/6
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < @p
!ll&&!rl&&r
001718
defined $seat and $seat =~ /\A[0-9]+\z/u
!ll&&!rl&&r
001718
MC/DC0%0/3
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < @p
defined $seat $seat =~ /\A[0-9]+\z/u $seat < @p
Truth table25%1/4
A and B and C
A= defined $seatB= $seat =~ /\A[0-9]+\z/uC= $seat < @p
ABCresult
0XX0
10X0
1100
1111
36 1718 return ($p[$seat] + 3) % 6;
37 }
38  
39 15 ▶sub pieces_ok {
Subroutine pieces_ok: called CC=2 SCAR=6.9
Pod documented
40 15 my ($seats, $pieces) = @_;
41 15 ▶ return defined why_not($seats, $pieces) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined why_not($seats, $pieces) ? : 7 8 15
42 }
43  
44 # Why a game of that many seats and pieces cannot be, or undef when it can.
45 # One seat is a crossing alone, which a game is not; it is built only on
46 # request (Game::Sternhalma's `solo`).
47 265 ▶sub why_not {
Subroutine why_not: called CC=13 SCAR=25.8
Pod documented
48 265 my ($seats, $pieces, $solo) = @_;
49 265 ▶ return 'the seat count must be a number' unless defined $seats && $seats =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seats and $seats =~ /\A[0-9]+\z/u 3 262 265
Condition66%2/3
defined $seats and $seats =~ /\A[0-9]+\z/u
!ll&&!rl&&r
03262
MC/DC50%1/2
defined $seats and $seats =~ /\A[0-9]+\z/u
defined $seats $seats =~ /\A[0-9]+\z/u
Truth table66%2/3
A and B
A= defined $seatsB= $seats =~ /\A[0-9]+\z/u
ABresult
0X0
100
111
50 262 ▶ return 'the piece count must be a number' unless defined $pieces && $pieces =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pieces and $pieces =~ /\A[0-9]+\z/u 0 262 262
Condition33%1/3
defined $pieces and $pieces =~ /\A[0-9]+\z/u
!ll&&!rl&&r
00262
MC/DC0%0/2
defined $pieces and $pieces =~ /\A[0-9]+\z/u
defined $pieces $pieces =~ /\A[0-9]+\z/u
Truth table33%1/3
A and B
A= defined $piecesB= $pieces =~ /\A[0-9]+\z/u
ABresult
0X0
100
111
51 262 ▶ return 'five cannot play: one seat would have nobody opposite' if $seats == 5;
Branch: 1 branch
BranchTrueFalseTotal
if $seats == 5 7 255 262
52 255 ▶ return 'one seat is a crossing alone, not a game' if $seats == 1 && !$solo;
Branch: 1 branch
BranchTrueFalseTotal
if $seats == 1 and not $solo 3 252 255
Condition100%3/3
$seats == 1 and not $solo
!ll&&!rl&&r
25023
MC/DC100%2/2
$seats == 1 and not $solo
$seats == 1 not $solo
Truth table100%3/3
A and not(B)
A= $seats == 1B= not $solo
ABresult
0X0
100
111
53 252 ▶ return "sternhalma is for 2, 3, 4 or 6 seats, not $seats" unless $POINTS{$seats};
Branch: 1 branch
BranchTrueFalseTotal
unless $POINTS{$seats} 3 249 252
54 249 ▶ return "a seat has 10 pieces, or 15, not $pieces" unless $pieces == 10 || $pieces == 15;
Branch: 1 branch
BranchTrueFalseTotal
unless $pieces == 10 or $pieces == 15 2 247 249
Condition100%3/3
$pieces == 10 or $pieces == 15
l!l&&r!l&&!r
237102
MC/DC100%2/2
$pieces == 10 or $pieces == 15
$pieces == 10 $pieces == 15
Truth table100%3/3
A or B
A= $pieces == 10B= $pieces == 15
ABresult
1X1
011
000
55 247 ▶ return "fifteen pieces cannot sit at $seats seats: neighbouring points would share a hole"
Branch: 1 branch
BranchTrueFalseTotal
if $pieces == 15 and $seats > 3 8 239 247
Condition100%3/3
$pieces == 15 and $seats > 3
!ll&&!rl&&r
23728
MC/DC100%2/2
$pieces == 15 and $seats > 3
$pieces == 15 $seats > 3
Truth table100%3/3
A and B
A= $pieces == 15B= $seats > 3
ABresult
0X0
100
111
56 if $pieces == 15 && $seats > 3;
57 239 return undef;
58 }
59  
60 31 1;
61  
62 __END__
« blib/lib/Game/Sternhalma.pm ↑ Summary blib/lib/Game/Sternhalma/Engine.pm »