lib/Date/Roman.pm

filter: Statementstmt 94.5% 261 / 276 Branchbran 81.8% 149 / 182 Conditioncond 79.5% 140 / 176 MC/DCmcdc 60.4% 49 / 81 Subroutinesub 92.8% 26 / 28 Podpod 100% 7 / 7 totaltotal 84.2% 632 / 750 CC 156 SCAR 28.9
CC
156
Cov
87%
_check_ical
33.5
_normalize_roman_date
28.2
as_string
27.7
CRAP 17.9
↑ Summary script/RomanDate »
1 package Date::Roman;
2 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use Roman qw(); #do not import roman and Roman, we want define our
Subroutine BEGIN: called CC=1 SCAR=0.0
4 #'roman' sub, which does something entierly different
5 #from Roman::roman
6  
7 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶use constant LastJulian => 1582;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Symbolic constants to identify fixed days
14  
15 11 ▶use constant Kalendae => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use constant Nonae => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use constant Idibus => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 11 $VERSION = '1.06';
20  
21 # Array local variables containing months' names
22 11 my @MONS_SHORT = ('','Ian.','Feb.','Mar.','Apr.','Mai.','Iun.',
23 'Iul.','Aug.','Sep.','Oct.','Nov.','Dec.');
24  
25 11 my @MONS = ('','Ianuarias','Februarias','Martias','Apriles',
26 'Maias','Iunias','Iulias','Augustas','Septembres',
27 'Octobres','Novembres','Decembres');
28  
29 11 my @MONS_FD = ('','Ianuariis','Februariis','Martiis','Aprilibus',
30 'Maiis','Iuniis','Iuliis','Augustis','Septembribus',
31 'Octobribus','Novembribus','Decembribus');
32  
33  
34 # Array local variables containing fixed day names (Nota: the indexing
35 # is based on the constants above).
36  
37 11 my @FD_SHORT = ('Kal.','Non.','Id.');
38 11 my @FD = ('Kalendas','Nonas','Idus');
39 11 my @FD_FD = ('Kalendis','Nonis','Idibus');
40  
41  
42  
43  
44 4029 ▶sub new {
Subroutine new: called CC=20 SCAR=31.8
Pod documented
45 4029 my $class = shift;
46 4029 my ($ical,$roman);
47
48 # default behavior: Date::Roman->new() is the same thing as
49 # Date::Roman->new(epoch => time())
50
51 4029 ▶ @_ = ('epoch',time()) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 4029 4029
52  
53 4029 ▶ if (ref($_[0])) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $_[0]) { } 0 4029 4029
elsif ($_[0] eq 'roman') { } 737 3292 4029
elsif ($_[0] eq 'ical') { } 732 2560 3292
elsif ($_[0] eq 'epoch') { } 1096 1464 2560
54 0 my $dateobject = shift;
55 0 ▶ if ($dateobject->can('roman')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dateobject->can('roman')) { } 0 0 0
elsif ($dateobject->can('ical')) { } 0 0 0
56 0 $roman = _parse_roman($dateobject->roman());
57 }
58 elsif ($dateobject->can('ical')) {
59 0 $ical = _parse_ical($dateobject->ical());
60 }
61 else {
62 0 croak "Bad parameter to ",__PACKAGE__,"::new()";
63 }
64 }
65 elsif ($_[0] eq 'roman') {
66 737 $roman = _parse_roman($_[1]);
67 }
68 elsif ($_[0] eq 'ical') {
69 732 $ical = _parse_ical($_[1]);
70 }
71 elsif ($_[0] eq 'epoch') {
72 1096 my ($day,$month,$year) = (localtime($_[1]))[3,4,5];
73 1096 $ical->{day} = $day;
74 1096 $ical->{month} = $month + 1;
75 1096 $ical->{year} = $year + 1900;
76 }
77 else {
78 1464 my %args = @_;
79 1464 ▶ if (grep {exists $args{$_}} qw(base mons annus)) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {exists $args{$_};} 'base', 'mons', 'annus') { } 731 733 1464
elsif (grep {exists $args{$_};} 'day', 'month', 'year') { } 733 0 733
80 731 ▶ $args{ad} = 1 unless exists $args{ad};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"ad"} 72 659 731
81 731 ▶ $args{bis} = 0 unless exists $args{bis};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"bis"} 730 1 731
82 731 $args{base} = lc($args{base});
83 $args{base} = ($args{base} eq 'kal') ? Kalendae :
84 731 ▶ (($args{base} eq 'non') ? Nonae : Idibus);
Branch: 2 branches
BranchTrueFalseTotal
$args{'base'} eq 'kal' ? : 427 304 731
$args{'base'} eq 'non' ? : 112 192 304
85  
86 731 foreach (qw(base mons annus)) {
87 2193 ▶ croak "Parameter $_ is mandatory" unless exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$_} 0 2193 2193
88 }
89  
90 #I hate it...
91 731 foreach (qw(ad mons annus)) {
92 2193 $args{$_} += 0;
93 }
94  
95 731 _check_roman(\%args);
96 731 $roman = \%args;
97 }
98 2199 elsif (grep {exists $args{$_}} qw(day month year)) {
99 #I hate it...
100 733 foreach (keys %args) {
101 2199 ▶ croak "Parameter $_ mandatory" unless exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$_} 0 2199 2199
102 2199 $args{$_} += 0;
103 }
104 733 _check_ical(\%args);
105 733 $ical = \%args;
106 }
107 else {
108 0 croak "Bad parameters to ",__PACKAGE__,"::new()";
109 }
110 }
111  
112 4029 ▶ $roman = _ical_to_roman($ical) unless $roman;
Branch: 1 branch
BranchTrueFalseTotal
unless $roman 2561 1468 4029
113  
114
115 4029 bless $roman,$class;
116 }
117  
118 8405 ▶sub roman {
Subroutine roman: called CC=6 SCAR=17.9
Pod documented
119 8405 my $self = shift;
120
121 8405 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 731 7674 8405
122 731 my $roman = shift;
123 731 my $rhash = _parse_roman($roman);
124 731 ▶ if ($rhash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhash) { } 731 0 731
125 731 %{$self} = %{$rhash};
126 }
127 else {
128 0 carp __PACKAGE__," Malformed roman date string $roman";
129 }
130 }
131
132 8405 my $result;
133 8405 ▶ if ($self->{bis}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'bis'}) { } 10 8395 8405
elsif ($self->{'ad'} == 2) { } 829 7566 8395
elsif ($self->{'ad'} > 2) { } 6733 833 7566
134 10 $result = "b6 ";
135 }
136 elsif ($self->{ad} == 2) {
137 829 $result = "pd ";
138 }
139 elsif ($self->{ad} > 2) {
140 6733 $result = "$self->{ad} ";
141 }
142  
143 8405 $result .= (qw(kal non id))[$self->{base}];
144  
145 8405 $result .= " $self->{mons} $self->{annus}";
146  
147 8405 return $result;
148 }
149  
150  
151 6215 ▶sub ical {
Subroutine ical: called CC=4 SCAR=13.9
Pod documented
152 6215 my $self = shift;
153 6215 my $ihash;
154  
155 6215 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 731 5484 6215
156 731 my $ical = shift;
157 731 $ihash = _parse_ical($ical);
158 731 ▶ if ($ihash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ihash) { } 731 0 731
159 731 my $rhash = _ical_to_roman($ihash);
160 731 %{$self} = %{$rhash};
161 }
162 else {
163 0 carp __PACKAGE__," Malformed ical string $ical";
164 }
165 }
166
167 6215 ▶ unless ($ihash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ihash) 5484 731 6215
168 5484 $ihash = _roman_to_ical($self);
169 }
170
171 6215 sprintf "%d%0.2d%0.2d",$ihash->{year},$ihash->{month},$ihash->{day};
172 }
173  
174  
175  
176 2190 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod documented
177 2190 my $self = shift;
178 2190 my ($days) = @_;
179 2190 my $class = ref($self);
180  
181 2190 my %result = %{$self};
182 2190 $result{ad} -= $days;
183
184 2190 _normalize_roman_date(\%result);
185  
186 2190 bless \%result,$class;
187 }
188  
189 0 ▶sub postridie {
Subroutine postridie: not called CC=1 SCAR=6.9
Pod documented
190 0 $_[0]->add(1);
191 }
192  
193 0 ▶sub heri {
Subroutine heri: not called CC=1 SCAR=6.9
Pod documented
194 0 $_[0]->add(-1);
195 }
196  
197  
198 26 ▶sub as_string {
Subroutine as_string: called CC=26 SCAR=33.2
Pod documented
199 26 my $self = shift;
200 26 my %args = @_;
201 26 my %params = ();
202 26 my $string = "";
203  
204 26 ▶ $params{prefix} = $args{prefix} ||$args{words} || 'abbrev';
Condition80%4/5
$args{'prefix'} || $args{'words'} || 'abbrev'
l!l
1016
$args{"prefix"} or $args{"words"}
l!l&&r!l&&!r
01016
MC/DC50%1/2
$args{'prefix'} || $args{'words'} || 'abbrev'
$args{"prefix"} $args{"words"}
Truth table66%2/3
A or B
A= $args{"prefix"}B= $args{"words"}
ABresult
1X1
011
000
205 26 ▶ $params{die} = $args{die} || $args{num} || 'Roman';
Condition80%4/5
$args{'die'} || $args{'num'} || 'Roman'
l!l
620
$args{"die"} or $args{"num"}
l!l&&r!l&&!r
0620
MC/DC50%1/2
$args{'die'} || $args{'num'} || 'Roman'
$args{"die"} $args{"num"}
Truth table66%2/3
A or B
A= $args{"die"}B= $args{"num"}
ABresult
1X1
011
000
206 26 ▶ $params{mons} = $args{mons} || $args{words} || 'abbrev';
Condition100%5/5
$args{'mons'} || $args{'words'} || 'abbrev'
l!l
1610
$args{"mons"} or $args{"words"}
l!l&&r!l&&!r
61010
MC/DC100%2/2
$args{'mons'} || $args{'words'} || 'abbrev'
$args{"mons"} $args{"words"}
Truth table100%3/3
A or B
A= $args{"mons"}B= $args{"words"}
ABresult
1X1
011
000
207 26 ▶ $params{fday} = $args{fday} || $args{words} || 'abbrev';
Condition100%5/5
$args{'fday'} || $args{'words'} || 'abbrev'
l!l
197
$args{"fday"} or $args{"words"}
l!l&&r!l&&!r
9107
MC/DC100%2/2
$args{'fday'} || $args{'words'} || 'abbrev'
$args{"fday"} $args{"words"}
Truth table100%3/3
A or B
A= $args{"fday"}B= $args{"words"}
ABresult
1X1
011
000
208 26 ▶ $params{annus} = $args{annus} || $args{num} || 'Roman';
Condition100%5/5
$args{'annus'} || $args{'num'} || 'Roman'
l!l
1511
$args{"annus"} or $args{"num"}
l!l&&r!l&&!r
9611
MC/DC100%2/2
$args{'annus'} || $args{'num'} || 'Roman'
$args{"annus"} $args{"num"}
Truth table100%3/3
A or B
A= $args{"annus"}B= $args{"num"}
ABresult
1X1
011
000
209 26 ▶ $params{auc} = $args{auc} || $args{words} || 'abbrev';
Condition100%5/5
$args{'auc'} || $args{'words'} || 'abbrev'
l!l
1016
$args{"auc"} or $args{"words"}
l!l&&r!l&&!r
4616
MC/DC100%2/2
$args{'auc'} || $args{'words'} || 'abbrev'
$args{"auc"} $args{"words"}
Truth table100%3/3
A or B
A= $args{"auc"}B= $args{"words"}
ABresult
1X1
011
000
210  
211 26 ▶ if ($self->{ad} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'ad'} == 2) { } 0 26 26
elsif ($self->{'ad'} > 2) { } 18 8 26
212 0 ▶ $string = ($params{prefix} eq 'abbrev') ? "p.d. " : "pridie ";
Branch: 1 branch
BranchTrueFalseTotal
$params{'prefix'} eq 'abbrev' ? : 0 0 0
213 }
214 elsif ($self->{ad} > 2) {
215 18 ▶ $string = ($params{prefix} eq 'abbrev') ? "a.d. " : "ante diem ";
Branch: 1 branch
BranchTrueFalseTotal
$params{'prefix'} eq 'abbrev' ? : 13 5 18
216 18 ▶ if ($params{die} eq 'Roman') {
Branch: 2 branches
BranchTrueFalseTotal
if ($params{'die'} eq 'Roman') { } 16 2 18
elsif ($params{'die'} eq 'roman') { } 2 0 2
217 16 $string .= Roman::Roman($self->{ad});
218 }
219 elsif ($params{die} eq 'roman') {
220 2 $string .= Roman::roman($self->{ad});
221 }
222 else {
223 0 $string .= $self->{ad};
224 }
225 18 $string .= " ";
226 }
227  
228
229 26 ▶ if ($params{fday} eq 'abbrev') {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'fday'} eq 'abbrev') { } 16 10 26
230 16 $string .= $FD_SHORT[$self->{base}]." ";
231 }
232 else {
233 10 ▶ $string .= ($self->{ad} == 0) ? "$FD_FD[$self->{base}] "
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ad'} == 0 ? : 0 10 10
234 : "$FD[$self->{base}] ";
235 }
236  
237 26 ▶ if ($params{mons} eq 'abbrev') {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'mons'} eq 'abbrev') { } 16 10 26
238 16 $string .= "$MONS_SHORT[$self->{mons}] ";
239 }
240 else {
241 10 ▶ $string .= ($self->{ad} == 0) ? $MONS_FD[$self->{mons}] : $MONS[$self->{mons}];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ad'} == 0 ? : 0 10 10
242 10 $string .= " ";
243 }
244  
245 26 ▶ if ($params{annus} eq 'Roman') {
Branch: 2 branches
BranchTrueFalseTotal
if ($params{'annus'} eq 'Roman') { } 20 6 26
elsif ($params{'annus'} eq 'roman') { } 6 0 6
246 20 $string .= Roman::Roman($self->{annus});
247 }
248 elsif ($params{annus} eq 'roman') {
249 6 $string .= Roman::roman($self->{annus});
250 }
251 else {
252 0 $string .= $self->{annus};
253 }
254  
255 26 ▶ if ($params{auc} eq 'abbrev') {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'auc'} eq 'abbrev') { } 23 3 26
256 23 $string .= " AUC";
257 }
258 else {
259 3 $string .= " ab Urbe Condida";
260 }
261  
262 26 return $string;
263 }
264  
265  
266  
267  
268 #private subroutines
269  
270 # _parse_roman: takes a roman date string and returns a reference to
271 # an hash describing the corresponding roman date and ready to be
272 # blessed.
273  
274 11 my $roman_date_regexp = qr/^(?:(b6|pd|\d+)\s+)?(kal|non|id)\s+(\d+)\s+(\d+)/i;
275  
276 1468 ▶sub _parse_roman {
Subroutine _parse_roman: called CC=8 SCAR=20.9
277 1468 my $datestring = shift;
278  
279 1468 my %result = (bis => 0);
280 1468 ▶ unless ($datestring =~ /$roman_date_regexp/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($datestring =~ /$roman_date_regexp/) 0 1468 1468
281 0 croak "Malformed roman date string: $datestring";
282 }
283
284 1468 my ($prefix,$base,$mons,$annus) = map lc,($1,$2,$3,$4);
285  
286 1468 ▶ if (!$prefix) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $prefix) { } 147 1321 1468
elsif ($prefix eq 'pd') { } 145 1176 1321
elsif ($prefix eq 'b6') { } 3 1173 1176
287 147 $result{ad} = 1;
288 }
289 elsif ($prefix eq 'pd') {
290 145 $result{ad} = 2;
291 }
292 elsif ($prefix eq 'b6') {
293 3 $result{ad} = 6;
294 3 $result{bis} = 1;
295 }
296 else {
297 1173 $result{ad} = $prefix;
298 }
299  
300 1468 ▶ $result{base} = ($base eq 'kal') ? Kalendae :
Branch: 2 branches
BranchTrueFalseTotal
$base eq 'kal' ? : 858 610 1468
$base eq 'non' ? : 224 386 610
301 (($base eq 'non') ? Nonae : Idibus);
302  
303 1468 $result{mons} = $mons;
304 1468 $result{annus} = $annus;
305  
306 #sanity checks
307 1468 ▶ _check_roman(\%result) || carp "Malformed Roman date hash";
Branch: 1 branch
BranchTrueFalseTotal
_check_roman(\%result) or carp("Malformed Roman date hash") 1468 0 1468
308  
309 1468 return \%result;
310
311 }
312  
313 # _check_roman: given a reference to an hash supposed to define a date
314 # in the Roman format (such the one returned by _parse_roman) it
315 # returns true if and only if the hash repesents a correct date.
316  
317 2199 ▶sub _check_roman {
Subroutine _check_roman: called CC=10 SCAR=29.4
318 2199 my $rhr = shift;
319  
320 2199 ▶ return undef unless $rhr->{base} >= Kalendae and $rhr->{base} <= Idibus;
Branch: 1 branch
BranchTrueFalseTotal
unless $rhr->{"base"} >= 0 and $rhr->{"base"} <= 2 0 2199 2199
Condition33%1/3
$rhr->{"base"} >= 0 and $rhr->{"base"} <= 2
!ll&&!rl&&r
002199
MC/DC0%0/2
$rhr->{"base"} >= 0 and $rhr->{"base"} <= 2
$rhr->{"base"} >= 0 $rhr->{"base"} <= 2
Truth table33%1/3
A and B
A= $rhr->{"base"} >= 0B= $rhr->{"base"} <= 2
ABresult
0X0
100
111
321 2199 ▶ return undef unless ($rhr->{mons} >= 1) and ($rhr->{mons} <= 12);
Branch: 1 branch
BranchTrueFalseTotal
unless $rhr->{"mons"} >= 1 and $rhr->{"mons"} <= 12 0 2199 2199
Condition33%1/3
$rhr->{"mons"} >= 1 and $rhr->{"mons"} <= 12
!ll&&!rl&&r
002199
MC/DC0%0/2
$rhr->{"mons"} >= 1 and $rhr->{"mons"} <= 12
$rhr->{"mons"} >= 1 $rhr->{"mons"} <= 12
Truth table33%1/3
A and B
A= $rhr->{"mons"} >= 1B= $rhr->{"mons"} <= 12
ABresult
0X0
100
111
322 return undef if $rhr->{bis} and ($rhr->{base} != Kalendae or
323 $rhr->{mons} != 3 or
324 2199 ▶ ! _leap($rhr->{annus},'roman'));
Branch: 1 branch
BranchTrueFalseTotal
if $rhr->{"bis"} and $rhr->{"base"} != 0 || $rhr->{"mons"} != 3 || !_leap($rhr->{"annus"}, "roman") 0 2199 2199
Condition44%4/9
$rhr->{"bis"} and $rhr->{"base"} != 0 || $rhr->{"mons"} != 3 || !_leap($rhr->{"annus"}, "roman")
!ll&&!rl&&r
219540
$rhr->{"base"} != 0 or $rhr->{"mons"} != 3 or not _leap($rhr->{"annus"}, "roman")
l!l&&r!l&&!r
004
$rhr->{"base"} != 0 or $rhr->{"mons"} != 3
l!l&&r!l&&!r
004
MC/DC0%0/4
$rhr->{"bis"} and $rhr->{"base"} != 0 || $rhr->{"mons"} != 3 || !_leap($rhr->{"annus"}, "roman")
$rhr->{"bis"} $rhr->{"base"} != 0 $rhr->{"mons"} != 3 not _leap($rhr->{"annus"}, "roman")
Truth table40%2/5
A and B or C or not(D)
A= $rhr->{"bis"}B= $rhr->{"base"} != 0C= $rhr->{"mons"} != 3D= not _leap($rhr->{"annus"}, "roman")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
325 2199 ▶ return undef unless $rhr->{ad} <= _days_before($rhr->{base},$rhr->{mons});
Branch: 1 branch
BranchTrueFalseTotal
unless $rhr->{"ad"} <= _days_before($rhr->{"base"}, $rhr->{"mons"}) 0 2199 2199
326 2199 return 1;
327 }
328  
329  
330 # _parse_ical: takes a ical date string and returns a reference to
331 # an hash describing the corresponding date.
332  
333 11 my $ical_date_regexp = qr/^(-?\d+)(\d\d)(\d\d)(?:$|T)/;
334  
335 1463 ▶sub _parse_ical {
Subroutine _parse_ical: called CC=3 SCAR=11.6
336 1463 my $datestring = shift;
337 1463 my %result = ();
338  
339 1463 ▶ unless (@result{'year','month','day'} = map {$_+0} ($datestring =~ /$ical_date_regexp/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@result{"year", "month", "day"} = map({$_ + 0;} $datestring =~ /$ical_date_regexp/)) 0 1463 1463
340 0 croak "Malformed ical date string: $datestring";
341 }
342  
343 #sanity check
344 1463 ▶ _check_ical(\%result) || carp "Malformed ical date hash";
Branch: 1 branch
BranchTrueFalseTotal
_check_ical(\%result) or carp("Malformed ical date hash") 1463 0 1463
345  
346 1463 return \%result;
347 }
348  
349 # _check_ical: given a reference to an hash supposed to define a date
350 # in the ical format (such the one returned by _parse_ical) it
351 # returns true if and only if the hash repesents a correct date.
352 2196 ▶sub _check_ical {
Subroutine _check_ical: called CC=14 SCAR=35.1
353 2196 my $ihr = shift;
354  
355 return undef if ($ihr->{month} < 1 or
356 2196 ▶ $ihr->{month} > 12);
Branch: 1 branch
BranchTrueFalseTotal
if $ihr->{"month"} < 1 or $ihr->{"month"} > 12 0 2196 2196
Condition33%1/3
$ihr->{"month"} < 1 or $ihr->{"month"} > 12
l!l&&r!l&&!r
002196
MC/DC0%0/2
$ihr->{"month"} < 1 or $ihr->{"month"} > 12
$ihr->{"month"} < 1 $ihr->{"month"} > 12
Truth table33%1/3
A or B
A= $ihr->{"month"} < 1B= $ihr->{"month"} > 12
ABresult
1X1
011
000
357  
358 return undef if ($ihr->{day} <= 0 or
359 2196 ▶ $ihr->{day} > 31);
Branch: 1 branch
BranchTrueFalseTotal
if $ihr->{"day"} <= 0 or $ihr->{"day"} > 31 0 2196 2196
Condition33%1/3
$ihr->{"day"} <= 0 or $ihr->{"day"} > 31
l!l&&r!l&&!r
002196
MC/DC0%0/2
$ihr->{"day"} <= 0 or $ihr->{"day"} > 31
$ihr->{"day"} <= 0 $ihr->{"day"} > 31
Truth table33%1/3
A or B
A= $ihr->{"day"} <= 0B= $ihr->{"day"} > 31
ABresult
1X1
011
000
360  
361 return undef if ($ihr->{day} > 30 and
362 ($ihr->{month} == 4 or $ihr->{month} == 6 or
363 2196 ▶ $ihr->{month} == 9 or $ihr->{month} == 11));
Branch: 1 branch
BranchTrueFalseTotal
if $ihr->{"day"} > 30 and $ihr->{"month"} == 4 || $ihr->{"month"} == 6 || $ihr->{"month"} == 9 || $ihr->{"month"} == 11 0 2196 2196
Condition41%5/12
$ihr->{"day"} > 30 and $ihr->{"month"} == 4 || $ihr->{"month"} == 6 || $ihr->{"month"} == 9 || $ihr->{"month"} == 11
!ll&&!rl&&r
2154420
$ihr->{"month"} == 4 or $ihr->{"month"} == 6 or $ihr->{"month"} == 9 or $ihr->{"month"} == 11
l!l&&r!l&&!r
0042
$ihr->{"month"} == 4 or $ihr->{"month"} == 6 or $ihr->{"month"} == 9
l!l&&r!l&&!r
0042
$ihr->{"month"} == 4 or $ihr->{"month"} == 6
l!l&&r!l&&!r
0042
MC/DC0%0/5
$ihr->{"day"} > 30 and $ihr->{"month"} == 4 || $ihr->{"month"} == 6 || $ihr->{"month"} == 9 || $ihr->{"month"} == 11
$ihr->{"day"} > 30 $ihr->{"month"} == 4 $ihr->{"month"} == 6 $ihr->{"month"} == 9 $ihr->{"month"} == 11
Truth table33%2/6
A and B or C or D or E
A= $ihr->{"day"} > 30B= $ihr->{"month"} == 4C= $ihr->{"month"} == 6D= $ihr->{"month"} == 9E= $ihr->{"month"} == 11
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
364  
365 return undef if ($ihr->{month} == 2 and
366 ($ihr->{day} > 29 or
367 2196 ▶ ($ihr->{day} > 28 and !_leap($ihr->{year}))));
Branch: 1 branch
BranchTrueFalseTotal
if $ihr->{"month"} == 2 and $ihr->{"day"} > 29 || $ihr->{"day"} > 28 && !_leap($ihr->{"year"}) 0 2196 2196
Condition55%5/9
$ihr->{"month"} == 2 and $ihr->{"day"} > 29 || $ihr->{"day"} > 28 && !_leap($ihr->{"year"})
!ll&&!rl&&r
20251710
$ihr->{"day"} > 29 or $ihr->{"day"} > 28 and not _leap($ihr->{"year"})
l!l&&r!l&&!r
00171
$ihr->{"day"} > 28 and not _leap($ihr->{"year"})
!ll&&!rl&&r
16830
MC/DC0%0/4
$ihr->{"month"} == 2 and $ihr->{"day"} > 29 || $ihr->{"day"} > 28 && !_leap($ihr->{"year"})
$ihr->{"month"} == 2 $ihr->{"day"} > 29 $ihr->{"day"} > 28 not _leap($ihr->{"year"})
Truth table60%3/5
A and B or C and not(D)
A= $ihr->{"month"} == 2B= $ihr->{"day"} > 29C= $ihr->{"day"} > 28D= not _leap($ihr->{"year"})
ABCDresult
0XXX0
100X0
10100
11XX1
10111
368 2196 return 1;
369 }
370  
371  
372 # _normalize_month: Given a month number, 'normalize' it, i.e. replace
373 # it in the 1..12 interval.
374  
375 198872 ▶sub _normalize_month {
Subroutine _normalize_month: called CC=2 SCAR=6.9
376 11 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
377  
378 198872 my ($mons) = @_;
379 198872 my $result = (($_[0] - 1) % 12) + 1;
380  
381 198872 ▶ unless (wantarray()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 196682 2190 198872
382 196682 return $result;
383 }
384  
385 2190 return ($result,$mons/12);
386 }
387  
388 2190 ▶sub _normalize_roman_date {
Subroutine _normalize_roman_date: called CC=27 SCAR=33.4
389 2190 my $rhr = shift;
390  
391 # print "_normalize_roman_date({",
392 # join(",", map {"$_ => $rhr->{$_}"} keys %{$rhr}),
393 # "})\n";
394  
395 2190 my ($mons,$deltay) = _normalize_month($rhr->{mons});
396  
397 2190 $rhr->{mons} = $mons;
398 2190 $rhr->{annus} += $deltay;
399 $rhr->{ad}++ if $rhr->{bis} or (($rhr->{mons} == 3) and
400 ($rhr->{base} == Kalendae) and
401 ($rhr->{ad} > 6) and
402 2190 ▶ (_leap($rhr->{annus},'roman')));
Branch: 1 branch
BranchTrueFalseTotal
if $rhr->{"bis"} or $rhr->{"mons"} == 3 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 6 and _leap($rhr->{"annus"}, "roman") 0 2190 2190
Condition33%4/12
$rhr->{"bis"} or $rhr->{"mons"} == 3 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 6 and _leap($rhr->{"annus"}, "roman")
l!l&&r!l&&!r
002190
$rhr->{"mons"} == 3 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 6 and _leap($rhr->{"annus"}, "roman")
!ll&&!rl&&r
219000
$rhr->{"mons"} == 3 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 6
!ll&&!rl&&r
219000
$rhr->{"mons"} == 3 and $rhr->{"base"} == 0
!ll&&!rl&&r
219000
MC/DC0%0/5
$rhr->{"bis"} or $rhr->{"mons"} == 3 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 6 and _leap($rhr->{"annus"}, "roman")
$rhr->{"bis"} $rhr->{"mons"} == 3 $rhr->{"base"} == 0 $rhr->{"ad"} > 6 _leap($rhr->{"annus"}, "roman")
Truth table16%1/6
A or B and C and D and E
A= $rhr->{"bis"}B= $rhr->{"mons"} == 3C= $rhr->{"base"} == 0D= $rhr->{"ad"} > 6E= _leap($rhr->{"annus"}, "roman")
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
403 2190 $rhr->{bis} = 0;
404  
405 # print "After initialization:\n";
406 # print "{",join(",", map {"$_ => $rhr->{$_}"} keys %{$rhr}),"}\n";
407  
408 2190 ▶ while (($rhr->{ad} > _days_before($rhr->{base},$rhr->{mons}) - 1) or
Branch: 1 branch
BranchTrueFalseTotal
if ($rhr->{"ad"} > _days_before($rhr->{"base"}, $rhr->{"mons"}) - 1 or $rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman") and $rhr->{"ad"} > 17) 58309 2190 60499
Condition83%10/12
$rhr->{"ad"} > _days_before($rhr->{"base"}, $rhr->{"mons"}) - 1 or $rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman") and $rhr->{"ad"} > 17
l!l&&r!l&&!r
5830902190
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman") and $rhr->{"ad"} > 17
!ll&&!rl&&r
2174160
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman")
!ll&&!rl&&r
21423216
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3
!ll&&!rl&&r
457168548
MC/DC20%1/5
$rhr->{"ad"} > _days_before($rhr->{"base"}, $rhr->{"mons"}) - 1 or $rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman") and $rhr->{"ad"} > 17
$rhr->{"ad"} > _days_before($rhr->{"base"}, $rhr->{"mons"}) - 1 $rhr->{"base"} == 0 $rhr->{"mons"} == 3 _leap($rhr->{"annus"}, "roman") $rhr->{"ad"} > 17
Truth table83%5/6
A or B and C and D and E
A= $rhr->{"ad"} > _days_before($rhr->{"base"}, $rhr->{"mons"}) - 1B= $rhr->{"base"} == 0C= $rhr->{"mons"} == 3D= _leap($rhr->{"annus"}, "roman")E= $rhr->{"ad"} > 17
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
409 (($rhr->{base} == Kalendae) and
410 ($rhr->{mons} == 3) and
411 _leap($rhr->{annus},'roman') and
412 ($rhr->{ad} > 17))) {
413 #decrement $rhr->{ad} and set mons and annus accordingly
414 # print "decrementing\n";
415  
416 58309 $rhr->{ad} -= _days_before($rhr->{base},$rhr->{mons});
417 $rhr->{ad}-- if (($rhr->{base} == Kalendae) and
418 ($rhr->{mons} == 3) and
419 58309 ▶ _leap($rhr->{annus},'roman'));
Branch: 1 branch
BranchTrueFalseTotal
if $rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman") 411 57898 58309
Condition100%6/6
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman")
!ll&&!rl&&r
57077821411
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3
!ll&&!rl&&r
38624184531232
MC/DC100%3/3
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman")
$rhr->{"base"} == 0 $rhr->{"mons"} == 3 _leap($rhr->{"annus"}, "roman")
Truth table100%4/4
A and B and C
A= $rhr->{"base"} == 0B= $rhr->{"mons"} == 3C= _leap($rhr->{"annus"}, "roman")
ABCresult
0XX0
10X0
1100
1111
420
421  
422 58309 $rhr->{base} = ($rhr->{base} - 1) % 3;
423 58309 ▶ $rhr->{mons}-- if $rhr->{base} == Idibus;
Branch: 1 branch
BranchTrueFalseTotal
if $rhr->{"base"} == 2 19685 38624 58309
424  
425 58309 ▶ if ($rhr->{mons} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhr->{"mons"} == 0) 2141 56168 58309
426 2141 $rhr->{mons} = 12;
427 2141 $rhr->{annus}--;
428 }
429 }
430  
431 2190 ▶ while ($rhr->{ad} < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhr->{"ad"} < 1) 60277 2190 62467
432 # print "Incrementing\n";
433 #increment $rhr->{ad} and set mons and annus accordingly
434 60277 $rhr->{base} = ($rhr->{base} + 1) % 3;
435  
436 60277 ▶ $rhr->{mons}++ if $rhr->{base} == Kalendae;
Branch: 1 branch
BranchTrueFalseTotal
if $rhr->{"base"} == 0 19845 40432 60277
437  
438 60277 ▶ if ($rhr->{mons} == 13) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhr->{"mons"} == 13) 1153 59124 60277
439 1153 $rhr->{mons} = 1;
440 1153 $rhr->{annus}++;
441 }
442  
443 60277 $rhr->{ad} += _days_before($rhr->{base},$rhr->{mons});
444
445 $rhr->{ad}++ if (($rhr->{base} == Kalendae) and
446 ($rhr->{mons} == 3) and
447 60277 ▶ _leap($rhr->{annus},'roman'));
Branch: 1 branch
BranchTrueFalseTotal
if $rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman") 689 59588 60277
Condition100%6/6
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman")
!ll&&!rl&&r
582131375689
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3
!ll&&!rl&&r
40432177812064
MC/DC100%3/3
$rhr->{"base"} == 0 and $rhr->{"mons"} == 3 and _leap($rhr->{"annus"}, "roman")
$rhr->{"base"} == 0 $rhr->{"mons"} == 3 _leap($rhr->{"annus"}, "roman")
Truth table100%4/4
A and B and C
A= $rhr->{"base"} == 0B= $rhr->{"mons"} == 3C= _leap($rhr->{"annus"}, "roman")
ABCresult
0XX0
10X0
1100
1111
448 }
449  
450 2190 ▶ if (_leap($rhr->{annus},'roman') and
Branch: 1 branch
BranchTrueFalseTotal
if (_leap($rhr->{"annus"}, "roman") and $rhr->{"mons"} == 3 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 6) 22 2168 2190
Condition100%9/9
_leap($rhr->{"annus"}, "roman") and $rhr->{"mons"} == 3 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 6
!ll&&!rl&&r
21561222
_leap($rhr->{"annus"}, "roman") and $rhr->{"mons"} == 3 and $rhr->{"base"} == 0
!ll&&!rl&&r
21282834
_leap($rhr->{"annus"}, "roman") and $rhr->{"mons"} == 3
!ll&&!rl&&r
145867062
MC/DC100%4/4
_leap($rhr->{"annus"}, "roman") and $rhr->{"mons"} == 3 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 6
_leap($rhr->{"annus"}, "roman") $rhr->{"mons"} == 3 $rhr->{"base"} == 0 $rhr->{"ad"} > 6
Truth table100%5/5
A and B and C and D
A= _leap($rhr->{"annus"}, "roman")B= $rhr->{"mons"} == 3C= $rhr->{"base"} == 0D= $rhr->{"ad"} > 6
ABCDresult
0XXX0
10XX0
110X0
11100
11111
451 ($rhr->{mons} == 3) and
452 ($rhr->{base} == Kalendae) and
453 ($rhr->{ad} > 6)) {
454 22 ▶ $rhr->{bis} = 1 if $rhr->{ad} == 7;
Branch: 1 branch
BranchTrueFalseTotal
if $rhr->{"ad"} == 7 2 20 22
455 22 $rhr->{ad}--;
456 }
457  
458 2190 return $rhr;
459  
460 }
461  
462 # _days_before: Given a fixed day and a month returns the number of
463 # days existing in that month before that given fixed day. Reamrks
464 # that this is always the same, unregarding if the year is leap or
465 # not.
466  
467 181284 ▶sub _days_before {
Subroutine _days_before: called CC=3 SCAR=11.0
468 181284 my ($base,$month) = @_;
469 181284 ▶ return 8 if $base == Idibus;
Branch: 1 branch
BranchTrueFalseTotal
if $base == 2 59791 121493 181284
470
471 121493 ▶ return _fixed_day(Nonae,$month) -1 if $base == Nonae;
Branch: 1 branch
BranchTrueFalseTotal
if $base == 1 59260 62233 121493
472  
473 #Kalendas
474 62233 return _monthlength($month - 1) - _fixed_day(Idibus,$month - 1) + 1;
475 }
476  
477 # _fixed_day: Given a fixed day and a month returns the 'position' of
478 # the fixed day in the month. Month is normalized.
479  
480 129644 ▶sub _fixed_day {
Subroutine _fixed_day: called CC=11 SCAR=24.0
481 129644 my ($fd,$mons) = @_;
482  
483 129644 ▶ return 1 if $fd == Kalendae;
Branch: 1 branch
BranchTrueFalseTotal
if $fd == 0 0 129644 129644
484  
485 129644 $mons = _normalize_month($mons);
486  
487 129644 ▶ if ($fd == Idibus) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fd == 2) { } 66361 63283 129644
488 66361 ▶ return 15 if ($mons == 3) or ($mons == 5) or
Branch: 1 branch
BranchTrueFalseTotal
if $mons == 3 or $mons == 5 or $mons == 7 or $mons == 10 21618 44743 66361
Condition100%9/9
$mons == 3 or $mons == 5 or $mons == 7 or $mons == 10
l!l&&r!l&&!r
15873574544743
$mons == 3 or $mons == 5 or $mons == 7
l!l&&r!l&&!r
10400547350488
$mons == 3 or $mons == 5
l!l&&r!l&&!r
5109529155961
MC/DC100%4/4
$mons == 3 or $mons == 5 or $mons == 7 or $mons == 10
$mons == 3 $mons == 5 $mons == 7 $mons == 10
Truth table100%5/5
A or B or C or D
A= $mons == 3B= $mons == 5C= $mons == 7D= $mons == 10
ABCDresult
1XXX1
01XX1
001X1
00011
00000
489 ($mons == 7) or ($mons == 10);
490 44743 return 13;
491 }
492 else {
493 63283 ▶ return 7 if ($mons == 3) or ($mons == 5) or
Branch: 1 branch
BranchTrueFalseTotal
if $mons == 3 or $mons == 5 or $mons == 7 or $mons == 10 21148 42135 63283
Condition100%9/9
$mons == 3 or $mons == 5 or $mons == 7 or $mons == 10
l!l&&r!l&&!r
15517563142135
$mons == 3 or $mons == 5 or $mons == 7
l!l&&r!l&&!r
10161535647766
$mons == 3 or $mons == 5
l!l&&r!l&&!r
4990517153122
MC/DC100%4/4
$mons == 3 or $mons == 5 or $mons == 7 or $mons == 10
$mons == 3 $mons == 5 $mons == 7 $mons == 10
Truth table100%5/5
A or B or C or D
A= $mons == 3B= $mons == 5C= $mons == 7D= $mons == 10
ABCDresult
1XXX1
01XX1
001X1
00011
00000
494 ($mons == 7) or ($mons == 10);
495 42135 return 5;
496 }
497 }
498  
499 # _monthlength: given a month number returns the length of the month.
500 #
501 # Notes:
502 #
503 # 1. for February we always returns 28.
504 #
505 # 2. month is normalized.
506  
507 67038 ▶sub _monthlength {
Subroutine _monthlength: called CC=6 SCAR=17.9
508 67038 my $month = _normalize_month(shift);
509  
510 67038 ▶ return 28 if $month == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $month == 2 5023 62015 67038
511 62015 ▶ return 30 if ($month == 4 or $month == 6 or $month == 9 or $month == 11);
Branch: 1 branch
BranchTrueFalseTotal
if $month == 4 or $month == 6 or $month == 9 or $month == 11 22373 39642 62015
Condition100%9/9
$month == 4 or $month == 6 or $month == 9 or $month == 11
l!l&&r!l&&!r
16458591539642
$month == 4 or $month == 6 or $month == 9
l!l&&r!l&&!r
10726573245557
$month == 4 or $month == 6
l!l&&r!l&&!r
5274545251289
MC/DC100%4/4
$month == 4 or $month == 6 or $month == 9 or $month == 11
$month == 4 $month == 6 $month == 9 $month == 11
Truth table100%5/5
A or B or C or D
A= $month == 4B= $month == 6C= $month == 9D= $month == 11
ABCDresult
1XXX1
01XX1
001X1
00011
00000
512 39642 return 31;
513 }
514  
515 # _leap: is a given year leap?
516 5755 ▶sub _leap {
Subroutine _leap: called CC=7 SCAR=19.5
517 5755 my $year = shift;
518 5755 ▶ my $format = shift || 'christian';
Condition100%2/2
shift() || 'christian'
l!l
5538217
MC/DC100%1/1
shift() || 'christian'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
519  
520 5755 ▶ $year -= 753 if $format eq 'roman';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "roman" 5538 217 5755
521
522 5755 ▶ return 0 if ($year % 4);
Branch: 1 branch
BranchTrueFalseTotal
if $year % 4 3801 1954 5755
523 1954 ▶ return 1 if ($year <= LastJulian) or ($year % 100);
Branch: 1 branch
BranchTrueFalseTotal
if $year <= 1582 or $year % 100 1849 105 1954
Condition100%3/3
$year <= 1582 or $year % 100
l!l&&r!l&&!r
11848105
MC/DC100%2/2
$year <= 1582 or $year % 100
$year <= 1582 $year % 100
Truth table100%3/3
A or B
A= $year <= 1582B= $year % 100
ABresult
1X1
011
000
524 105 ▶ return 0 if ($year % 400);
Branch: 1 branch
BranchTrueFalseTotal
if $year % 400 0 105 105
525 105 return 1;
526 }
527  
528  
529 # _ical_to_roman: Given a reference to an hash representing a date in
530 # the ical format (as returned by the _parse_ical sub) it returns a
531 # reference to an hash containing the corresponding Roman date, as
532 # returned by the _parse_roman sub.
533  
534 3292 ▶sub _ical_to_roman {
Subroutine _ical_to_roman: called CC=10 SCAR=23.0
535 3292 my $ihr = shift; #ical hash ref
536 3292 my %result = (bis => 0);
537 3292 my $fd;
538  
539 3292 ▶ if ($ihr->{day} == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ihr->{'day'} == 1) { } 108 3184 3292
elsif ($ihr->{'day'} <= ($fd = _fixed_day(1, $ihr->{'month'}))) { } 503 2681 3184
elsif ($ihr->{'day'} <= ($fd = _fixed_day(2, $ihr->{'month'}))) { } 870 1811 2681
540 108 $result{ad} = 1;
541 108 $result{base} = Kalendae;
542 108 $result{mons} = $ihr->{month};
543 108 $result{annus} = $ihr->{year};
544 }
545 elsif ($ihr->{day} <= ($fd = _fixed_day(Nonae,$ihr->{month}))) {
546 503 $result{ad} = $fd - $ihr->{day} + 1;
547 503 $result{base} = Nonae;
548 503 $result{mons} = $ihr->{month};
549 503 $result{annus} = $ihr->{year};
550 }
551 elsif ($ihr->{day} <= ($fd = _fixed_day(Idibus,$ihr->{month}))) {
552 870 $result{ad} = $fd - $ihr->{day} + 1;
553 870 $result{base} = Idibus;
554 870 $result{mons} = $ihr->{month};
555 870 $result{annus} = $ihr->{year};
556 }
557 else {
558 1811 $result{base} = Kalendae;
559 1811 ▶ $result{mons} = ($ihr->{month} < 12) ? $ihr->{month} + 1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$ihr->{'month'} < 12 ? : 1649 162 1811
560 1811 ▶ $result{annus} = ($result{mons} == 1) ? $ihr->{year} + 1 : $ihr->{year};
Branch: 1 branch
BranchTrueFalseTotal
$result{'mons'} == 1 ? : 162 1649 1811
561  
562 1811 ▶ if ($result{mons} != 3 or !_leap($ihr->{year}) or ($ihr->{day} < 24)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result{'mons'} != 3 or not _leap($ihr->{'year'}) or $ihr->{'day'} < 24) { } 1787 24 1811
elsif ($ihr->{'day'} == 24) { } 4 20 24
Condition100%6/6
$result{"mons"} != 3 or not _leap($ihr->{"year"}) or $ihr->{"day"} < 24
l!l&&r!l&&!r
17474024
$result{"mons"} != 3 or not _leap($ihr->{"year"})
l!l&&r!l&&!r
16727564
MC/DC100%3/3
$result{"mons"} != 3 or not _leap($ihr->{"year"}) or $ihr->{"day"} < 24
$result{"mons"} != 3 not _leap($ihr->{"year"}) $ihr->{"day"} < 24
Truth table100%4/4
A or not(B) or C
A= $result{"mons"} != 3B= not _leap($ihr->{"year"})C= $ihr->{"day"} < 24
ABCresult
1XX1
01X1
0011
0000
563 1787 $result{ad} = _monthlength($ihr->{month}) - $ihr->{day} + 2;
564 }
565 elsif ($ihr->{day} == 24) {
566 4 $result{bis} = 1;
567 4 $result{ad} = 6;
568 }
569 else {
570 20 $result{ad} = 31 - $ihr->{day};
571 }
572 }
573  
574 3292 $result{annus} += 753;
575  
576 3292 return \%result;
577 }
578  
579 # _roman_to_ical:
580 5484 ▶sub _roman_to_ical {
Subroutine _roman_to_ical: called CC=14 SCAR=26.4
581 5484 my $rhr = shift; # roman hash ref
582 5484 my %result = ();
583  
584  
585 $result{year} = (($rhr->{mons} == 1) and
586 ($rhr->{base} == Kalendae) and
587 5484 ▶ ($rhr->{ad} > 1)) ? $rhr->{annus} - 1 : $rhr->{annus};
Branch: 1 branch
BranchTrueFalseTotal
$rhr->{'mons'} == 1 && $rhr->{'base'} == 0 && $rhr->{'ad'} > 1 ? : 270 5214 5484
Condition100%6/6
$rhr->{"mons"} == 1 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 1
!ll&&!rl&&r
519915270
$rhr->{"mons"} == 1 and $rhr->{"base"} == 0
!ll&&!rl&&r
5019180285
MC/DC100%3/3
$rhr->{"mons"} == 1 and $rhr->{"base"} == 0 and $rhr->{"ad"} > 1
$rhr->{"mons"} == 1 $rhr->{"base"} == 0 $rhr->{"ad"} > 1
Truth table100%4/4
A and B and C
A= $rhr->{"mons"} == 1B= $rhr->{"base"} == 0C= $rhr->{"ad"} > 1
ABCresult
0XX0
10X0
1100
1111
588
589 5484 $result{year} -= 753;
590  
591 $result{month} = (($rhr->{base} != Kalendae) or ($rhr->{ad} == 1)) ?
592 $rhr->{mons} :
593 5484 ▶ (($rhr->{mons} > 1) ? $rhr->{mons} - 1 : 12);
Branch: 2 branches
BranchTrueFalseTotal
$rhr->{'base'} != 0 || $rhr->{'ad'} == 1 ? : 2466 3018 5484
$rhr->{'mons'} > 1 ? : 2748 270 3018
Condition100%3/3
$rhr->{"base"} != 0 or $rhr->{"ad"} == 1
l!l&&r!l&&!r
22861803018
MC/DC100%2/2
$rhr->{"base"} != 0 or $rhr->{"ad"} == 1
$rhr->{"base"} != 0 $rhr->{"ad"} == 1
Truth table100%3/3
A or B
A= $rhr->{"base"} != 0B= $rhr->{"ad"} == 1
ABresult
1X1
011
000
594  
595 5484 ▶ if ($rhr->{base} == Kalendae) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhr->{'base'} == 0) { } 3198 2286 5484
596 3198 ▶ if ($rhr->{ad} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhr->{'ad'} == 1) { } 180 3018 3198
597 180 $result{day} = 1;
598 }
599 else {
600 3018 $result{day} = _monthlength($result{month}) - $rhr->{ad} + 2;
601 3018 ▶ if ($result{month} == 2 and
Branch: 1 branch
BranchTrueFalseTotal
if ($result{"month"} == 2 and $rhr->{"ad"} < 6 || $rhr->{"ad"} == 6 && !$rhr->{"bis"} and _leap($result{"year"})) 35 2983 3018
Condition100%12/12
$result{"month"} == 2 and $rhr->{"ad"} < 6 || $rhr->{"ad"} == 6 && !$rhr->{"bis"} and _leap($result{"year"})
!ll&&!rl&&r
29434035
$result{"month"} == 2 and $rhr->{"ad"} < 6 || $rhr->{"ad"} == 6 && !$rhr->{"bis"}
!ll&&!rl&&r
278615775
$rhr->{"ad"} < 6 or $rhr->{"ad"} == 6 and not $rhr->{"bis"}
l!l&&r!l&&!r
6015157
$rhr->{"ad"} == 6 and not $rhr->{"bis"}
!ll&&!rl&&r
150715
MC/DC100%5/5
$result{"month"} == 2 and $rhr->{"ad"} < 6 || $rhr->{"ad"} == 6 && !$rhr->{"bis"} and _leap($result{"year"})
$result{"month"} == 2 $rhr->{"ad"} < 6 $rhr->{"ad"} == 6 not $rhr->{"bis"} _leap($result{"year"})
Truth table100%7/7
A and B or C and not(D) and E
A= $result{"month"} == 2B= $rhr->{"ad"} < 6C= $rhr->{"ad"} == 6D= not $rhr->{"bis"}E= _leap($result{"year"})
ABCDEresult
0XXXX0
100XX0
1010X0
11XX00
101100
11XX11
101111
602 ($rhr->{ad} < 6 or ($rhr->{ad} == 6 and !$rhr->{bis})) and
603 (_leap($result{year}))) {
604 35 $result{day}++;
605 }
606 }
607 }
608 else {
609 2286 $result{day} = _fixed_day($rhr->{base},$rhr->{mons}) - $rhr->{ad} + 1;
610 }
611  
612 5484 return \%result;
613 }
614 11 1;
615 __END__
↑ Summary script/RomanDate »