blib/lib/Game/Go/Notation.pm

filter: Statementstmt 100% 57 / 57 Branchbran 81.2% 26 / 32 Conditioncond 54.2% 19 / 35 MC/DCmcdc 26.3% 5 / 19 Subroutinesub 100% 13 / 13 Podpod 100% 7 / 7 totaltotal 77.9% 127 / 163 CC 31 SCAR 18.5
CC
31
Cov
82%
to_sgf
13.1
to_human
7.4
from_human
7.0
CRAP 6.4
« blib/lib/Game/Go.pm ↑ Summary blib/lib/Game/Go/Move.pm »
1 package Game::Go::Notation;
2  
3 5 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 5 ▶use Game::Go::Rules;
Subroutine __ANON__: called CC=1 SCAR=0.0
8  
9 5 our $VERSION = '0.03';
10  
11 5 our @HUMAN_COLS;
12 5 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
13 5 @HUMAN_COLS = grep { $_ ne 'I' } ('A' .. 'Z');
14 }
15  
16 5 our %HUMAN_INDEX;
17 5 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
18 5 $HUMAN_INDEX{ $HUMAN_COLS[$_] } = $_ for 0 .. $#HUMAN_COLS;
19 }
20  
21 1570 ▶sub col_letter { $HUMAN_COLS[ $_[-1] ] }
Subroutine col_letter: called CC=1 SCAR=0.0
Pod documented
22  
23 664 ▶sub letter_col {
Subroutine letter_col: called CC=3 SCAR=11.1
Pod documented
24 664 ▶ my $letter = uc($_[-1] // '');
Condition50%1/2
$_[-1] // ""
l!l
6640
MC/DC0%0/1
$_[-1] // ""
$_[-1]
Truth table50%1/2
A
A= $_[-1]
Aresult
11
00
25 664 ▶ return exists $HUMAN_INDEX{$letter} ? $HUMAN_INDEX{$letter} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $Game::Go::Notation::HUMAN_INDEX{$letter} ? : 662 2 664
26 }
27  
28 811 ▶sub to_human {
Subroutine to_human: called CC=7 SCAR=20.0
Pod documented
29 811 my ($size, $col, $row) = @_[-3, -2, -1];
30 811 ▶ return undef unless defined $col && defined $row;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col and defined $row 0 811 811
Condition33%1/3
defined $col and defined $row
!ll&&!rl&&r
00811
MC/DC0%0/2
defined $col and defined $row
defined $col defined $row
Truth table33%1/3
A and B
A= defined $colB= defined $row
ABresult
0X0
100
111
31 811 ▶ return undef if $col < 0 || $row < 0 || $col >= $size || $row >= $size;
Branch: 1 branch
BranchTrueFalseTotal
if $col < 0 or $row < 0 or $col >= $size or $row >= $size 9 802 811
Condition88%8/9
$col < 0 or $row < 0 or $col >= $size or $row >= $size
l!l&&r!l&&!r
63802
$col < 0 or $row < 0 or $col >= $size
l!l&&r!l&&!r
33805
$col < 0 or $row < 0
l!l&&r!l&&!r
30808
MC/DC75%3/4
$col < 0 or $row < 0 or $col >= $size or $row >= $size
$col < 0 $row < 0 $col >= $size $row >= $size
Truth table80%4/5
A or B or C or D
A= $col < 0B= $row < 0C= $col >= $sizeD= $row >= $size
ABCDresult
1XXX1
01XX1
001X1
00011
00000
32 802 return $HUMAN_COLS[$col] . ($size - $row);
33 }
34  
35 993 ▶sub from_human {
Subroutine from_human: called CC=7 SCAR=19.5
Pod documented
36 993 my ($size, $name) = @_[-2, -1];
37 993 ▶ return () unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 993 993
38 993 my ($letter, $number) = $name =~ /\A\s*([A-Za-z])\s*([0-9]+)\s*\z/;
39 993 ▶ return () unless defined $letter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $letter 337 656 993
40  
41 656 my $col = letter_col($letter);
42 656 ▶ return () unless defined $col;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col 1 655 656
43 655 ▶ return () if $col >= $size;
Branch: 1 branch
BranchTrueFalseTotal
if $col >= $size 4 651 655
44 651 ▶ return () if $number < 1 || $number > $size;
Branch: 1 branch
BranchTrueFalseTotal
if $number < 1 or $number > $size 4 647 651
Condition66%2/3
$number < 1 or $number > $size
l!l&&r!l&&!r
04647
MC/DC50%1/2
$number < 1 or $number > $size
$number < 1 $number > $size
Truth table66%2/3
A or B
A= $number < 1B= $number > $size
ABresult
1X1
011
000
45  
46 647 return ($col, $size - $number);
47 }
48  
49 801 ▶sub to_sgf {
Subroutine to_sgf: called CC=7 SCAR=25.7
Pod documented
50 801 my ($size, $col, $row) = @_[-3, -2, -1];
51 801 ▶ return undef unless defined $col && defined $row;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col and defined $row 0 801 801
Condition33%1/3
defined $col and defined $row
!ll&&!rl&&r
00801
MC/DC0%0/2
defined $col and defined $row
defined $col defined $row
Truth table33%1/3
A and B
A= defined $colB= defined $row
ABresult
0X0
100
111
52 801 ▶ return undef if $col < 0 || $row < 0 || $col >= $size || $row >= $size;
Branch: 1 branch
BranchTrueFalseTotal
if $col < 0 or $row < 0 or $col >= $size or $row >= $size 0 801 801
Condition33%3/9
$col < 0 or $row < 0 or $col >= $size or $row >= $size
l!l&&r!l&&!r
00801
$col < 0 or $row < 0 or $col >= $size
l!l&&r!l&&!r
00801
$col < 0 or $row < 0
l!l&&r!l&&!r
00801
MC/DC0%0/4
$col < 0 or $row < 0 or $col >= $size or $row >= $size
$col < 0 $row < 0 $col >= $size $row >= $size
Truth table20%1/5
A or B or C or D
A= $col < 0B= $row < 0C= $col >= $sizeD= $row >= $size
ABCDresult
1XXX1
01XX1
001X1
00011
00000
53 801 return chr(ord('a') + $col) . chr(ord('a') + $row);
54 }
55  
56 628 ▶sub from_sgf {
Subroutine from_sgf: called CC=5 SCAR=16.2
Pod documented
57 628 my ($size, $text) = @_[-2, -1];
58 628 ▶ return () unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 628 628
59 628 ▶ return () unless $text =~ /\A([a-z])([a-z])\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\A([a-z])([a-z])\z/ 1 627 628
60  
61 627 my ($col, $row) = (ord($1) - ord('a'), ord($2) - ord('a'));
62 627 ▶ return () if $col >= $size || $row >= $size;
Branch: 1 branch
BranchTrueFalseTotal
if $col >= $size or $row >= $size 4 623 627
Condition66%2/3
$col >= $size or $row >= $size
l!l&&r!l&&!r
40623
MC/DC50%1/2
$col >= $size or $row >= $size
$col >= $size $row >= $size
Truth table66%2/3
A or B
A= $col >= $sizeB= $row >= $size
ABresult
1X1
011
000
63 623 return ($col, $row);
64 }
65  
66 1 ▶sub transcript {
Subroutine transcript: called CC=6 SCAR=18.1
Pod documented
67 1 my ($game) = @_;
68 1 my @out;
69 1 for my $e (@{ $game->log }) {
70 4 ▶ my $who = Game::Go::Rules::from_letter($e->{actor}) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $who = Game::Go::Rules::from_letter($e->{"actor"}) or next 3 1 4
71 3 my $name = Game::Go::Rules::colour_name($who);
72 3 ▶ if ($e->{kind} eq 'pass') { push @out, "$name pass"; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"kind"} eq "pass") 1 2 3
73 2 ▶ next unless $e->{kind} eq 'play' || $e->{kind} eq 'handicap';
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"kind"} eq "play" or $e->{"kind"} eq "handicap" 0 2 2
Condition33%1/3
$e->{"kind"} eq "play" or $e->{"kind"} eq "handicap"
l!l&&r!l&&!r
200
MC/DC0%0/2
$e->{"kind"} eq "play" or $e->{"kind"} eq "handicap"
$e->{"kind"} eq "play" $e->{"kind"} eq "handicap"
Truth table33%1/3
A or B
A= $e->{"kind"} eq "play"B= $e->{"kind"} eq "handicap"
ABresult
1X1
011
000
74 2 my ($col, $row) = $game->col_row($e->{payload}{pt});
75 2 push @out, "$name " . to_human($game->size, $col, $row);
76 }
77 1 return \@out;
78 }
79  
80 5 1;
81  
82 __END__
« blib/lib/Game/Go.pm ↑ Summary blib/lib/Game/Go/Move.pm »