blib/lib/Math/BigInt/Named/Norwegian.pm

filter: Statementstmt 100% 83 / 83 Branchbran 94.7% 36 / 38 Conditioncond 86.6% 13 / 15 MC/DCmcdc 77.7% 7 / 9 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 96.0% 146 / 152 CC 26 SCAR 22.3
CC
26
Cov
97%
name
13.0
_triple
9.0
_triple_name
6.0
CRAP 9.3
« lib/Math/BigInt/Named.pm ↑ Summary lib/Math/BigInt/Named/German.pm »
1 # -*- mode: perl; -*-
2  
3 package Math::BigInt::Named::Norwegian;
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Math::BigInt::Named;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 our @ISA = qw< Math::BigInt::Named >;
10  
11 2 our $VERSION = '0.08';
12  
13 2 my $SMALL = [ qw/
14 null
15 en
16 to
17 tre
18 fire
19 fem
20 seks
21 syv
22 åtte
23 ni
24 ti
25 elleve
26 tolv
27 tretten
28 fjorten
29 femten
30 seksten
31 sytten
32 atten
33 nitten
34 / ];
35  
36 2 my $TENS = [ qw /
37 ti
38 tjue
39 tretti
40 førti
41 femti
42 seksti
43 sytti
44 åtti
45 nitti
46 / ];
47  
48 2 my $HUNDREDS = [ qw /
49 en
50 to
51 tre
52 fire
53 fem
54 seks
55 sju
56 åtte
57 ni
58 / ];
59  
60 2 my $TRIPLE = [ qw /
61 mi
62 bi
63 tri
64 kvadri
65 kvinti
66 seksti
67 septi
68 okti
69 noni
70 desi
71 undesi
72 duodesi
73 tredesi
74 kvattordesi
75 kvindesi
76 seksdesi
77 septendesi
78 oktodesi
79 novemdesi
80 viginti
81 / ];
82  
83 55 ▶sub name {
Subroutine name: called CC=13 SCAR=25.7
Pod documented
84 55 my $x = shift;
85 55 ▶ $x = Math::BigInt -> new($x) unless ref($x);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 0 55 55
86  
87 55 my $class = ref($x);
88  
89 55 ▶ return '' if $x -> is_nan();
Branch: 1 branch
BranchTrueFalseTotal
if $x->is_nan 0 55 55
90  
91 55 my $ret = '';
92 55 my $y = $x -> copy();
93 55 my $rem;
94  
95 55 ▶ if ($y -> sign() eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($y->sign eq "-") 1 54 55
96 1 $ret = 'minus ';
97 1 $y -> babs();
98 }
99  
100 55 ▶ if ($y < 1000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < 1000) 42 13 55
101 42 return $ret . $class -> _triple($y, 1, 0);
102 }
103  
104 # Split the number into numerical triplets.
105  
106 13 my @num = ();
107 13 ▶ while (!$y -> is_zero()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($y->is_zero) 32 13 45
108 32 ($y, $rem) = $y -> bdiv(1000);
109 32 unshift @num, $rem;
110 }
111  
112 # Convert each numerical triplet into a string.
113  
114 13 my @str = ();
115 13 for my $i (0 .. $#num) {
116 32 my $num = $num[$i];
117 32 my $str;
118 32 my $index = $#num - $i;
119  
120 32 my $count;
121 32 ▶ if ($num == 1 && $index == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num == 1 and $index == 1) { } 8 24 32
Condition100%3/3
$num == 1 and $index == 1
!ll&&!rl&&r
1958
MC/DC100%2/2
$num == 1 and $index == 1
$num == 1 $index == 1
Truth table100%3/3
A and B
A= $num == 1B= $index == 1
ABresult
0X0
100
111
122 8 $count = "ett"; # "ett tusen", not "en tusen"
123 } else {
124 24 $count = $class -> _triple($num, 0, $i);
125 }
126 32 $str .= $count;
127  
128 # "tusen", "million"/"millioner", "milliard/milliarder", ...
129  
130 32 ▶ if ($index > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index > 0) 19 13 32
131 19 my $triple_name = $class -> _triple_name($#num - $i, $num);
132 19 $str .= ' ' . $triple_name;
133 }
134  
135 32 $str[$i] = $str;
136 }
137  
138 # 1100 -> "ett tusen ett hundre" (not "ett tusen og ett hundre")
139 # 1099 -> "ett tusen og nittini" (not "ett tusen nittini")
140 # 1098 -> "ett tusen og nittiåtte" (not "ett tusen nittiåtte")
141 # ...
142 # 1001 -> "ett tusen og en" (not "ett tusen en")
143 # 1000 -> "ett tusen" (not "ett tusen og null"
144  
145 13 ▶ if (@num > 1 && 0 < $num[-1] && $num[-1] < 100) {
Branch: 1 branch
BranchTrueFalseTotal
if (@num > 1 and 0 < $num[-1] and $num[-1] < 100) 5 8 13
Condition83%5/6
@num > 1 and 0 < $num[-1] and $num[-1] < 100
!ll&&!rl&&r
355
@num > 1 and 0 < $num[-1]
!ll&&!rl&&r
0310
MC/DC66%2/3
@num > 1 and 0 < $num[-1] and $num[-1] < 100
@num > 1 0 < $num[-1] $num[-1] < 100
Truth table75%3/4
A and B and C
A= @num > 1B= 0 < $num[-1]C= $num[-1] < 100
ABCresult
0XX0
10X0
1100
1111
146 5 splice @str, -1, 0, "og";
147 }
148  
149 13 $ret . join(" ", grep /\S/, @str);
150 }
151  
152 19 ▶sub _triple_name {
Subroutine _triple_name: called CC=6 SCAR=17.9
153 19 my ($self, $index, $number) = @_;
154 # index => 0 hundreds, tens and ones
155 # index => 1 thousands
156 # index => 2 millions
157  
158 19 ▶ return '' if $index == 0 || $number -> is_zero();
Branch: 1 branch
BranchTrueFalseTotal
if $index == 0 or $number->is_zero 5 14 19
Condition66%2/3
$index == 0 or $number->is_zero
l!l&&r!l&&!r
0514
MC/DC50%1/2
$index == 0 or $number->is_zero
$index == 0 $number->is_zero
Truth table66%2/3
A or B
A= $index == 0B= $number->is_zero
ABresult
1X1
011
000
159 14 ▶ return 'tusen' if $index == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $index == 1 8 6 14
160  
161 6 my $postfix = 'llion';
162 6 my $plural = 'er';
163 6 ▶ if (($index & 1) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (($index & 1) == 1) 1 5 6
164 1 $postfix = 'lliard';
165 }
166 6 ▶ $postfix .= $plural unless $number -> is_one();
Branch: 1 branch
BranchTrueFalseTotal
unless $number->is_one 3 3 6
167 6 $index -= 2;
168 6 $TRIPLE -> [$index >> 1] . $postfix;
169 }
170  
171 66 ▶sub _triple {
Subroutine _triple: called CC=9 SCAR=22.0
172 # return name of a triple
173 # input: number >= 0, < 1000
174 # only true if triple is the only triple
175 66 my ($self, $number, $only) = @_;
176  
177 # 0 => null, but only if there is just one triple
178 66 ▶ return '' if $number -> is_zero() && !$only;
Branch: 1 branch
BranchTrueFalseTotal
if $number->is_zero and not $only 8 58 66
Condition100%3/3
$number->is_zero and not $only
!ll&&!rl&&r
5718
MC/DC100%2/2
$number->is_zero and not $only
$number->is_zero not $only
Truth table100%3/3
A and not(B)
A= $number->is_zeroB= not $only
ABresult
0X0
100
111
179  
180 # we have the full name for these
181 58 ▶ return $SMALL -> [$number] if $number <= $#$SMALL;
Branch: 1 branch
BranchTrueFalseTotal
if $number <= $SMALL->$#* 29 29 58
182  
183 # New code:
184  
185 29 my @num = ();
186 29 $num[1] = $number % 100; # tens and ones
187 29 $num[0] = ($number - $num[1]) / 100; # hundreds
188  
189 29 my @str = ();
190  
191 # Do the hundreds, if any.
192  
193 29 ▶ if ($num[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num[0]) 17 12 29
194 17 my $str;
195 17 ▶ $str = $num[0] == 1 ? "ett" # "ett hundre", not "en hundre"
Branch: 1 branch
BranchTrueFalseTotal
$num[0] == 1 ? : 8 9 17
196 : $HUNDREDS -> [$num[0] - 1];
197 17 $str .= " hundre";
198 17 push @str, $str;
199 }
200  
201 # Do the tens and ones, if any.
202  
203 29 ▶ if ($num[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num[1]) 18 11 29
204 18 my $str;
205 18 my $ones = $num[1] % 10;
206 18 my $tens = ($num[1] - $ones) / 10;
207 18 ▶ if ($num[1] <= $#$SMALL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num[1] <= $SMALL->$#*) { } 4 14 18
208 4 $str = $SMALL -> [ $num[1] ];
209 } else {
210 14 $str = $TENS -> [ $tens - 1];
211 14 ▶ if ($ones > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ones > 0) 13 1 14
212 13 $str .= "";
213 13 $str .= $SMALL -> [ $ones ];
214 }
215 }
216 18 push @str, $str;
217 }
218  
219 29 return join " og ", @str;
220 }
221  
222 2 1;
223  
224 __END__
« lib/Math/BigInt/Named.pm ↑ Summary lib/Math/BigInt/Named/German.pm »