File: PortugueseBrazilianTest.php

package info (click to toggle)
php-numbers-words 0.16.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 572 kB
  • ctags: 1,071
  • sloc: php: 7,220; xml: 555; makefile: 5
file content (196 lines) | stat: -rw-r--r-- 8,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 autoindent: */
/**
 * Numbers_Words class extension to spell numbers in Portuguese Brazilian.
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.01 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category   Numbers
 * @package    Numbers_Words
 * @author     Igor Feghali <ifeghali@php.net>
 * @copyright  1997-2008 The PHP Group
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
 * @version    SVN: $Id$
 * @link       http://pear.php.net/package/Numbers_Words
 */

require_once 'Numbers/Words.php';
require_once 'PHPUnit/Framework/TestCase.php';

class Numbers_Words_PortugueseBrazilianTest extends PHPUnit_Framework_TestCase
{
    protected $handle;

    public function setUp() {
        $this->handle = new Numbers_Words();
    }
    /**
     * Testing numbers between 0 and 9
     */
    function testDigits()
    {
        $digits = array('zero',
                        'um',
                        'dois',
                        'trs',
                        'quatro',
                        'cinco',
                        'seis',
                        'sete',
                        'oito',
                        'nove'
                       );
        for ($i = 0; $i < 10; $i++)
        {
            $number = $this->handle->toWords($i, 'pt_BR');
            $this->assertEquals($digits[$i], $number);

            if ($i > 0) {
                $number = $this->handle->toWords(-$i, 'pt_BR');
                $this->assertEquals($digits[$i].' negativo', $number);
            }
        }
    }

    /**
     * Testing numbers between 10 and 99
     */
    function testTens()
    {
        $tens = array(11 => 'onze',
                      12 => 'doze',
                      16 => 'dezesseis',
                      19 => 'dezenove',
                      20 => 'vinte',
                      21 => 'vinte e um',
                      26 => 'vinte e seis',
                      30 => 'trinta',
                      31 => 'trinta e um',
                      40 => 'quarenta',
                      43 => 'quarenta e trs',
                      50 => 'cinqenta',
                      55 => 'cinqenta e cinco',
                      60 => 'sessenta',
                      67 => 'sessenta e sete',
                      70 => 'setenta',
                      79 => 'setenta e nove'
                     );
        foreach ($tens as $number => $word) {
            $this->assertEquals($word, $this->handle->toWords($number, 'pt_BR'));
            $this->assertEquals("$word negativo", $this->handle->toWords(-$number, 'pt_BR'));
        }
    }

    /**
     * Testing numbers between 100 and 999
     */
    function testHundreds()
    {
        $hundreds = array(100 => 'cem',
                          101 => 'cento e um',
                          199 => 'cento e noventa e nove',
                          203 => 'duzentos e trs',
                          287 => 'duzentos e oitenta e sete',
                          300 => 'trezentos',
                          356 => 'trezentos e cinqenta e seis',
                          410 => 'quatrocentos e dez',
                          434 => 'quatrocentos e trinta e quatro',
                          578 => 'quinhentos e setenta e oito',
                          689 => 'seiscentos e oitenta e nove',
                          729 => 'setecentos e vinte e nove',
                          717 => 'setecentos e dezessete',
                          894 => 'oitocentos e noventa e quatro',
                          999 => 'novecentos e noventa e nove'
                         );
        foreach ($hundreds as $number => $word) {
            $this->assertEquals($word, $this->handle->toWords($number, 'pt_BR'));
            $this->assertEquals("$word negativo", $this->handle->toWords(-$number, 'pt_BR'));
        }
    }

    /**
     * Testing numbers between 1000 and 9999
     */
    function testThousands()
    {
        $thousands = array(1000 => 'um mil',
                           1001 => 'um mil e um',
                           1097 => 'um mil e noventa e sete',
                           1104 => 'um mil cento e quatro',
                           1243 => 'um mil duzentos e quarenta e trs',
                           2200 => 'dois mil e duzentos',
                           2385 => 'dois mil trezentos e oitenta e cinco',
                           3766 => 'trs mil setecentos e sessenta e seis',
                           4196 => 'quatro mil cento e noventa e seis',
                           5846 => 'cinco mil oitocentos e quarenta e seis',
                           6459 => 'seis mil quatrocentos e cinqenta e nove',
                           7232 => 'sete mil duzentos e trinta e dois',
                           8569 => 'oito mil quinhentos e sessenta e nove',
                           9539 => 'nove mil quinhentos e trinta e nove'
                          );
        foreach ($thousands as $number => $word) {
            $this->assertEquals($word, $this->handle->toWords($number, 'pt_BR'));
            $this->assertEquals("$word negativo", $this->handle->toWords(-$number, 'pt_BR'));
        }
    }

    /**
     * Testing numbers greater than 9999
     */
    function testMillions()
    {
        $millions = array(1000001   => 'um milho e um',
                          2000025   => 'dois milhes e vinte e cinco',
                          5100000   => 'cinco milhes e cem mil',
                          5015004   => 'cinco milhes quinze mil e quatro',
                          5123000   => 'cinco milhes cento e vinte e trs mil',
                          7100100   => 'sete milhes cem mil e cem',
                          8100345   => 'oito milhes cem mil trezentos e quarenta e cinco',
                          8000016   => 'oito milhes e dezesseis',
                          100000001 => 'cem milhes e um',
                          345199054 => 'trezentos e quarenta e cinco milhes cento e noventa e nove mil e cinqenta e quatro',
                         1000077000 => 'um bilho e setenta e sete mil',
                         1000777000 => 'um bilho setecentos e setenta e sete mil',
                          );
        foreach ($millions as $number => $word) {
            $this->assertEquals($word, $this->handle->toWords($number, 'pt_BR'));
            $this->assertEquals("$word negativo", $this->handle->toWords(-$number, 'pt_BR'));
        }
    }

    /**
     * Testing Currency
     */
    function testCurrency()
    {
        $money = array('1.00' => 'um real',
                       '1.01' => 'um real e um centavo',
                       '1.10' => 'um real e dez centavos',
                       '1.11' => 'um real e onze centavos',
                       '1.21' => 'um real e vinte e um centavos',
                       '2.00' => 'dois reais',
                       '2.01' => 'dois reais e um centavo',
                       '2.10' => 'dois reais e dez centavos',
                       '2.11' => 'dois reais e onze centavos',
                       '2.21' => 'dois reais e vinte e um centavos',
                       '0.01' => 'um centavo de real',
                       '0.45' => 'quarenta e cinco centavos de real',
                    '1000.00' => 'um mil reais',
                 '1000000.00' => 'um milho de reais',
                 '1000001.00' => 'um milho e um reais',
                 '1100000.00' => 'um milho e cem mil reais',
               '100001000000' => 'cem bilhes e um milho de reais',
                 '1000000000' => 'um bilho de reais',
                          );
        foreach ($money as $number => $word) {
            $this->assertEquals($word, $this->handle->toCurrency($number, 'pt_BR'));
            $this->assertEquals("$word negativo", $this->handle->toCurrency(-$number, 'pt_BR'));
        }
    }
}