RuleEngine/Rule/InputOverThreshold.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran 66.6% 4 / 6 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 86.0% 43 / 50 CC 7 SCAR 15.7
CC
7
Cov
87%
evaluate
7.5
BEGIN
1.0
BEGIN
1.0
CRAP 4.8
« RuleEngine/Rule.pm ↑ Summary RuleEngine/Output.pm »
1 package VS::RuleEngine::Rule::InputOverThreshold;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use VS::RuleEngine::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use base qw(VS::RuleEngine::Rule);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 7 my ($pkg, %args) = @_;
12 7 my $self = bless { %args }, $pkg;
13 7 return $self;
14 }
15  
16 7 ▶sub evaluate {
Subroutine evaluate: called CC=7 SCAR=20.2
Pod documented
17 7 my ($self, $input) = @_;
18  
19 # If we have nothing to match aginst it's a no match
20 7 ▶ return KV_NO_MATCH unless %{$self};
Branch: 1 branch
BranchTrueFalseTotal
unless %{$self;} 0 7 7
21
22 # The order we evaulate each change in is not relevant
23 7 for my $key (keys %{$self}) {
24 17 ▶ my $v1 = $input->get($key) || 0;
Condition50%1/2
$input->get($key) || 0
l!l
170
MC/DC0%0/1
$input->get($key) || 0
$input->get($key)
Truth table50%1/2
A
A= $input->get($key)
Aresult
11
00
25  
26 17 ▶ if (!$v1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v1) 0 17 17
27 0 return KV_NO_MATCH;
28 }
29  
30 17 my $change = $self->{$key};
31
32 17 ▶ if ($change && ($v1 / $change) < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($change and $v1 / $change < 1) 3 14 17
Condition66%2/3
$change and $v1 / $change < 1
!ll&&!rl&&r
0143
MC/DC50%1/2
$change and $v1 / $change < 1
$change $v1 / $change < 1
Truth table66%2/3
A and B
A= $changeB= $v1 / $change < 1
ABresult
0X0
100
111
33 3 return KV_NO_MATCH;
34 }
35 }
36
37 # All thresholds passed therefore we have a match
38 4 return KV_MATCH;
39 }
40  
41 2 1;
42  
43 =head1 NAME
44  
45 VS::RuleEngine::Rule::InputOverThreshold - Generic rule for checking input thresholds
46  
47 =head1 SYNOPSIS
48  
49 use VS::RuleEngine::Declare;
50
51 my $engine = engine {
52 rule 'valid_name' => instanceof "VS::RuleEngine::Rule::InputOverThreshold" => with_args {
53 'input_1' => 5,
54 'input_2' => -5,
55 }
56 }
57
58 =head1 DESCRIPTION
59  
60 This is a generic rule that checks if the value from an input is equal or passes a
61 threshold relative to 0. This can be used to model change matrices where a row
62 represets a rule.
63  
64 The following table shows the conditions when it matches
65  
66 Input | Threshold | Result
67 ------+-----------+-------
68 x | 0 | match
69 >= y | y > 0 | match
70 >= y | y < 0 | no match
71 <= y | y < 0 | match
72 <= y | y > 0 | no match
73
74 =head1 USAGE
75  
76 =head2 Rule arguments
77  
78 This rule expects a hash reference as its argument, which is what C<< with_args >> provides,
79 where the key is the name of an input and the value is the expected threshold value.
80  
81 =begin PRIVATE
82  
83 =over 4
84  
85 =item new
86  
87 L<VS::RuleEngine::Rule/new>
88  
89 =item evaluate
90  
91 L<VS::RuleEngine::Rule/evaulate>
92  
93 =back
94  
95 =end PRIVATE
96  
97 =cut
« RuleEngine/Rule.pm ↑ Summary RuleEngine/Output.pm »