blib/lib/Lingua/NLD/Num2Word.pm

filter: Statementstmt 91.6% 44 / 48 Branchbran 50.0% 10 / 20 Conditioncond 37.5% 9 / 24 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 64.3% 74 / 115 CC 19 SCAR 35.2
CC
19
Cov
68%
num2nld_cardinal
45.8
BEGIN
1.0
BEGIN
1.0
CRAP 33.7
↑ Summary
1 # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*-
2  
3 package Lingua::NLD::Num2Word;
4 # ABSTRACT: Number to word conversion in Dutch
5  
6 1 ▶use 5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # {{{ use block
11  
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # }}}
17 # {{{ var block
18  
19 1 my Readonly::Scalar $COPY = 'Copyright (c) PetaMem, s.r.o. 2015-present';
20 1 our $VERSION = '0.2603260';
21  
22 # }}}
23  
24 # {{{ num2nld_cardinal convert number to text
25  
26 sub num2nld_cardinal :Export {
27 7 ▶ my $positive = shift;
Subroutine num2nld_cardinal: called CC=19 SCAR=38.2
Pod documented
28  
29 7 ▶ croak 'You should specify a number from interval [0, 999_999_999]'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999 0 7 7
Condition33%3/9
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
l!l&&r!l&&!r
007
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0
l!l&&r!l&&!r
007
defined $positive && $positive =~ /\A\d+\z/msux
!ll&&!rl&&r
007
MC/DC0%0/4
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
defined $positive $positive =~ /\A\d+\z/msux $positive < 0 $positive > 999999999
Truth table20%1/5
not(A && B) or C or D
A= defined $positiveB= $positive =~ /\A\d+\z/msuxC= $positive < 0D= $positive > 999999999
ABCDresult
0XXX1
10XX1
111X1
11011
11000
30 if !defined $positive
31 || $positive !~ m{\A\d+\z}xms
32 || $positive < 0
33 || $positive > 999_999_999;
34  
35 7 my @tokens1 = qw(nul een twee drie vier vijf zes zeven acht negen tien
36 elf twaalf dertien veertien vijftien zestien zeventien achtien negentien);
37 7 my @tokens2 = qw(twintig dertig veertig vijftig zestig zeventig tachtig negentig honderd);
38  
39 7 ▶ return $tokens1[$positive] if ($positive >= 0 && $positive < 20); # 0 .. 19
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 0 and $positive < 20 0 7 7
Condition33%1/3
$positive >= 0 and $positive < 20
!ll&&!rl&&r
070
MC/DC0%0/2
$positive >= 0 and $positive < 20
$positive >= 0 $positive < 20
Truth table33%1/3
A and B
A= $positive >= 0B= $positive < 20
ABresult
0X0
100
111
40  
41 7 my $out; # string for return value construction
42 my $one_idx; # index for tokens1 array
43 7 my $remain; # remainder
44  
45 7 ▶ if ($positive > 19 && $positive < 101) { # 20 .. 100
Branch: 4 branches
BranchTrueFalseTotal
if ($positive > 19 and $positive < 101) { } 3 4 7
elsif ($positive > 100 and $positive < 1000) { } 3 1 4
elsif ($positive > 999 and $positive < 1000000) { } 1 0 1
elsif ($positive > 999999 and $positive < 1000000000) { } 0 0 0
Condition66%2/3
$positive > 19 and $positive < 101
!ll&&!rl&&r
043
MC/DC50%1/2
$positive > 19 and $positive < 101
$positive > 19 $positive < 101
Truth table66%2/3
A and B
A= $positive > 19B= $positive < 101
ABresult
0X0
100
111
46 3 $one_idx = int ($positive / 10);
47 3 $remain = $positive % 10;
48  
49 3 ▶ $out = "$tokens1[$remain]en" if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 3 0 3
50 3 $out .= $tokens2[$one_idx - 2];
51 }
52 ▶ elsif ($positive > 100 && $positive < 1000) { # 101 .. 999
Condition66%2/3
$positive > 100 and $positive < 1000
!ll&&!rl&&r
013
MC/DC50%1/2
$positive > 100 and $positive < 1000
$positive > 100 $positive < 1000
Truth table66%2/3
A and B
A= $positive > 100B= $positive < 1000
ABresult
0X0
100
111
53 3 $one_idx = int ($positive / 100);
54 3 $remain = $positive % 100;
55  
56 3 $out = "$tokens1[$one_idx]honderd";
57 3 ▶ $out .= $remain ? num2nld_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 3 0 3
58 }
59 ▶ elsif ($positive > 999 && $positive < 1_000_000) { # 1000 .. 999_999
Condition33%1/3
$positive > 999 and $positive < 1000000
!ll&&!rl&&r
001
MC/DC0%0/2
$positive > 999 and $positive < 1000000
$positive > 999 $positive < 1000000
Truth table33%1/3
A and B
A= $positive > 999B= $positive < 1000000
ABresult
0X0
100
111
60 1 $one_idx = int ($positive / 1000);
61 1 $remain = $positive % 1000;
62  
63 1 $out = num2nld_cardinal($one_idx) . 'duizend ';
64 1 ▶ $out .= $remain ? num2nld_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 1 0 1
65 }
66 ▶ elsif ( $positive > 999_999
Condition0%0/3
$positive > 999999 and $positive < 1000000000
!ll&&!rl&&r
000
MC/DC0%0/2
$positive > 999999 and $positive < 1000000000
$positive > 999999 $positive < 1000000000
Truth table0%0/3
A and B
A= $positive > 999999B= $positive < 1000000000
ABresult
0X0
100
111
67 && $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999
68 0 $one_idx = int ($positive / 1000000);
69 0 $remain = $positive % 1000000;
70  
71 0 $out = num2nld_cardinal($one_idx) . " miljoen";
72 0 ▶ $out .= $remain ? ' ' . num2nld_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
73 }
74  
75 7 return $out;
76 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 # }}}
79  
80 1 1;
81  
82 __END__
↑ Summary