blib/lib/Game/Senet/Sticks.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 16 / 16 Conditioncond 90.4% 19 / 21 MC/DCmcdc 84.6% 11 / 13 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 96.3% 104 / 108 CC 17 SCAR 14.1
CC
17
Cov
97%
extra_throw
6.0
throw_for
6.0
roll_of
4.0
CRAP 4.1
« blib/lib/Game/Senet/Bot.pm ↑ Summary blib/lib/Game/Senet/Rules.pm »
1 package Game::Senet::Sticks;
2  
3 68 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 68 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 68 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 68 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 68 our $VERSION = '0.02';
12  
13 68 our @EXPORT_OK = qw(throw_for light_of roll_of roll_for extra_throw);
14 68 our %EXPORT_TAGS = (all => \@EXPORT_OK);
15  
16 1678334 ▶sub throw_for {
Subroutine throw_for: called CC=6 SCAR=17.9
Pod documented
17 1678334 my ($seed, $n) = @_;
18 1678334 ▶ Carp::croak('Game::Senet::Sticks: throw_for wants a seed')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seed and length $seed 2 1678332 1678334
Condition100%3/3
defined $seed and length $seed
!ll&&!rl&&r
111678332
MC/DC100%2/2
defined $seed and length $seed
defined $seed length $seed
Truth table100%3/3
A and B
A= defined $seedB= length $seed
ABresult
0X0
100
111
19 unless defined $seed && length $seed;
20 1678332 ▶ Carp::croak('Game::Senet::Sticks: a throw number is a non-negative integer')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and $n =~ /\A\d+\z/ 3 1678329 1678332
Condition100%3/3
defined $n and $n =~ /\A\d+\z/
!ll&&!rl&&r
121678329
MC/DC100%2/2
defined $n and $n =~ /\A\d+\z/
defined $n $n =~ /\A\d+\z/
Truth table100%3/3
A and B
A= defined $nB= $n =~ /\A\d+\z/
ABresult
0X0
100
111
21 unless defined $n && $n =~ /\A\d+\z/;
22 1678329 my $bytes = "$seed";
23 1678329 ▶ Carp::croak('Game::Senet::Sticks: a seed is bytes, and that one holds a character above 255')
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::downgrade($bytes, 1) 1 1678328 1678329
24 unless utf8::downgrade($bytes, 1);
25 1678328 my $byte = unpack 'C', Digest::SHA::sha256($bytes . "throw:$n");
26 1678328 return [ map { ($byte >> $_) & 1 } 0 .. 3 ];
27 }
28  
29 1677632 ▶sub light_of {
Subroutine light_of: called CC=4 SCAR=13.9
Pod documented
30 1677632 my ($sticks) = @_;
31 1677632 ▶ Carp::croak('Game::Senet::Sticks: light_of wants the four sticks')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sticks eq "ARRAY" and @$sticks == 4 2 1677630 1677632
Condition100%3/3
ref $sticks eq "ARRAY" and @$sticks == 4
!ll&&!rl&&r
111677630
MC/DC100%2/2
ref $sticks eq "ARRAY" and @$sticks == 4
ref $sticks eq "ARRAY" @$sticks == 4
Truth table100%3/3
A and B
A= ref $sticks eq "ARRAY"B= @$sticks == 4
ABresult
0X0
100
111
32 unless ref $sticks eq 'ARRAY' && @$sticks == 4;
33 1677630 my $count = 0;
34 1677630 $count += $_ for @$sticks;
35 1677630 return $count;
36 }
37  
38 2220511 ▶sub roll_of {
Subroutine roll_of: called CC=4 SCAR=13.9
Pod documented
39 2220511 my ($throw) = @_;
40 2220511 ▶ Carp::croak('Game::Senet::Sticks: a throw is a count of light faces, 0 to 4')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $throw and $throw =~ /\A[0-4]\z/ 1 2220510 2220511
Condition66%2/3
defined $throw and $throw =~ /\A[0-4]\z/
!ll&&!rl&&r
012220510
MC/DC50%1/2
defined $throw and $throw =~ /\A[0-4]\z/
defined $throw $throw =~ /\A[0-4]\z/
Truth table66%2/3
A and B
A= defined $throwB= $throw =~ /\A[0-4]\z/
ABresult
0X0
100
111
41 unless defined $throw && $throw =~ /\A[0-4]\z/;
42 2220510 ▶ return $throw == 0 ? 5 : $throw + 0;
Branch: 1 branch
BranchTrueFalseTotal
$throw == 0 ? : 134495 2086015 2220510
43 }
44  
45 354142 ▶sub roll_for {
Subroutine roll_for: called CC=1 SCAR=0.0
Pod documented
46 354142 my ($seed, $n) = @_;
47 354142 return roll_of(light_of(throw_for($seed, $n)));
48 }
49  
50 818373 ▶sub extra_throw {
Subroutine extra_throw: called CC=6 SCAR=17.9
Pod documented
51 818373 my ($roll) = @_;
52 818373 ▶ Carp::croak('Game::Senet::Sticks: a roll is a number of houses, 1 to 5')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll and $roll =~ /\A[1-5]\z/ 1 818372 818373
Condition66%2/3
defined $roll and $roll =~ /\A[1-5]\z/
!ll&&!rl&&r
01818372
MC/DC50%1/2
defined $roll and $roll =~ /\A[1-5]\z/
defined $roll $roll =~ /\A[1-5]\z/
Truth table66%2/3
A and B
A= defined $rollB= $roll =~ /\A[1-5]\z/
ABresult
0X0
100
111
53 unless defined $roll && $roll =~ /\A[1-5]\z/;
54 818372 ▶ return ($roll == 1 || $roll == 4 || $roll == 5) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$roll == 1 || $roll == 4 || $roll == 5 ? : 330959 487413 818372
Condition100%6/6
$roll == 1 or $roll == 4 or $roll == 5
l!l&&r!l&&!r
27021660743487413
$roll == 1 or $roll == 4
l!l&&r!l&&!r
19613274084548156
MC/DC100%3/3
$roll == 1 or $roll == 4 or $roll == 5
$roll == 1 $roll == 4 $roll == 5
Truth table100%4/4
A or B or C
A= $roll == 1B= $roll == 4C= $roll == 5
ABCresult
1XX1
01X1
0011
0000
55 }
56  
57 68 1;
58  
59 __END__
« blib/lib/Game/Senet/Bot.pm ↑ Summary blib/lib/Game/Senet/Rules.pm »