blib/lib/Number/Interval.pm

filter: Statementstmt 90.3% 242 / 268 Branchbran 76.0% 184 / 242 Conditioncond 76.3% 103 / 135 MC/DCmcdc 62.6% 52 / 83 Subroutinesub 92.3% 24 / 26 Podpod 100% 17 / 17 totaltotal 80.6% 622 / 771 CC 169 SCAR 38.5
CC
169
Cov
82%
contains
88.9
intersection
63.8
minmax_hash
56.0
CRAP 47.1
↑ Summary
1 package Number::Interval;
2  
3 =head1 NAME
4  
5 Number::Interval - Implement a representation of a numeric interval
6  
7 =head1 SYNOPSIS
8  
9 use Number::Interval;
10  
11 $i = new Number::Interval( Min => -4, Max => 20);
12 $i = new Number::Interval( Min => 0 );
13  
14 $is = $i->contains( $value );
15 $status = $i->intersection( $i2 );
16  
17 print "$i";
18  
19 =head1 DESCRIPTION
20  
21 Simple class to implement a closed or open interval. Can be used to
22 compare different intervals, determine set membership, calculate
23 intersections and provide default stringification methods.
24  
25 Intervals can be bound or unbound. If C<max> is less than C<min>
26 the interval is inverted.
27  
28 =cut
29  
30 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 use overload
36 1 ▶ '""' => "stringify",
Subroutine BEGIN: called CC=1 SCAR=0.0
37 '==' => 'equate',
38 'eq' => "equate",
39 '!=' => "notequal",
40 1 'ne' => "notequal";
41  
42 # CVS ID: $Id$
43  
44 1 ▶use vars qw/ $VERSION /;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 $VERSION = '0.07';
46  
47 # hash of allowed lower-cased constructor keys with
48 # corresponding accessor method
49 1 my %ConstructAllowed = (
50 min => 'min',
51 max => 'max',
52 incmax => 'inc_max',
53 incmin => 'inc_min',
54 posdef => 'pos_def',
55 );
56  
57 =head1 METHODS
58  
59 =head2 Constructor
60  
61 =over 4
62  
63 =item B<new>
64  
65 Create a new object. Can be populated when supplied with
66 keys C<Max> and C<Min>.
67  
68 $r = new Number::Interval();
69  
70 This interval is Inf.
71  
72 $r = new Number::Interval( Max => 5 );
73  
74 This interval is > 5.
75  
76 $r = new Number::Interval( Max => 5, Min => 22 );
77  
78 This interval is > 22 and < 5.
79  
80 By default the interval does not include the bounds themselves. They
81 can be included by using the IncMax and IncMin keys.
82  
83 $r = new Number::Interval( Max => 5, IncMax => 1 );
84  
85 The above interval is >=5
86  
87 Positive-definite intervals allow the stringification to ignore
88 the lower bound if it is 0 (even if set explicitly).
89  
90 $r = new Number::Interval( Max => 5, IncMax => 1, Min => 0,
91 PosDef => 1);
92  
93 The keys are case-insensitive.
94  
95 =cut
96  
97 117 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
98 117 my $proto = shift;
99 117 ▶ my $class = ref($proto) || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
51120
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
100  
101 117 my %args = @_;
102  
103 117 my $r = {
104 Min => undef,
105 Max => undef,
106 IncMax => 0,
107 IncMin => 0,
108 PosDef => 0,
109 };
110  
111 # Create object
112 117 my $obj = bless $r, $class;
113  
114 # Populate it
115 117 for my $key (keys %args) {
116 193 my $lc = lc( $key );
117 193 ▶ if (exists $ConstructAllowed{$lc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ConstructAllowed{$lc}) 193 0 193
118 193 my $method = $ConstructAllowed{$lc};
119 193 $obj->$method( $args{$key} );
120 }
121 }
122  
123 117 return $obj;
124 }
125  
126 =item B<copy>
127  
128 Copy the contents of the current object into a new object and return it.
129  
130 $new = $r->copy;
131  
132 =cut
133  
134 5 ▶sub copy {
Subroutine copy: called CC=1 SCAR=0.0
Pod documented
135 5 my $self = shift;
136 5 my $new = $self->new();
137 # simplistic hash copy since we know that we are a simple hash internally
138 # subclasses might get in trouble if they have complexity.
139 5 %$new = %$self;
140 5 return $new;
141 }
142  
143 =back
144  
145 =head2 Accessors
146  
147 =over 4
148  
149 =item B<max>
150  
151 Return (or set) the upper end of the interval.
152  
153 $max = $r->max;
154 $r->max(22.0);
155  
156 C<undef> indicates that the interval has no upper bound.
157  
158 =cut
159  
160 549 ▶sub max {
Subroutine max: called CC=2 SCAR=6.9
Pod documented
161 549 my $self = shift;
162 549 ▶ $self->{Max} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 119 430 549
163 549 return $self->{Max};
164 }
165  
166 =item B<min>
167  
168 Return (or set) the lower end of the interval.
169  
170 $min = $r->min;
171 $r->min( undef );
172  
173 C<undef> indicates that the interval has no lower bound.
174  
175 =cut
176  
177 578 ▶sub min {
Subroutine min: called CC=2 SCAR=6.9
Pod documented
178 578 my $self = shift;
179 578 ▶ $self->{Min} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 123 455 578
180 578 return $self->{Min};
181 }
182  
183 =item B<inc_max>
184  
185 Return (or set) the boolean indicating whether the maximum bound
186 of the interval should be included in the bound definition. If true,
187 the bounds will be >= max.
188  
189 $inc = $r->inc_max;
190 $r->inc_max( 1 );
191  
192 Default is false (not included).
193  
194 =cut
195  
196 219 ▶sub inc_max {
Subroutine inc_max: called CC=2 SCAR=6.9
Pod documented
197 219 my $self = shift;
198 219 ▶ $self->{IncMax} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 46 173 219
199 219 return $self->{IncMax};
200 }
201  
202  
203 =item B<inc_min>
204  
205 Return (or set) the boolean indicating whether the minimum bound
206 of the interval should be included in the bound definition. If true,
207 the bounds will be <= min.
208  
209 $inc = $r->inc_min;
210 $r->inc_min( 1 );
211  
212 Default is false (not included).
213  
214 =cut
215  
216 205 ▶sub inc_min {
Subroutine inc_min: called CC=2 SCAR=6.9
Pod documented
217 205 my $self = shift;
218 205 ▶ $self->{IncMin} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 49 156 205
219 205 return $self->{IncMin};
220 }
221  
222 =item B<pos_def>
223  
224 Indicate that the interval is positive definite. This helps the
225 stringification method to determine whether the lower bound
226 should be included
227  
228 $r->pos_def( 1 );
229  
230  
231 If set to true, automatically sets the lower bound to 0 if the lower bound
232 is not explicitly defined.
233  
234 =cut
235  
236 28 ▶sub pos_def {
Subroutine pos_def: called CC=4 SCAR=14.3
Pod documented
237 28 my $self = shift;
238 28 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 27 28
239 1 $self->{PosDef} = shift;
240 1 ▶ if ($self->{PosDef} && !defined $self->min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PosDef"} and not defined $self->min) 1 0 1
Condition33%1/3
$self->{"PosDef"} and not defined $self->min
!ll&&!rl&&r
001
MC/DC0%0/2
$self->{"PosDef"} and not defined $self->min
$self->{"PosDef"} not defined $self->min
Truth table33%1/3
A and not(B)
A= $self->{"PosDef"}B= not defined $self->min
ABresult
0X0
100
111
241 1 $self->min( 0 );
242 }
243 }
244 28 return $self->{PosDef};
245 }
246  
247 =item B<minmax>
248  
249 Return (or set) the minimum and maximum values of the
250 interval as an array.
251  
252 $r->minmax( 1, 5 );
253 @interval = $r->minmax;
254  
255 Returns reference to an array in a scalar context.
256  
257 =cut
258  
259 3 ▶sub minmax {
Subroutine minmax: called CC=3 SCAR=11.0
Pod documented
260 3 my $self = shift;
261 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 1 3
262 2 $self->min( $_[0] );
263 2 $self->max( $_[1] );
264 }
265 3 my @minmax = ( $self->min, $self->max );
266 3 ▶ return (wantarray ? @minmax : \@minmax);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 2 3
267 }
268  
269 =item B<minmax_hash>
270  
271 Return (or set) the minimum and maximum values of the
272 interval as an hash.
273  
274 $r->minmax_hash( min => 1, max => 5 );
275 %interval = $r->minmax_hash;
276  
277 Returns reference to an hash in a scalar context.
278  
279 C<min> or C<max> can be ommitted. The returned hash
280 contains C<min> and C<max> keys but only if they
281 have defined values.
282  
283 =cut
284  
285 0 ▶sub minmax_hash {
Subroutine minmax_hash: not called CC=7 SCAR=40.3
Pod documented
286 0 my $self = shift;
287 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
288 0 my %args = @_;
289 0 ▶ $self->min( $args{min} ) if exists $args{min};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"min"} 0 0 0
290 0 ▶ $self->max( $args{max} ) if exists $args{max};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"max"} 0 0 0
291 }
292  
293 # Populate the output hash
294 0 my %minmax;
295 0 ▶ $minmax{min} = $self->min if defined $self->min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->min 0 0 0
296 0 ▶ $minmax{max} = $self->max if defined $self->max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->max 0 0 0
297  
298 0 ▶ return (wantarray ? %minmax : \%minmax);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
299 }
300  
301 =item B<sizeof>
302  
303 Returns the size of the interval.
304  
305 $sizeof = $r->sizeof;
306  
307 If either of the lower or upper ends are unbounded, then C<undef> will
308 be returned.
309  
310 =cut
311  
312 5 ▶sub sizeof {
Subroutine sizeof: called CC=3 SCAR=11.0
Pod documented
313 5 my $self = shift;
314 5 ▶ if( ! defined( $self->min ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->min and defined $self->max) 3 2 5
Condition100%3/3
defined $self->min and defined $self->max
!ll&&!rl&&r
212
MC/DC100%2/2
defined $self->min and defined $self->max
defined $self->min defined $self->max
Truth table100%3/3
A and B
A= defined $self->minB= defined $self->max
ABresult
0X0
100
111
315 ! defined( $self->max ) ) {
316 3 return undef;
317 }
318  
319 2 return abs( $self->max - $self->min );
320 }
321  
322 =back
323  
324 =head2 General
325  
326 =over 4
327  
328 =item B<stringify>
329  
330 Convert the object into a string representation for display.
331 Usually called via a stringify overload.
332  
333 =cut
334  
335 9 ▶sub stringify {
Subroutine stringify: called CC=15 SCAR=28.6
Pod documented
336 9 my $self = shift;
337  
338 9 my $min = $self->min;
339 9 my $max = $self->max;
340  
341 # are we inclusive (for unbound ranges)
342 9 ▶ my $inc_min_ub = ( $self->inc_min ? "=" : " " );
Branch: 1 branch
BranchTrueFalseTotal
$self->inc_min ? : 3 6 9
343 9 ▶ my $inc_max_ub = ( $self->inc_max ? "=" : " " );
Branch: 1 branch
BranchTrueFalseTotal
$self->inc_max ? : 2 7 9
344  
345 9 ▶ if (defined $min && defined $max) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $min and defined $max) { } 9 0 9
elsif (defined $min) { } 0 0 0
elsif (defined $max) { } 0 0 0
Condition33%1/3
defined $min and defined $max
!ll&&!rl&&r
009
MC/DC0%0/2
defined $min and defined $max
defined $min defined $max
Truth table33%1/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
346 # Bound
347  
348 # use standard interval notation when using a bound range
349 9 ▶ my $inc_min_b = ( $self->inc_min ? "[" : "(" );
Branch: 1 branch
BranchTrueFalseTotal
$self->inc_min ? : 3 6 9
350 9 ▶ my $inc_max_b = ( $self->inc_max ? "]" : ")" );
Branch: 1 branch
BranchTrueFalseTotal
$self->inc_max ? : 2 7 9
351  
352 9 ▶ if ($min == $max) {
Branch: 2 branches
BranchTrueFalseTotal
if ($min == $max) { } 4 5 9
elsif ($max < $min) { } 1 4 5
353 # no range
354 4 ▶ if ($self->inc_min() or $self->inc_max()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inc_min or $self->inc_max) { } 3 1 4
Condition100%3/3
$self->inc_min or $self->inc_max
l!l&&r!l&&!r
211
MC/DC100%2/2
$self->inc_min or $self->inc_max
$self->inc_min $self->inc_max
Truth table100%3/3
A or B
A= $self->inc_minB= $self->inc_max
ABresult
1X1
011
000
355 # A single value.
356 3 return "==$min";
357 } else {
358 # This interval matches nothing.
359 1 return "{}";
360 }
361 } elsif ($max < $min) {
362 1 return "<$inc_max_ub$max and >$inc_min_ub$min";
363 } else {
364 4 ▶ if ($min <= 0 && $self->pos_def) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min <= 0 and $self->pos_def) { } 2 2 4
Condition66%2/3
$min <= 0 and $self->pos_def
!ll&&!rl&&r
202
MC/DC50%1/2
$min <= 0 and $self->pos_def
$min <= 0 $self->pos_def
Truth table66%2/3
A and B
A= $min <= 0B= $self->pos_def
ABresult
0X0
100
111
365 2 return "<$inc_max_ub$max";
366 } else {
367 2 return "$inc_min_b$min,$max$inc_max_b";
368 }
369 }
370 } elsif (defined $min) {
371 0 return ">$inc_min_ub$min";
372 } elsif (defined $max) {
373 0 return "<$inc_max_ub$max";
374 } else {
375 0 return "Inf";
376 }
377  
378 }
379  
380 =item B<isinverted>
381  
382 Determine whether the interval is inverted. This is true if
383 both max and min are supplied but max is less than min. For all other
384 cases (including unbound single-sided intervals) this will return false.
385  
386 =cut
387  
388 136 ▶sub isinverted {
Subroutine isinverted: called CC=4 SCAR=13.9
Pod documented
389 136 my $self = shift;
390 136 my $min = $self->min;
391 136 my $max = $self->max;
392  
393 136 ▶ if (defined $min and defined $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and defined $max) 88 48 136
Condition100%3/3
defined $min and defined $max
!ll&&!rl&&r
291988
MC/DC100%2/2
defined $min and defined $max
defined $min defined $max
Truth table100%3/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
394 88 ▶ return 1 if $min > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $min > $max 22 66 88
395 }
396 114 return 0;
397 }
398  
399 =item B<isbound>
400  
401 Returns true if the interval is bound by an upper and lower limit.
402 An inverted interval would be bounded but inverted.
403  
404 =cut
405  
406 92 ▶sub isbound {
Subroutine isbound: called CC=3 SCAR=11.0
Pod documented
407 92 my $self = shift;
408 92 my $min = $self->min;
409 92 my $max = $self->max;
410 92 ▶ if (defined $min and defined $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and defined $max) { } 52 40 92
Condition100%3/3
defined $min and defined $max
!ll&&!rl&&r
251552
MC/DC100%2/2
defined $min and defined $max
defined $min defined $max
Truth table100%3/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
411 52 return 1;
412 } else {
413 40 return 0;
414 }
415 }
416  
417  
418 =item B<equate>
419  
420 Compare with another Interval object.
421 Returns true if they are the same. False otherwise.
422  
423 =cut
424  
425 9 ▶sub equate {
Subroutine equate: called CC=12 SCAR=25.8
Pod documented
426 9 my $self = shift;
427 9 my $comparison = shift;
428  
429 # Need to check that both are objects
430 9 ▶ return 0 unless defined $comparison;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $comparison 0 9 9
431 9 ▶ return 0 unless UNIVERSAL::isa($comparison, "Number::Interval");
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($comparison, "Number::Interval") 0 9 9
432  
433 # need to be explicit about undefs
434 # return false immediately we find a difference
435 9 for my $m (qw/ min max/) {
436 # first values
437 15 ▶ if ( defined $comparison->$m() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comparison->$m) { } 9 6 15
438 9 ▶ return 0 if !defined $self->$m();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->$m 0 9 9
439 9 ▶ return 0 if $comparison->$m() != $self->$m();
Branch: 1 branch
BranchTrueFalseTotal
if $comparison->$m != $self->$m 1 8 9
440 } else {
441 6 ▶ return 0 if defined $self->$m();
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->$m 1 5 6
442 }
443  
444 # then boolean
445 13 my $incm = 'inc_' . $m;
446  
447 # return false if state of one is NOT the other
448 13 ▶ return 0 if ( ( $self->$incm() && !$comparison->$incm() ) ||
Branch: 1 branch
BranchTrueFalseTotal
if $self->$incm and not $comparison->$incm or not $self->$incm and $comparison->$incm 2 11 13
Condition55%5/9
$self->$incm and not $comparison->$incm or not $self->$incm and $comparison->$incm
l!l&&r!l&&!r
0211
$self->$incm and not $comparison->$incm
!ll&&!rl&&r
1300
not $self->$incm and $comparison->$incm
!ll&&!rl&&r
0112
MC/DC25%1/4
$self->$incm and not $comparison->$incm or not $self->$incm and $comparison->$incm
$self->$incm not $comparison->$incm not $self->$incm $comparison->$incm
Truth table28%2/7
A and not(B) or not(C) and D
A= $self->$incmB= not $comparison->$incmC= not $self->$incmD= $comparison->$incm
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
449 ( !$self->$incm() && $comparison->$incm() ) );
450 }
451 5 return 1;
452 }
453  
454 =item B<notequal>
455  
456 Inverse of C<equate>. Used by the tied interface to implement !=.
457  
458 $i1 != $i2
459  
460 =cut
461  
462 4 ▶sub notequal {
Subroutine notequal: called CC=1 SCAR=0.0
Pod documented
463 4 my $self = shift;
464 4 return !$self->equate( @_ );
465 }
466  
467 =item B<contains>
468  
469 Determine whether a supplied value is within the defined intervals.
470  
471 $is = $i->contains( $value );
472  
473 If both intervals are undefined, always returns true.
474  
475 B<Note:> If the min == max, returns true if the supplied value is that
476 value, but only if either IncMin or IncMax is true.
477 I<This is a change in version 0.06:> previously this method returned
478 true in this case regardless of IncMin and IncMax setttings.
479  
480 If the interval is positive definite, always returns false if the
481 supplied value is negative.
482  
483 =cut
484  
485 42 ▶sub contains {
Subroutine contains: called CC=46 SCAR=44.9
Pod documented
486 42 my $self = shift;
487 42 my $value = shift;
488  
489 42 my $max = $self->max;
490 42 my $min = $self->min;
491 42 ▶ return 1 if (!defined $max && !defined $min);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max or defined $min 0 42 42
Condition66%2/3
defined $max or defined $min
l!l&&r!l&&!r
3840
MC/DC0%0/2
defined $max or defined $min
defined $max defined $min
Truth table66%2/3
A or B
A= defined $maxB= defined $min
ABresult
1X1
011
000
492  
493 # Assume it doesnt match the interval
494 42 my $contains = 0;
495 42 ▶ if ($self->isinverted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isinverted) { } 6 36 42
496 # Inverted interval. Both max and min must be defined
497 6 ▶ if (defined $max and defined $min) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and defined $min) { } 6 0 6
Condition33%1/3
defined $max and defined $min
!ll&&!rl&&r
006
MC/DC0%0/2
defined $max and defined $min
defined $max defined $min
Truth table33%1/3
A and B
A= defined $maxB= defined $min
ABresult
0X0
100
111
498 6 ▶ if ($self->inc_max && $self->inc_min) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->inc_max and $self->inc_min) { } 0 6 6
elsif ($self->inc_max) { } 0 6 6
elsif ($self->inc_min) { } 0 6 6
Condition33%1/3
$self->inc_max and $self->inc_min
!ll&&!rl&&r
600
MC/DC0%0/2
$self->inc_max and $self->inc_min
$self->inc_max $self->inc_min
Truth table33%1/3
A and B
A= $self->inc_maxB= $self->inc_min
ABresult
0X0
100
111
499 0 ▶ if ($value <= $max || $value >= $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value <= $max or $value >= $min) 0 0 0
Condition0%0/3
$value <= $max or $value >= $min
l!l&&r!l&&!r
000
MC/DC0%0/2
$value <= $max or $value >= $min
$value <= $max $value >= $min
Truth table0%0/3
A or B
A= $value <= $maxB= $value >= $min
ABresult
1X1
011
000
500 0 $contains = 1;
501 }
502 } elsif ($self->inc_max) {
503 0 ▶ if ($value <= $max || $value > $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value <= $max or $value > $min) 0 0 0
Condition0%0/3
$value <= $max or $value > $min
l!l&&r!l&&!r
000
MC/DC0%0/2
$value <= $max or $value > $min
$value <= $max $value > $min
Truth table0%0/3
A or B
A= $value <= $maxB= $value > $min
ABresult
1X1
011
000
504 0 $contains = 1;
505 }
506 } elsif ($self->inc_min) {
507 0 ▶ if ($value < $max || $value >= $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $max or $value >= $min) 0 0 0
Condition0%0/3
$value < $max or $value >= $min
l!l&&r!l&&!r
000
MC/DC0%0/2
$value < $max or $value >= $min
$value < $max $value >= $min
Truth table0%0/3
A or B
A= $value < $maxB= $value >= $min
ABresult
1X1
011
000
508 0 $contains = 1;
509 }
510 } else {
511 6 ▶ if ($value < $max || $value > $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $max or $value > $min) 4 2 6
Condition100%3/3
$value < $max or $value > $min
l!l&&r!l&&!r
222
MC/DC100%2/2
$value < $max or $value > $min
$value < $max $value > $min
Truth table100%3/3
A or B
A= $value < $maxB= $value > $min
ABresult
1X1
011
000
512 4 $contains = 1;
513 }
514 }
515  
516 } else {
517 0 croak "An interval can not be inverted with only one defined value";
518 }
519  
520 } else {
521 # normal interval
522 36 ▶ if (defined $max and defined $min) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $max and defined $min) { } 28 8 36
elsif (defined $max) { } 4 4 8
elsif (defined $min) { } 4 0 4
Condition100%3/3
defined $max and defined $min
!ll&&!rl&&r
4428
MC/DC100%2/2
defined $max and defined $min
defined $max defined $min
Truth table100%3/3
A and B
A= defined $maxB= defined $min
ABresult
0X0
100
111
523 28 ▶ if ($max == $min) { # need to include a bound
Branch: 5 branches
BranchTrueFalseTotal
if ($max == $min) { } 5 23 28
elsif ($self->pos_def and $value < 0) { } 2 21 23
elsif ($self->inc_max and $self->inc_min) { } 2 19 21
elsif ($self->inc_max) { } 2 17 19
elsif ($self->inc_min) { } 6 11 17
524 5 ▶ if ($self->inc_min || $self->inc_max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inc_min or $self->inc_max) 4 1 5
Condition100%3/3
$self->inc_min or $self->inc_max
l!l&&r!l&&!r
311
MC/DC100%2/2
$self->inc_min or $self->inc_max
$self->inc_min $self->inc_max
Truth table100%3/3
A or B
A= $self->inc_minB= $self->inc_max
ABresult
1X1
011
000
525 4 ▶ $contains = 1 if $value == $max;
Branch: 1 branch
BranchTrueFalseTotal
if $value == $max 3 1 4
526 }
527 ▶ } elsif ($self->pos_def && $value < 0) {
Condition100%3/3
$self->pos_def and $value < 0
!ll&&!rl&&r
1922
MC/DC100%2/2
$self->pos_def and $value < 0
$self->pos_def $value < 0
Truth table100%3/3
A and B
A= $self->pos_defB= $value < 0
ABresult
0X0
100
111
528 2 $contains = 0;
529 ▶ } elsif ($self->inc_max && $self->inc_min) {
Condition100%3/3
$self->inc_max and $self->inc_min
!ll&&!rl&&r
1722
MC/DC100%2/2
$self->inc_max and $self->inc_min
$self->inc_max $self->inc_min
Truth table100%3/3
A and B
A= $self->inc_maxB= $self->inc_min
ABresult
0X0
100
111
530 2 ▶ if ($value <= $max && $value >= $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value <= $max and $value >= $min) 2 0 2
Condition33%1/3
$value <= $max and $value >= $min
!ll&&!rl&&r
002
MC/DC0%0/2
$value <= $max and $value >= $min
$value <= $max $value >= $min
Truth table33%1/3
A and B
A= $value <= $maxB= $value >= $min
ABresult
0X0
100
111
531 2 $contains = 1;
532 }
533 } elsif ($self->inc_max) {
534 2 ▶ if ($value <= $max && $value > $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value <= $max and $value > $min) 1 1 2
Condition66%2/3
$value <= $max and $value > $min
!ll&&!rl&&r
011
MC/DC50%1/2
$value <= $max and $value > $min
$value <= $max $value > $min
Truth table66%2/3
A and B
A= $value <= $maxB= $value > $min
ABresult
0X0
100
111
535 1 $contains = 1;
536 }
537 } elsif ($self->inc_min) {
538 6 ▶ if ($value < $max && $value >= $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $max and $value >= $min) 3 3 6
Condition100%3/3
$value < $max and $value >= $min
!ll&&!rl&&r
213
MC/DC100%2/2
$value < $max and $value >= $min
$value < $max $value >= $min
Truth table100%3/3
A and B
A= $value < $maxB= $value >= $min
ABresult
0X0
100
111
539 3 $contains = 1;
540 }
541 } else {
542 11 ▶ if ($value < $max && $value > $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $max and $value > $min) 5 6 11
Condition100%3/3
$value < $max and $value > $min
!ll&&!rl&&r
335
MC/DC100%2/2
$value < $max and $value > $min
$value < $max $value > $min
Truth table100%3/3
A and B
A= $value < $maxB= $value > $min
ABresult
0X0
100
111
543 5 $contains = 1;
544 }
545 }
546 } elsif (defined $max) {
547 4 ▶ if ($self->inc_max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inc_max) { } 1 3 4
548 1 ▶ $contains = 1 if $value <= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $value <= $max 1 0 1
549 } else {
550 3 ▶ $contains = 1 if $value < $max;
Branch: 1 branch
BranchTrueFalseTotal
if $value < $max 1 2 3
551 }
552 } elsif (defined $min) {
553 4 ▶ if ($self->inc_min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inc_min) { } 1 3 4
554 1 ▶ $contains = 1 if $value >= $min;
Branch: 1 branch
BranchTrueFalseTotal
if $value >= $min 1 0 1
555 } else {
556 3 ▶ $contains = 1 if $value > $min;
Branch: 1 branch
BranchTrueFalseTotal
if $value > $min 1 2 3
557 }
558 }
559 }
560  
561 42 return $contains;
562 }
563  
564  
565 =item B<intersection>
566  
567 Given another Interval object, modify the existing interval to include
568 the additional constraints. For example, if the current object
569 has a interval of -3 to 10, and it is merged with an external object
570 that has a interval of 0 to 20 then the interval of the current object
571 will be converted to 0 to 10 since that is consistent with both
572 intervals.
573  
574 $status = $interval->intersection( $newinterval );
575  
576 Returns true if the intersection was successful. If the intervals are
577 incompatible (no intersection) or if no object was supplied returns
578 false and the object is not modified.
579  
580 Intersections of an inverted interval with a non-inverted interval
581 can, in some circumstances, result in an intersection covering
582 two distinct bound intervals. This class can not yet support multiple
583 intervals (that would make the intersection method even more of a nightmare)
584 so the routine dies if such a situation arises.
585  
586 =cut
587  
588 # There must be a neater way of implementing this method!
589 # There may be some edge cases that fail (when one of the
590 # interval boundaries is identical in both objects)
591  
592 46 ▶sub intersection {
Subroutine intersection: called CC=61 SCAR=41.6
Pod documented
593 46 my $self = shift;
594 46 my $int2 = shift;
595  
596 # Check input
597 46 ▶ return 0 unless defined $int2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $int2 0 46 46
598 46 ▶ return 0 unless UNIVERSAL::isa($int2,"Number::Interval");
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($int2, "Number::Interval") 0 46 46
599  
600 # Create an alternate reference to $self to use in case of swapping
601 # the variables around.
602 46 my $int1 = $self;
603  
604 # Get the values
605 46 my $max1 = $int1->max;
606 46 my $min1 = $int1->min;
607 46 my $max2 = $int2->max;
608 46 my $min2 = $int2->min;
609  
610 46 my $inverted1 = $int1->isinverted;
611 46 my $inverted2 = $int2->isinverted;
612 46 ▶ my $inverted = $inverted1 || $inverted2;
Condition66%2/3
$inverted1 || $inverted2
l!l&&r!l&&!r
14032
MC/DC50%1/2
$inverted1 || $inverted2
$inverted1 $inverted2
Truth table66%2/3
A || B
A= $inverted1B= $inverted2
ABresult
1X1
011
000
613  
614 46 my $bound1 = $int1->isbound;
615 46 my $bound2 = $int2->isbound;
616 46 ▶ my $bound = $bound1 || $bound2;
Condition100%3/3
$bound1 || $bound2
l!l&&r!l&&!r
3169
MC/DC100%2/2
$bound1 || $bound2
$bound1 $bound2
Truth table100%3/3
A || B
A= $bound1B= $bound2
ABresult
1X1
011
000
617  
618 46 my $outmax;
619 my $outmin;
620  
621 # There are six possible combinations of Bound interval,
622 # inverted interval and unbound interval.
623  
624 46 ▶ if ($bound) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bound) { } 37 9 46
625 # Support BB, BU and BI and II
626  
627 37 ▶ if ($inverted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inverted) { } 14 23 37
628 # Any inverted: II or BI or IB or UI or IU
629 #print "*********** INVERTED *********\n";
630  
631 14 ▶ if ($inverted1 && $inverted2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inverted1 and $inverted2) { } 1 13 14
Condition66%2/3
$inverted1 and $inverted2
!ll&&!rl&&r
0131
MC/DC50%1/2
$inverted1 and $inverted2
$inverted1 $inverted2
Truth table66%2/3
A and B
A= $inverted1B= $inverted2
ABresult
0X0
100
111
632 # II
633 # This is fairly easy.
634 # Always take the smallest max and largest min
635 1 ▶ $outmin = ( $min1 > $min2 ? $min1 : $min2);
Branch: 1 branch
BranchTrueFalseTotal
$min1 > $min2 ? : 1 0 1
636 1 ▶ $outmax = ( $max1 < $max2 ? $max1 : $max2);
Branch: 1 branch
BranchTrueFalseTotal
$max1 < $max2 ? : 0 1 1
637  
638 } else {
639 # IB, IU (BI and UI)
640 # swap if needed, to have everything as IX
641 13 my $nowbound;
642 13 ▶ if ($inverted2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inverted2) { } 0 13 13
643 0 ($max1,$min1,$max2,$min2,$int1,$int2) =
644 ($max2,$min2,$max1,$min1,$int2,$int1);
645 # determine bound state of #1 before losing order information
646 0 $nowbound = $bound1;
647 } else {
648 # #1 is inverted so we need the bound state of #1
649 13 $nowbound = $bound2;
650 }
651  
652 13 ▶ if ($nowbound) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nowbound) { } 6 7 13
653 # IB
654 # We know that max2 and min2 are defined
655 # We always end up with at least one bound interval
656 6 ▶ if ($min2 < $max1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($min2 < $max1) { } 3 3 6
elsif ($min2 < $min1) { } 2 1 3
elsif ($min2 > $min1) { } 1 0 1
657 3 $outmin = $min2;
658  
659 # If max2 is too high we get two intervals.
660 3 ▶ croak "This intersection results in two output intervals. Currently not supported" if $max2 > $min1;
Branch: 1 branch
BranchTrueFalseTotal
if $max2 > $min1 1 2 3
661  
662 # Upper limit of interval must be the min of the two maxes
663 2 ▶ $outmax = ( $max1 < $max2 ? $max1 : $max2 );
Branch: 1 branch
BranchTrueFalseTotal
$max1 < $max2 ? : 1 1 2
664  
665 } elsif ($min2 < $min1) {
666  
667 # Make sure we intersect a little
668 # If the bound interval lies outside the inverted interval
669 # return undef
670 2 ▶ if ($max2 >= $min1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max2 >= $min1) 1 1 2
671 1 $outmin = $min1;
672 1 $outmax = $max2;
673 }
674  
675 } elsif ($min2 > $min1) {
676  
677 # This is just the bound interval
678 1 $outmin = $min2;
679 1 $outmax = $max2;
680  
681  
682 } else {
683 0 croak "Oops Bug in interval intersection [6]\n".
684 _formaterr( $min1, $max1, $min2, $max2);
685 }
686  
687  
688 } else {
689 # IU
690 7 ▶ if (defined $max2) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $max2) { } 3 4 7
elsif (defined $min2) { } 3 1 4
691  
692 # The upper bound must be below the inverted "min"
693 # else we get intersection of two intervals
694 3 ▶ if ($max2 > $min1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($max2 > $min1) { } 1 2 3
elsif ($max2 > $max1) { } 1 1 2
695 1 croak "This intersection results in two output intervals. Currently not supported";
696 } elsif ($max2 > $max1) {
697 # Just use the inverted interval
698 1 $outmax = $max1;
699 1 $outmin = $min1;
700 } else {
701 # max must be decreased to include min2
702 1 $outmax = $max2;
703 1 $outmin = $min1;
704 }
705  
706  
707 } elsif (defined $min2) {
708  
709 # The lower bound must be above the "max"
710 # else we get an intersection of two intervals
711 3 ▶ if ($min2 < $max1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($min2 < $max1) { } 1 2 3
elsif ($min2 < $min1) { } 1 1 2
712 1 croak "This intersection results in two output intervals. Currently not supported";
713 } elsif ($min2 < $min1) {
714 # Just use the inverted interval
715 1 $outmax = $max1;
716 1 $outmin = $min1;
717 } else {
718 # min must be increased to include min2
719 1 $outmax = $max1;
720 1 $outmin = $min2;
721 }
722  
723 } else {
724 # both undefined
725 1 $outmax = $max1;
726 1 $outmin = $min1;
727 }
728  
729 }
730  
731 }
732  
733  
734  
735 } else {
736 # BB, BU or UB
737 #print "*********** BOUND NON INVERTED ************\n";
738 23 ▶ if ($bound1 and $bound2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bound1 and $bound2) { } 8 15 23
Condition100%3/3
$bound1 and $bound2
!ll&&!rl&&r
698
MC/DC100%2/2
$bound1 and $bound2
$bound1 $bound2
Truth table100%3/3
A and B
A= $bound1B= $bound2
ABresult
0X0
100
111
739 # BB
740 #print "---------- BB -----------\n";
741 8 ▶ $outmin = ( $min1 > $min2 ? $min1 : $min2 );
Branch: 1 branch
BranchTrueFalseTotal
$min1 > $min2 ? : 0 8 8
742 8 ▶ $outmax = ( $max1 < $max2 ? $max1 : $max2 );
Branch: 1 branch
BranchTrueFalseTotal
$max1 < $max2 ? : 6 2 8
743  
744 # Check that we really are overlapping
745 8 ▶ if ($outmax < $outmin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outmax < $outmin) 1 7 8
746 # oops - intervals did not intersect. Reset
747 1 $outmin = $outmax = undef;
748 }
749
750  
751 } else {
752 # BU and UB
753 #print "---------- BU/UB -----------\n";
754 # swap if needed, to have everything as BU
755 15 ▶ if ($bound2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bound2) 6 9 15
756 6 ($max1,$min1,$max2,$min2,$int1,$int2) =
757 ($max2,$min2,$max1,$min1,$int2,$int1);
758 }
759  
760 # unbound is now guaranteed to be (2)
761 # Check that unbound max is in interval
762 15 ▶ if (defined $max2) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $max2) { } 8 7 15
elsif (defined $min2) { } 5 2 7
763 8 ▶ if ($max2 <= $max1 && $max2 >= $min1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($max2 <= $max1 and $max2 >= $min1) { } 2 6 8
elsif ($max2 <= $min1) { } 0 6 6
elsif ($max2 >= $max1) { } 6 0 6
Condition66%2/3
$max2 <= $max1 and $max2 >= $min1
!ll&&!rl&&r
602
MC/DC50%1/2
$max2 <= $max1 and $max2 >= $min1
$max2 <= $max1 $max2 >= $min1
Truth table66%2/3
A and B
A= $max2 <= $max1B= $max2 >= $min1
ABresult
0X0
100
111
764 # inside interval
765 2 $outmax = $max2;
766 2 $outmin = $min1;
767 } elsif ($max2 <= $min1) {
768 # outside interval. No intersection
769 } elsif ($max2 >= $max1) {
770 # below interval. irrelevant
771 6 $outmax = $max1;
772 6 $outmin = $min1;
773 } else {
774 0 croak "Number::Interval - This should not happen[2]\n".
775 _formaterr( $min1, $max1, $min2, $max2);
776 }
777  
778 } elsif (defined $min2) {
779 5 ▶ if ($min2 <= $max1 && $min2 >= $min1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($min2 <= $max1 and $min2 >= $min1) { } 3 2 5
elsif ($min2 >= $max1) { } 1 1 2
elsif ($min2 <= $min1) { } 1 0 1
Condition100%3/3
$min2 <= $max1 and $min2 >= $min1
!ll&&!rl&&r
113
MC/DC100%2/2
$min2 <= $max1 and $min2 >= $min1
$min2 <= $max1 $min2 >= $min1
Truth table100%3/3
A and B
A= $min2 <= $max1B= $min2 >= $min1
ABresult
0X0
100
111
780 # inside interval
781 3 $outmax = $max1;
782 3 $outmin = $min2;
783 } elsif ($min2 >= $max1) {
784 # outside interval. No intersection
785 } elsif ($min2 <= $min1) {
786 # below interval. irrelevant
787 1 $outmax = $max1;
788 1 $outmin = $min1;
789 } else {
790 0 croak "Number::Interval - This should not happen[3]:\n" .
791 _formaterr( $min1, $max1, $min2, $max2);
792 }
793  
794 } else {
795 # The second interval is unbounded at both ends
796 2 $outmax = $max1;
797 2 $outmin = $min1;
798 }
799  
800  
801 }
802  
803 }
804  
805  
806 } else {
807 # Unbound+Unbound only
808 # Four options here.
809 # 1. A max and a max => max (same for min and min)
810 # 2. max and a min with no overlap => no intersection
811 # 3. max and min with overlap => bounded interval
812 # 4. all undefined
813 9 ▶ if (defined $max1 && defined $max2) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $max1 and defined $max2) { } 1 8 9
elsif (defined $min2 and defined $min1) { } 1 7 8
Condition100%3/3
defined $max1 and defined $max2
!ll&&!rl&&r
531
MC/DC100%2/2
defined $max1 and defined $max2
defined $max1 defined $max2
Truth table100%3/3
A and B
A= defined $max1B= defined $max2
ABresult
0X0
100
111
814 1 ▶ $outmax = ( $max1 < $max2 ? $max1 : $max2 );
Branch: 1 branch
BranchTrueFalseTotal
$max1 < $max2 ? : 1 0 1
815 ▶ } elsif (defined $min2 && defined $min1) {
Condition100%3/3
defined $min2 and defined $min1
!ll&&!rl&&r
431
MC/DC100%2/2
defined $min2 and defined $min1
defined $min2 defined $min1
Truth table100%3/3
A and B
A= defined $min2B= defined $min1
ABresult
0X0
100
111
816 1 ▶ $outmin = ( $min1 > $min2 ? $min1 : $min2 );
Branch: 1 branch
BranchTrueFalseTotal
$min1 > $min2 ? : 0 1 1
817 } else {
818 # max and a min - one must be defined for both
819 7 ▶ my $refmax = (defined $max1 ? $max1 : $max2);
Branch: 1 branch
BranchTrueFalseTotal
defined $max1 ? : 3 4 7
820 7 ▶ my $refmin = (defined $min1 ? $min1 : $min2);
Branch: 1 branch
BranchTrueFalseTotal
defined $min1 ? : 2 5 7
821  
822 7 ▶ if (!defined $refmax && !defined $refmin) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $refmax || defined $refmin) { } 1 6 7
elsif (not defined $refmax) { } 1 5 6
elsif (not defined $refmin) { } 1 4 5
elsif ($refmax > $refmin) { } 2 2 4
Condition100%3/3
defined $refmax || defined $refmin
l!l&&r!l&&!r
511
MC/DC100%2/2
defined $refmax || defined $refmin
defined $refmax defined $refmin
Truth table100%3/3
A || B
A= defined $refmaxB= defined $refmin
ABresult
1X1
011
000
823 # infinite bound
824 1 return 1;
825 } elsif (!defined $refmax) {
826 # just a min
827 1 $outmin = $refmin;
828 } elsif (!defined $refmin) {
829 # just a max
830 1 $outmax = $refmax;
831 } elsif ($refmax > $refmin) {
832 # normal bound interval
833 2 $outmax = $refmax;
834 2 $outmin = $refmin;
835 } else {
836 # unbound interval. No intersection
837 }
838  
839  
840 }
841  
842 }
843  
844  
845 # Modify object if we have new values
846 42 ▶ if (defined $outmax or defined $outmin) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $outmax or defined $outmin) { } 37 5 42
Condition100%3/3
defined $outmax or defined $outmin
l!l&&r!l&&!r
3525
MC/DC100%2/2
defined $outmax or defined $outmin
defined $outmax defined $outmin
Truth table100%3/3
A or B
A= defined $outmaxB= defined $outmin
ABresult
1X1
011
000
847 # Need to check the inc_min and inc_max settings
848 37 my $inc_max = $self->_checkinc( $outmax, $max1, $max2,
849 $int1->inc_max, $int2->inc_max );
850 37 my $inc_min = $self->_checkinc( $outmin, $min1, $min2,
851 $int1->inc_min, $int2->inc_min );
852  
853 # Abort if the min and max are the same and we
854 # are not including the bounds in the interval
855 37 ▶ if (defined $outmax && defined $outmin &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $outmax and defined $outmin and $outmax == $outmin and not $inc_max && $inc_min) 4 33 37
Condition91%11/12
defined $outmax and defined $outmin and $outmax == $outmin and not $inc_max && $inc_min
!ll&&!rl&&r
3034
defined $outmax and defined $outmin and $outmax == $outmin
!ll&&!rl&&r
4267
defined $outmax and defined $outmin
!ll&&!rl&&r
2233
$inc_max && $inc_min
!ll&&!rl&&r
403
MC/DC80%4/5
defined $outmax and defined $outmin and $outmax == $outmin and not $inc_max && $inc_min
defined $outmax defined $outmin $outmax == $outmin $inc_max $inc_min
Truth table83%5/6
A and B and C and not(D && E)
A= defined $outmaxB= defined $outminC= $outmax == $outminD= $inc_maxE= $inc_min
ABCDEresult
0XXXX0
10XXX0
110XX0
111110
1110X1
111101
856 $outmax == $outmin &&
857 (!$inc_max || !$inc_min)
858 ) {
859 4 return 0;
860 }
861  
862 33 $self->inc_min( $inc_min );
863 33 $self->inc_max( $inc_max );
864 33 $self->max($outmax);
865 33 $self->min($outmin);
866 33 return 1;
867 } else {
868 5 return 0;
869 }
870  
871 }
872  
873 # Given
874 74 ▶sub _checkinc {
Subroutine _checkinc: called CC=10 SCAR=23.0
875 74 my $self = shift;
876 74 my $newval = shift;
877 74 my $ref1 = shift;
878 74 my $ref2 = shift;
879 74 my $inc1 = shift;
880 74 my $inc2 = shift;
881  
882 74 my $inc_val = $inc1;
883 74 ▶ if (defined $newval) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newval) 70 4 74
884 70 ▶ if (defined $ref1 && $ref1 == $newval &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ref1 and $ref1 == $newval and defined $ref2 and $ref2 == $newval) { } 4 66 70
elsif (defined $ref2 and $ref2 == $newval) { } 23 68 91
Condition100%9/9
defined $ref1 and $ref1 == $newval and defined $ref2 and $ref2 == $newval
!ll&&!rl&&r
48184
defined $ref1 and $ref1 == $newval and defined $ref2
!ll&&!rl&&r
232522
defined $ref1 and $ref1 == $newval
!ll&&!rl&&r
32047
MC/DC100%4/4
defined $ref1 and $ref1 == $newval and defined $ref2 and $ref2 == $newval
defined $ref1 $ref1 == $newval defined $ref2 $ref2 == $newval
Truth table100%5/5
A and B and C and D
A= defined $ref1B= $ref1 == $newvalC= defined $ref2D= $ref2 == $newval
ABCDresult
0XXX0
10XX0
110X0
11100
11111
885 defined $ref2 && $ref2 == $newval) {
886 # value comes from both so we want the least
887 # inclusive inc_max value
888 4 ▶ $inc_val = 0 if (!$inc1 || !$inc2);
Branch: 1 branch
BranchTrueFalseTotal
unless $inc1 and $inc2 4 0 4
Condition66%2/3
$inc1 and $inc2
!ll&&!rl&&r
310
MC/DC0%0/2
$inc1 and $inc2
$inc1 $inc2
Truth table66%2/3
A and B
A= $inc1B= $inc2
ABresult
0X0
100
111
889 ▶ } elsif (defined $ref2 && $ref2 == $newval) {
Condition100%3/3
defined $ref2 and $ref2 == $newval
!ll&&!rl&&r
251823
MC/DC100%2/2
defined $ref2 and $ref2 == $newval
defined $ref2 $ref2 == $newval
Truth table100%3/3
A and B
A= defined $ref2B= $ref2 == $newval
ABresult
0X0
100
111
890 # this value comes from ref2 so we copy
891 # inc from #2
892 23 $inc_val = $inc2;
893 }
894 }
895 74 return $inc_val;
896 }
897  
898 0 ▶sub _formaterr {
Subroutine _formaterr: not called CC=5 SCAR=34.0
899 0 my ($min1, $max1, $min2, $max2) = @_;
900 0 ▶ return "Comparing : (".
Branch: 4 branches
BranchTrueFalseTotal
defined $min1 ? : 0 0 0
defined $max1 ? : 0 0 0
defined $min2 ? : 0 0 0
defined $max2 ? : 0 0 0
901 (defined $min1 ? $min1 : "<undef>" ).
902 "," .
903 (defined $max1 ? $max1 : "<undef>" ).
904 ") with (".
905 (defined $min2 ? $min2 : "<undef>" ).
906 "," . (defined $max2 ? $max2 : "<undef>" ).
907 ")";
908 }
909  
910 =back
911  
912 =head1 NOTES
913  
914 The default interval is not inclusive of the bounds.
915  
916 =head1 COPYRIGHT
917  
918 Copyright (C) 2009-2011 Science and Technology Facilities Council.
919 Copyright (C) 2002-2005 Particle Physics and Astronomy Research Council.
920 All Rights Reserved.
921  
922 This program is free software; you can redistribute it and/or modify it under
923 the terms of the GNU General Public License as published by the Free Software
924 Foundation; either version 2 of the License, or (at your option) any later
925 version.
926  
927 This program is distributed in the hope that it will be useful,but WITHOUT ANY
928 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
929 PARTICULAR PURPOSE. See the GNU General Public License for more details.
930  
931 You should have received a copy of the GNU General Public License along with
932 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
933 Place,Suite 330, Boston, MA 02111-1307, USA
934  
935 =head1 AUTHOR
936  
937 Tim Jenness E<lt>tjenness@cpan.orgE<gt>.
938  
939 =cut
940  
941 1 1;
942  
↑ Summary