| 1 | package VS::RuleEngine::Rule::InputUnderThreshold; | ||||||||||||||||||||||||||||
| 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=8 SCAR=22.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
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # The order we evaulate each change in is not relevant | ||||||||||||||||||||||||||||
| 23 | 7 | for my $key (keys %{$self}) { | |||||||||||||||||||||||||||
| 24 | 11 | ▶ | my $v1 = $input->get($key) || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$input->get($key) || 0
MC/DC0%0/1
$input->get($key) || 0
$input->get($key)
Truth table50%1/2
A
A= $input->get($key)
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 11 | my $change = $self->{$key}; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 11 | ▶ | if ($change && ($v1 / $change) >= 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$change and $v1 / $change >= 1
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
| |||||||||||||||||||||||||||||
| 29 | 5 | return KV_NO_MATCH; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | if (!$change && $v1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $change and $v1
MC/DC0%0/2
not $change and $v1
not $change
$v1
Truth table33%1/3
not(A) and B
A= not $changeB= $v1
| |||||||||||||||||||||||||||||
| 33 | 0 | return KV_NO_MATCH; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # All thresholds passed therefore we have a match | ||||||||||||||||||||||||||||
| 38 | 2 | return KV_MATCH; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | 1; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head1 NAME | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | VS::RuleEngine::Rule::InputUnderThreshold - 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::InputUnderThreshold" => 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 does not pass 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 | no match | ||||||||||||||||||||||||||||
| 70 | > y | y < 0 | match | ||||||||||||||||||||||||||||
| 71 | < y | y < 0 | no match | ||||||||||||||||||||||||||||
| 72 | < y | y > 0 | 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 | ||||||||||||||||||||||||||||