blib/lib/Game/Mahjong/Decompose.pm

filter: Statementstmt 100% 33 / 33 Branchbran 83.3% 5 / 6 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 98.0% 51 / 52 CC 7 SCAR 12.4
CC
7
Cov
98%
decompose
6.0
waits
2.0
BEGIN
1.0
CRAP 3.5
« blib/lib/Game/Mahjong/Wall.pm ↑ Summary blib/lib/Game/Mahjong/Hand.pm »
1 package Game::Mahjong::Decompose;
2  
3 34 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 34 ▶use Game::Mahjong::Tiles;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 34 our $VERSION = '0.02';
10  
11 34 our %FORM = (
12 1 => 'standard',
13 2 => 'seven_pairs',
14 3 => 'thirteen_orphans',
15 4 => 'honours_knitted',
16 5 => 'knitted_straight',
17 );
18  
19 25080 ▶sub decompose {
Subroutine decompose: called CC=6 SCAR=17.9
Pod documented
20 25080 my ($hand, $winning) = @_;
21 25080 ▶ my $splits = _decompose($hand->counts, $hand->meld_count, $winning // 0);
Condition100%2/2
$winning // 0
l!l
2501070
MC/DC100%1/1
$winning // 0
$winning
Truth table100%2/2
A
A= $winning
Aresult
11
00
22 25080 ▶ die 'Game::Mahjong::Decompose: more splits than the table holds' unless defined $splits;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $splits 0 25080 25080
23  
24 my @melded = map {
25 {
26 kind => $_->kind,
27 7524 ▶ tiles => [ @{ $_->tiles } ],
Branch: 1 branch
BranchTrueFalseTotal
$_->concealed ? : 219 7305 7524
28 concealed => $_->concealed ? 1 : 0,
29 melded => 1,
30 }
31 25080 } @{ $hand->melds };
32  
33 25080 for my $split (@$splits) {
34 2199 $_->{concealed} = 1, $_->{melded} = 0 for @{ $split->{sets} };
35 2199 push @{ $split->{sets} }, @melded;
36 }
37 25080 return @$splits;
38 }
39  
40 18 ▶sub is_complete {
Subroutine is_complete: called CC=1 SCAR=0.0
Pod documented
41 18 my ($hand) = @_;
42 18 return _is_complete($hand->counts, $hand->meld_count);
43 }
44  
45 38621 ▶sub waits {
Subroutine waits: called CC=2 SCAR=6.9
Pod documented
46 38621 my ($hand) = @_;
47 38621 ▶ die 'Game::Mahjong::Decompose: waits are asked of a hand between turns, not of one holding a fourteenth'
Branch: 1 branch
BranchTrueFalseTotal
unless $hand->total == 13 1 38620 38621
48 unless $hand->total == 13;
49 38620 return @{ _waits($hand->counts, $hand->meld_count) };
50 }
51  
52 34 1;
53  
54 __END__
« blib/lib/Game/Mahjong/Wall.pm ↑ Summary blib/lib/Game/Mahjong/Hand.pm »