blib/lib/Quantum/Superpositions/Lazy/Util.pm

filter: Statementstmt 100% 48 / 48 Branchbran 100% 8 / 8 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 3 totaltotal 91.7% 78 / 85 CC 8 SCAR 10.6
CC
8
Cov
97%
__ANON__
6.0
is_collapsible
2.0
is_state
2.0
CRAP 2.9
« blib/lib/Quantum/Superpositions/Lazy/Computation.pm ↑ Summary blib/lib/Quantum/Superpositions/Lazy.pm »
1 package Quantum::Superpositions::Lazy::Util;
2 15 $Quantum::Superpositions::Lazy::Util::VERSION = '1.12';
3 15 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use List::Util qw(max);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Random::Any qw(rand);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 15 our @EXPORT_OK = qw(
11 is_collapsible
12 is_state
13 get_rand
14 get_iterator
15 );
16  
17 sub is_collapsible
18 16838 ▶{
Subroutine is_collapsible: called CC=2 SCAR=7.1
Pod undocumented
19 16838 my ($item) = @_;
20  
21 16838 ▶ return blessed $item && $item->DOES("Quantum::Superpositions::Lazy::Role::Collapsible");
Condition66%2/3
builtin::blessed($item) && $item->DOES('Quantum::Superpositions::Lazy::Role::Collapsible')
!ll&&!rl&&r
165150323
MC/DC50%1/2
builtin::blessed($item) && $item->DOES('Quantum::Superpositions::Lazy::Role::Collapsible')
builtin::blessed($item) $item->DOES('Quantum::Superpositions::Lazy::Role::Collapsible')
Truth table66%2/3
A && B
A= builtin::blessed($item)B= $item->DOES('Quantum::Superpositions::Lazy::Role::Collapsible')
ABresult
0X0
100
111
22 }
23  
24 sub is_state
25 244897 ▶{
Subroutine is_state: called CC=2 SCAR=7.1
Pod undocumented
26 244897 my ($item) = @_;
27  
28 244897 ▶ return blessed $item && $item->isa("Quantum::Superpositions::Lazy::State");
Condition66%2/3
builtin::blessed($item) && $item->isa('Quantum::Superpositions::Lazy::State')
!ll&&!rl&&r
201488043409
MC/DC50%1/2
builtin::blessed($item) && $item->isa('Quantum::Superpositions::Lazy::State')
builtin::blessed($item) $item->isa('Quantum::Superpositions::Lazy::State')
Truth table66%2/3
A && B
A= builtin::blessed($item)B= $item->isa('Quantum::Superpositions::Lazy::State')
ABresult
0X0
100
111
29 }
30  
31 # MUST return a value in range of [0, 1)
32 35 ▶sub get_rand { rand() }
Subroutine get_rand: called CC=1 SCAR=0.0
33  
34 sub get_iterator
35 146 ▶{
Subroutine get_iterator: called CC=1 SCAR=0.0
Pod undocumented
36 146 my (@states) = @_;
37  
38 146 my @indexes = map { 0 } @states;
39 146 my @max_indexes = map { $#$_ } @states;
40  
41 # we can't iterate if one of the elements do not exist
42 146 my $finished = scalar grep { $_ < 0 } @max_indexes;
43 122497 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
44 122497 my ($with_indexes) = @_;
45 122497 ▶ return if $finished;
Branch: 1 branch
BranchTrueFalseTotal
if $finished 82 122415 122497
46  
47 122415 my $i = 0;
48 my @ret =
49 244897 ▶ map { is_state($_) ? $_->value : $_ }
Branch: 1 branch
BranchTrueFalseTotal
is_state($_) ? : 43409 201488 244897
50 122415 map { $states[$i++][$_] }
51 @indexes;
52  
53 122415 ▶ if ($with_indexes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($with_indexes) 39529 82886 122415
54 39529 @ret = map { $indexes[$_], $ret[$_] } 0 .. max($#indexes, $#ret);
55 }
56  
57 122415 $i = 0;
58 122415 ▶ while ($i < @indexes && ++$indexes[$i] > $max_indexes[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @indexes and ++$indexes[$i] > $max_indexes[$i]) 16107 122415 138522
Condition100%3/3
$i < @indexes and ++$indexes[$i] > $max_indexes[$i]
!ll&&!rl&&r
11412230116107
MC/DC100%2/2
$i < @indexes and ++$indexes[$i] > $max_indexes[$i]
$i < @indexes ++$indexes[$i] > $max_indexes[$i]
Truth table100%3/3
A and B
A= $i < @indexesB= ++$indexes[$i] > $max_indexes[$i]
ABresult
0X0
100
111
59 16107 $indexes[$i] = 0;
60 16107 $i += 1;
61 }
62  
63 122415 $finished = $i == @indexes;
64 122415 return @ret;
65 146 };
66 }
67  
68 15 1;
69  
« blib/lib/Quantum/Superpositions/Lazy/Computation.pm ↑ Summary blib/lib/Quantum/Superpositions/Lazy.pm »