Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 autoindent: */
3
/**
4
 * Numbers_Words class extension to spell numbers in Portuguese Brazilian.
5
 *
6
 * PHP versions 4 and 5
7
 *
8
 * LICENSE: This source file is subject to version 3.01 of the PHP license
9
 * that is available through the world-wide-web at the following URI:
10
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
11
 * the PHP License and are unable to obtain it through the web, please
12
 * send a note to license@php.net so we can mail you a copy immediately.
13
 *
14
 * @category   Numbers
15
 * @package    Numbers_Words
16
 * @author     Igor Feghali <ifeghali@php.net>
17
 * @copyright  1997-2008 The PHP Group
18
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
19
 * @version    CVS: $Id: PortugueseBrazilianTest.php 271693 2008-12-20 22:15:12Z ifeghali $
20
 * @link       http://pear.php.net/package/Numbers_Words
21
 * @since      File available only in CVS
22
 */
23
 
24
require_once 'Numbers/Words.php';
25
require_once 'PHPUnit/Framework/TestCase.php';
26
 
27
class Numbers_Words_PortugueseBrazilianTest extends PHPUnit_Framework_TestCase
28
{
29
 
30
    /**
31
     * Testing numbers between 0 and 9
32
     */
33
    function testDigits()
34
    {
35
        $digits = array('zero',
36
                        'um',
37
                        'dois',
38
                        'três',
39
                        'quatro',
40
                        'cinco',
41
                        'seis',
42
                        'sete',
43
                        'oito',
44
                        'nove'
45
                       );
46
        for ($i = 0; $i < 10; $i++)
47
        {
48
            $number = Numbers_Words::toWords($i, 'pt_BR');
49
            $this->assertEquals($digits[$i], $number);
50
 
51
            if ($i > 0) {
52
                $number = Numbers_Words::toWords(-$i, 'pt_BR');
53
                $this->assertEquals($digits[$i].' negativo', $number);
54
            }
55
        }
56
    }
57
 
58
    /**
59
     * Testing numbers between 10 and 99
60
     */
61
    function testTens()
62
    {
63
        $tens = array(11 => 'onze',
64
                      12 => 'doze',
65
                      16 => 'dezesseis',
66
                      19 => 'dezenove',
67
                      20 => 'vinte',
68
                      21 => 'vinte e um',
69
                      26 => 'vinte e seis',
70
                      30 => 'trinta',
71
                      31 => 'trinta e um',
72
                      40 => 'quarenta',
73
                      43 => 'quarenta e três',
74
                      50 => 'cinqüenta',
75
                      55 => 'cinqüenta e cinco',
76
                      60 => 'sessenta',
77
                      67 => 'sessenta e sete',
78
                      70 => 'setenta',
79
                      79 => 'setenta e nove'
80
                     );
81
        foreach ($tens as $number => $word) {
82
            $this->assertEquals($word, Numbers_Words::toWords($number, 'pt_BR'));
83
            $this->assertEquals("$word negativo", Numbers_Words::toWords(-$number, 'pt_BR'));
84
        }
85
    }
86
 
87
    /**
88
     * Testing numbers between 100 and 999
89
     */
90
    function testHundreds()
91
    {
92
        $hundreds = array(100 => 'cem',
93
                          101 => 'cento e um',
94
                          199 => 'cento e noventa e nove',
95
                          203 => 'duzentos e três',
96
                          287 => 'duzentos e oitenta e sete',
97
                          300 => 'trezentos',
98
                          356 => 'trezentos e cinqüenta e seis',
99
                          410 => 'quatrocentos e dez',
100
                          434 => 'quatrocentos e trinta e quatro',
101
                          578 => 'quinhentos e setenta e oito',
102
                          689 => 'seiscentos e oitenta e nove',
103
                          729 => 'setecentos e vinte e nove',
104
                          717 => 'setecentos e dezessete',
105
                          894 => 'oitocentos e noventa e quatro',
106
                          999 => 'novecentos e noventa e nove'
107
                         );
108
        foreach ($hundreds as $number => $word) {
109
            $this->assertEquals($word, Numbers_Words::toWords($number, 'pt_BR'));
110
            $this->assertEquals("$word negativo", Numbers_Words::toWords(-$number, 'pt_BR'));
111
        }
112
    }
113
 
114
    /**
115
     * Testing numbers between 1000 and 9999
116
     */
117
    function testThousands()
118
    {
119
        $thousands = array(1000 => 'um mil',
120
                           1001 => 'um mil e um',
121
                           1097 => 'um mil e noventa e sete',
122
                           1104 => 'um mil cento e quatro',
123
                           1243 => 'um mil duzentos e quarenta e três',
124
                           2200 => 'dois mil e duzentos',
125
                           2385 => 'dois mil trezentos e oitenta e cinco',
126
                           3766 => 'três mil setecentos e sessenta e seis',
127
                           4196 => 'quatro mil cento e noventa e seis',
128
                           5846 => 'cinco mil oitocentos e quarenta e seis',
129
                           6459 => 'seis mil quatrocentos e cinqüenta e nove',
130
                           7232 => 'sete mil duzentos e trinta e dois',
131
                           8569 => 'oito mil quinhentos e sessenta e nove',
132
                           9539 => 'nove mil quinhentos e trinta e nove'
133
                          );
134
        foreach ($thousands as $number => $word) {
135
            $this->assertEquals($word, Numbers_Words::toWords($number, 'pt_BR'));
136
            $this->assertEquals("$word negativo", Numbers_Words::toWords(-$number, 'pt_BR'));
137
        }
138
    }
139
 
140
    /**
141
     * Testing numbers greater than 9999
142
     */
143
    function testMillions()
144
    {
145
        $millions = array(1000001   => 'um milhão e um',
146
                          2000025   => 'dois milhões e vinte e cinco',
147
                          5100000   => 'cinco milhões e cem mil',
148
                          5015004   => 'cinco milhões quinze mil e quatro',
149
                          5123000   => 'cinco milhões cento e vinte e três mil',
150
                          7100100   => 'sete milhões cem mil e cem',
151
                          8100345   => 'oito milhões cem mil trezentos e quarenta e cinco',
152
                          8000016   => 'oito milhões e dezesseis',
153
                          100000001 => 'cem milhões e um',
154
                          345199054 => 'trezentos e quarenta e cinco milhões cento e noventa e nove mil e cinqüenta e quatro',
155
                         1000077000 => 'um bilhão e setenta e sete mil',
156
                         1000777000 => 'um bilhão setecentos e setenta e sete mil',
157
                          );
158
        foreach ($millions as $number => $word) {
159
            $this->assertEquals($word, Numbers_Words::toWords($number, 'pt_BR'));
160
            $this->assertEquals("$word negativo", Numbers_Words::toWords(-$number, 'pt_BR'));
161
        }
162
    }
163
 
164
    /**
165
     * Testing Currency
166
     */
167
    function testCurrency()
168
    {
169
        $money = array('1.00' => 'um real',
170
                       '1.01' => 'um real e um centavo',
171
                       '1.10' => 'um real e dez centavos',
172
                       '1.11' => 'um real e onze centavos',
173
                       '1.21' => 'um real e vinte e um centavos',
174
                       '2.00' => 'dois reais',
175
                       '2.01' => 'dois reais e um centavo',
176
                       '2.10' => 'dois reais e dez centavos',
177
                       '2.11' => 'dois reais e onze centavos',
178
                       '2.21' => 'dois reais e vinte e um centavos',
179
                       '0.01' => 'um centavo de real',
180
                       '0.45' => 'quarenta e cinco centavos de real',
181
                    '1000.00' => 'um mil reais',
182
                 '1000000.00' => 'um milhão de reais',
183
                 '1000001.00' => 'um milhão e um reais',
184
                 '1100000.00' => 'um milhão e cem mil reais',
185
               '100001000000' => 'cem bilhões e um milhão de reais',
186
                 '1000000000' => 'um bilhão de reais',
187
                          );
188
        foreach ($money as $number => $word) {
189
            $this->assertEquals($word, Numbers_Words::toCurrency($number, 'pt_BR'));
190
            $this->assertEquals("$word negativo", Numbers_Words::toCurrency(-$number, 'pt_BR'));
191
        }
192
    }
193
}
194