blib/lib/Logic/Relational/Goal/Domain.pm

filter: Statementstmt 83.3% 35 / 42 Branchbran 64.2% 9 / 14 Conditioncond 25.0% 3 / 12 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 90.0% 9 / 10 Podpod 75.0% 3 / 4 totaltotal 66.6% 60 / 90 CC 12 SCAR 20.5
CC
12
Cov
69%
expand
16.7
new
4.3
freshen
2.0
CRAP 7.8
« blib/lib/Logic/Relational/Goal/AllDifferent.pm ↑ Summary lib/Logic/Relational/Goal/GeneratorStep.pm »
1 package Logic::Relational::Goal::Domain;
2  
3 30 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use parent 'Logic::Relational::Goal';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use Logic::Relational::Domain;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 30 ▶use Logic::Relational::Unifier qw(unify);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Logic::Relational::Goal::Domain - Goal to constrain a variable to a range.
13  
14 =cut
15  
16 36 ▶sub new ( $class, $var, @spec ) {
Subroutine new: called CC=4 SCAR=14.6
Pod undocumented
17 36 ▶ if ( @spec == 1 && ref( $spec[0] ) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@spec == 1 and ref $spec[0] eq 'ARRAY') { } 2 34 36
elsif (@spec == 2) { } 34 0 34
Condition66%2/3
@spec == 1 and ref $spec[0] eq "ARRAY"
!ll&&!rl&&r
3402
MC/DC50%1/2
@spec == 1 and ref $spec[0] eq "ARRAY"
@spec == 1 ref $spec[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @spec == 1B= ref $spec[0] eq "ARRAY"
ABresult
0X0
100
111
18 2 return bless { var => $var, values => $spec[0] }, $class;
19 }
20 elsif ( @spec == 2 ) {
21 34 return bless { var => $var, min => $spec[0], max => $spec[1] }, $class;
22 }
23 0 croak "Invalid Goal::Domain specification";
24 }
25  
26 22 ▶sub expand ( $self, %args ) {
Subroutine expand: called CC=8 SCAR=28.2
Pod documented
27 22 my $subst = $args{substitution};
28 22 my $remaining = $args{remaining};
29 22 my $state = $args{state};
30  
31 22 my $val = $subst->walk( $self->{var} );
32  
33 my $domain_spec =
34 exists $self->{values}
35 ? { values => $self->{values} }
36 22 ▶ : { min => $self->{min}, max => $self->{max} };
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'values'} ? : 1 21 22
37  
38 22 ▶ if ( ref($val) eq 'Logic::Relational::Variable' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'Logic::Relational::Variable') { } 22 0 22
39 22 my $domain = Logic::Relational::Domain->new($domain_spec);
40 22 my $new_subst = unify( $val, $domain, $subst );
41 22 ▶ if ($new_subst) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_subst) 22 0 22
42 22 my $succ = $state->derive(
43 substitution => $new_subst,
44 goals => $remaining,
45 );
46 22 ▶ return $succ // ();
Condition33%1/3
$succ // ()
l!l&&r!l&&!r
2200
MC/DC0%0/2
$succ // ()
$succ ()
Truth table33%1/3
A // B
A= $succB= ()
ABresult
1X1
011
000
47 }
48 }
49 else {
50 0 my $domain = Logic::Relational::Domain->new($domain_spec);
51 0 ▶ if ( $val =~ /^-?\d+$/x && $domain->contains($val) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^-?\d+$/ux and $domain->contains($val)) 0 0 0
Condition0%0/3
$val =~ /^-?\d+$/ux and $domain->contains($val)
!ll&&!rl&&r
000
MC/DC0%0/2
$val =~ /^-?\d+$/ux and $domain->contains($val)
$val =~ /^-?\d+$/ux $domain->contains($val)
Truth table0%0/3
A and B
A= $val =~ /^-?\d+$/uxB= $domain->contains($val)
ABresult
0X0
100
111
52 0 my $succ = $state->derive( goals => $remaining, );
53 0 ▶ return $succ // ();
Condition0%0/3
$succ // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$succ // ()
$succ ()
Truth table0%0/3
A // B
A= $succB= ()
ABresult
1X1
011
000
54 }
55 }
56  
57 0 return ();
58 }
59  
60 14 ▶sub freshen ( $self, $var_map ) {
Subroutine freshen: called CC=2 SCAR=6.9
Pod documented
61 14 require Logic::Relational::DSL;
62 my $fresh_var =
63 14 Logic::Relational::DSL::freshen_val( $self->{var}, $var_map );
64 return
65 exists $self->{values}
66 ? ref($self)->new( $fresh_var, $self->{values} )
67 14 ▶ : ref($self)->new( $fresh_var, $self->{min}, $self->{max} );
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'values'} ? : 1 13 14
68 }
69  
70 0 ▶sub is_ground ( $self, $subst ) {
Subroutine is_ground: not called CC=1 SCAR=6.9
Pod documented
71 0 return $self->term_is_ground( $self->{var}, $subst );
72 }
73  
74 30 1;
« blib/lib/Logic/Relational/Goal/AllDifferent.pm ↑ Summary lib/Logic/Relational/Goal/GeneratorStep.pm »