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 89 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 89 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 89 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 89 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 89 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 89 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 89 our $VERSION = '0.03';
12  
13 89 our @EXPORT_OK = qw(throw_for light_of roll_of roll_for extra_throw);
14 89 our %EXPORT_TAGS = (all => \@EXPORT_OK);
15  
16 1678518 ▶sub throw_for {
Subroutine throw_for: called CC=6 SCAR=17.9
Pod documented
17 1678518 my ($seed, $n) = @_;
18 1678518 ▶ Carp::croak('Game::Senet::Sticks: throw_for wants a seed')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seed and length $seed 2 1678516 1678518
Condition100%3/3
defined $seed and length $seed
!ll&&!rl&&r
111678516
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 1678516 ▶ 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 1678513 1678516
Condition100%3/3
defined $n and $n =~ /\A\d+\z/
!ll&&!rl&&r
121678513
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 1678513 my $bytes = "$seed";
23 1678513 ▶ 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 1678512 1678513
24 unless utf8::downgrade($bytes, 1);
25 1678512 my $byte = unpack 'C', Digest::SHA::sha256($bytes . "throw:$n");
26 1678512 return [ map { ($byte >> $_) & 1 } 0 .. 3 ];
27 }
28  
29 1677816 ▶sub light_of {
Subroutine light_of: called CC=4 SCAR=13.9
Pod documented
30 1677816 my ($sticks) = @_;
31 1677816 ▶ Carp::croak('Game::Senet::Sticks: light_of wants the four sticks')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sticks eq "ARRAY" and @$sticks == 4 2 1677814 1677816
Condition100%3/3
ref $sticks eq "ARRAY" and @$sticks == 4
!ll&&!rl&&r
111677814
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 1677814 my $count = 0;
34 1677814 $count += $_ for @$sticks;
35 1677814 return $count;
36 }
37  
38 2220745 ▶sub roll_of {
Subroutine roll_of: called CC=4 SCAR=13.9
Pod documented
39 2220745 my ($throw) = @_;
40 2220745 ▶ 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 2220744 2220745
Condition66%2/3
defined $throw and $throw =~ /\A[0-4]\z/
!ll&&!rl&&r
012220744
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 2220744 ▶ return $throw == 0 ? 5 : $throw + 0;
Branch: 1 branch
BranchTrueFalseTotal
$throw == 0 ? : 134495 2086249 2220744
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 818553 ▶sub extra_throw {
Subroutine extra_throw: called CC=6 SCAR=17.9
Pod documented
51 818553 my ($roll) = @_;
52 818553 ▶ 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 818552 818553
Condition66%2/3
defined $roll and $roll =~ /\A[1-5]\z/
!ll&&!rl&&r
01818552
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 818552 ▶ return ($roll == 1 || $roll == 4 || $roll == 5) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$roll == 1 || $roll == 4 || $roll == 5 ? : 331016 487536 818552
Condition100%6/6
$roll == 1 or $roll == 4 or $roll == 5
l!l&&r!l&&!r
27027360743487536
$roll == 1 or $roll == 4
l!l&&r!l&&!r
19618974084548279
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 89 1;
58  
59 __END__
« blib/lib/Game/Senet/Bot.pm ↑ Summary blib/lib/Game/Senet/Rules.pm »