blib/lib/Lingua/DEU/Num2Word.pm

filter: Statementstmt 89.2% 50 / 56 Branchbran 50.0% 15 / 30 Conditioncond 55.5% 15 / 27 MC/DCmcdc 31.2% 5 / 16 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 68.3% 95 / 139 SCAR 37.0
CC
25
Cov
71%
num2deu_cardinal
59.1
BEGIN
1.0
BEGIN
1.0
CRAP 40.6
↑ Summary
1 # For Emacs: -*- mode:cperl; mode:folding; coding:utf-8 -*-
2  
3 package Lingua::DEU::Num2Word;
4 # ABSTRACT: Number 2 word conversion in DEU.
5  
6 # {{{ use block
7  
8 1 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Perl6::Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # }}}
19 # {{{ variable declarations
20  
21 1 my Readonly::Scalar $COPY = 'Copyright (C) PetaMem, s.r.o. 2002-present';
22  
23 1 our $VERSION = 0.1106;
24  
25 # }}}
26  
27 # {{{ num2deu_cardinal convert number to text
28  
29 sub num2deu_cardinal :Export {
30 7 ▶ my $positive = shift;
Subroutine num2deu_cardinal: called CC=25 SCAR=40.8
Pod documented
31  
32 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/msx or $positive < 0 or $positive > 999999999 1 5 6
Condition77%7/9
not defined $positive && $positive =~ /\A\d+\z/msx or $positive < 0 or $positive > 999999999
l!l&&r!l&&!r
115
not defined $positive && $positive =~ /\A\d+\z/msx or $positive < 0
l!l&&r!l&&!r
106
defined $positive && $positive =~ /\A\d+\z/msx
!ll&&!rl&&r
106
MC/DC50%2/4
not defined $positive && $positive =~ /\A\d+\z/msx or $positive < 0 or $positive > 999999999
defined $positive $positive =~ /\A\d+\z/msx $positive < 0 $positive > 999999999
Truth table60%3/5
not(A && B) or C or D
A= defined $positiveB= $positive =~ /\A\d+\z/msxC= $positive < 0D= $positive > 999999999
ABCDresult
0XXX1
10XX1
111X1
11011
11000
33 if !defined $positive
34 || $positive !~ m{\A\d+\z}xms
35 || $positive < 0
36 || $positive > 999_999_999;
37  
38 5 my @tokens1 = qw(null ein zwei drei vier fünf sechs sieben acht neun zehn elf zwölf);
39 5 my @tokens2 = qw(zwanzig dreissig vierzig fünfzig sechzig siebzig achtzig neunzig hundert);
40  
41 5 ▶ return $tokens1[$positive] if ($positive >= 0 && $positive < 13); # 0 .. 12
Branch: 1 branch
BranchTrueFalseTotal
if $positive >= 0 and $positive < 13 2 3 5
Condition66%2/3
$positive >= 0 and $positive < 13
!ll&&!rl&&r
032
MC/DC50%1/2
$positive >= 0 and $positive < 13
$positive >= 0 $positive < 13
Truth table66%2/3
A and B
A= $positive >= 0B= $positive < 13
ABresult
0X0
100
111
42 3 ▶ return 'sechzehn' if ($positive == 16); # 16 exception
Branch: 1 branch
BranchTrueFalseTotal
if $positive == 16 0 3 3
43 3 ▶ return 'siebzehn' if ($positive == 17); # 17 exception
Branch: 1 branch
BranchTrueFalseTotal
if $positive == 17 0 3 3
44 3 ▶ return $tokens1[$positive-10] . 'zehn' if ($positive > 12 && $positive < 20); # 13 .. 19
Branch: 1 branch
BranchTrueFalseTotal
if $positive > 12 and $positive < 20 0 3 3
Condition33%1/3
$positive > 12 and $positive < 20
!ll&&!rl&&r
030
MC/DC0%0/2
$positive > 12 and $positive < 20
$positive > 12 $positive < 20
Truth table33%1/3
A and B
A= $positive > 12B= $positive < 20
ABresult
0X0
100
111
45  
46 3 my $out; # string for return value construction
47 my $one_idx; # index for tokens1 array
48 3 my $remain; # remainder
49  
50 3 ▶ if ($positive > 19 && $positive < 101) { # 20 .. 100
Branch: 4 branches
BranchTrueFalseTotal
if ($positive > 19 and $positive < 101) { } 1 2 3
elsif ($positive > 100 and $positive < 1000) { } 1 1 2
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
021
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
51 1 $one_idx = int ($positive / 10);
52 1 $remain = $positive % 10;
53  
54 1 ▶ $out = "$tokens1[$remain]und" if ($remain);
Branch: 1 branch
BranchTrueFalseTotal
if $remain 1 0 1
55 1 $out .= $tokens2[$one_idx - 2];
56 }
57 ▶ elsif ($positive > 100 && $positive < 1000) { # 101 .. 999
Condition66%2/3
$positive > 100 and $positive < 1000
!ll&&!rl&&r
011
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
58 1 $one_idx = int ($positive / 100);
59 1 $remain = $positive % 100;
60  
61 1 $out = "$tokens1[$one_idx]hundert";
62 1 ▶ $out .= $remain ? num2deu_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 1 0 1
63 }
64 ▶ 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
65 1 $one_idx = int ($positive / 1000);
66 1 $remain = $positive % 1000;
67  
68 1 $out = num2deu_cardinal($one_idx).'tausend';
69 1 ▶ $out .= $remain ? num2deu_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 1 1
70 }
71 ▶ 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
72 && $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999
73 0 $one_idx = int ($positive / 1000000);
74 0 $remain = $positive % 1000000;
75 0 ▶ my $one = $one_idx == 1 ? 'e' : '';
Branch: 1 branch
BranchTrueFalseTotal
$one_idx == 1 ? : 0 0 0
76  
77 0 $out = num2deu_cardinal($one_idx) . "$one million";
78 0 ▶ $out .= 'en' if ($one_idx > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $one_idx > 1 0 0 0
79 0 ▶ $out .= $remain ? ' ' . num2deu_cardinal($remain) : '';
Branch: 1 branch
BranchTrueFalseTotal
$remain ? : 0 0 0
80 }
81  
82 3 return $out;
83 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 # }}}
86  
87 1 1;
88  
89 __END__
↑ Summary