blib/lib/Game/Mahjong/Decompose.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 54 CC 4 SCAR 17.6
CC
4
Cov
0%
decompose
12.0
waits
6.0
is_complete
2.0
CRAP 5.8
1 package Game::Mahjong::Decompose;
2  
3 use 5.010;
4 use strict;
5 use warnings;
6  
7 use Game::Mahjong::Tiles;
8  
9 our $VERSION = '0.04';
10  
11 our %FORM = (
12 1 => 'standard',
13 2 => 'seven_pairs',
14 3 => 'thirteen_orphans',
15 4 => 'honours_knitted',
16 5 => 'knitted_straight',
17 );
18  
19 sub decompose {
20 my ($hand, $winning) = @_;
21 my $splits = _decompose($hand->counts, $hand->meld_count, $winning // 0);
22 die 'Game::Mahjong::Decompose: more splits than the table holds' unless defined $splits;
23  
24 my @melded = map {
25 {
26 kind => $_->kind,
27 tiles => [ @{ $_->tiles } ],
28 concealed => $_->concealed ? 1 : 0,
29 melded => 1,
30 }
31 } @{ $hand->melds };
32  
33 for my $split (@$splits) {
34 $_->{concealed} = 1, $_->{melded} = 0 for @{ $split->{sets} };
35 push @{ $split->{sets} }, @melded;
36 }
37 return @$splits;
38 }
39  
40 sub is_complete {
41 my ($hand) = @_;
42 return _is_complete($hand->counts, $hand->meld_count);
43 }
44  
45 sub waits {
46 my ($hand) = @_;
47 die 'Game::Mahjong::Decompose: waits are asked of a hand between turns, not of one holding a fourteenth'
48 unless $hand->total == 13;
49 return @{ _waits($hand->counts, $hand->meld_count) };
50 }
51  
52 1;
53  
54 __END__