| 1 |
lars |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
//
|
|
|
4 |
// +----------------------------------------------------------------------+
|
|
|
5 |
// | PHP version 4 |
|
|
|
6 |
// +----------------------------------------------------------------------+
|
|
|
7 |
// | Copyright (c) 1997-2003 The PHP Group |
|
|
|
8 |
// +----------------------------------------------------------------------+
|
|
|
9 |
// | This source file is subject to version 3.0 of the PHP license, |
|
|
|
10 |
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
11 |
// | available at through the world-wide-web at |
|
|
|
12 |
// | http://www.php.net/license/3_0.txt. |
|
|
|
13 |
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
14 |
// | obtain it through the world-wide-web, please send a note to |
|
|
|
15 |
// | license@php.net so we can mail you a copy immediately. |
|
|
|
16 |
// +----------------------------------------------------------------------+
|
|
|
17 |
// | Authors: Xavier Noguer |
|
|
|
18 |
// +----------------------------------------------------------------------+
|
|
|
19 |
//
|
|
|
20 |
// Numbers_Words class extension to spell numbers in Spanish (Castellano).
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
require_once 'Numbers/Words.php';
|
|
|
24 |
require_once 'PHPUnit/Framework/TestCase.php';
|
|
|
25 |
|
|
|
26 |
class Numbers_Words_SpanishTest extends PHPUnit_Framework_TestCase
|
|
|
27 |
{
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Testing numbers between 0 and 9
|
|
|
31 |
*/
|
|
|
32 |
function testDigits()
|
|
|
33 |
{
|
|
|
34 |
$digits = array('cero',
|
|
|
35 |
'uno',
|
|
|
36 |
'dos',
|
|
|
37 |
'tres',
|
|
|
38 |
'cuatro',
|
|
|
39 |
'cinco',
|
|
|
40 |
'seis',
|
|
|
41 |
'siete',
|
|
|
42 |
'ocho',
|
|
|
43 |
'nueve'
|
|
|
44 |
);
|
|
|
45 |
for ($i = 0; $i < 10; $i++)
|
|
|
46 |
{
|
|
|
47 |
$number = Numbers_Words::toWords($i, 'es');
|
|
|
48 |
$this->assertEquals($digits[$i], $number);
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Testing numbers between 10 and 99
|
|
|
54 |
*/
|
|
|
55 |
function testTens()
|
|
|
56 |
{
|
|
|
57 |
$tens = array(11 => 'once',
|
|
|
58 |
12 => 'doce',
|
|
|
59 |
16 => 'dieciseis',
|
|
|
60 |
19 => 'diecinueve',
|
|
|
61 |
20 => 'veinte',
|
|
|
62 |
21 => 'veintiuno',
|
|
|
63 |
26 => 'veintiseis',
|
|
|
64 |
30 => 'treinta',
|
|
|
65 |
31 => 'treinta y uno',
|
|
|
66 |
40 => 'cuarenta',
|
|
|
67 |
43 => 'cuarenta y tres',
|
|
|
68 |
50 => 'cincuenta',
|
|
|
69 |
55 => 'cincuenta y cinco',
|
|
|
70 |
60 => 'sesenta',
|
|
|
71 |
67 => 'sesenta y siete',
|
|
|
72 |
70 => 'setenta',
|
|
|
73 |
79 => 'setenta y nueve'
|
|
|
74 |
);
|
|
|
75 |
foreach ($tens as $number => $word) {
|
|
|
76 |
$this->assertEquals($word, Numbers_Words::toWords($number, 'es'));
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Testing numbers between 100 and 999
|
|
|
82 |
*/
|
|
|
83 |
function testHundreds()
|
|
|
84 |
{
|
|
|
85 |
$hundreds = array(100 => 'cien',
|
|
|
86 |
101 => 'ciento uno',
|
|
|
87 |
199 => 'ciento noventa y nueve',
|
|
|
88 |
203 => 'doscientos tres',
|
|
|
89 |
287 => 'doscientos ochenta y siete',
|
|
|
90 |
300 => 'trescientos',
|
|
|
91 |
356 => 'trescientos cincuenta y seis',
|
|
|
92 |
410 => 'cuatrocientos diez',
|
|
|
93 |
434 => 'cuatrocientos treinta y cuatro',
|
|
|
94 |
578 => 'quinientos setenta y ocho',
|
|
|
95 |
689 => 'seiscientos ochenta y nueve',
|
|
|
96 |
729 => 'setecientos veintinueve',
|
|
|
97 |
894 => 'ochocientos noventa y cuatro',
|
|
|
98 |
999 => 'novecientos noventa y nueve'
|
|
|
99 |
);
|
|
|
100 |
foreach ($hundreds as $number => $word) {
|
|
|
101 |
$this->assertEquals($word, Numbers_Words::toWords($number, 'es'));
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/**
|
|
|
106 |
* Testing numbers between 1000 and 9999
|
|
|
107 |
*/
|
|
|
108 |
function testThousands()
|
|
|
109 |
{
|
|
|
110 |
$thousands = array(1000 => 'mil',
|
|
|
111 |
1001 => 'mil uno',
|
|
|
112 |
1097 => 'mil noventa y siete',
|
|
|
113 |
1104 => 'mil ciento cuatro',
|
|
|
114 |
1243 => 'mil doscientos cuarenta y tres',
|
|
|
115 |
2385 => 'dos mil trescientos ochenta y cinco',
|
|
|
116 |
3766 => 'tres mil setecientos sesenta y seis',
|
|
|
117 |
4196 => 'cuatro mil ciento noventa y seis',
|
|
|
118 |
5846 => 'cinco mil ochocientos cuarenta y seis',
|
|
|
119 |
6459 => 'seis mil cuatrocientos cincuenta y nueve',
|
|
|
120 |
7232 => 'siete mil doscientos treinta y dos',
|
|
|
121 |
8569 => 'ocho mil quinientos sesenta y nueve',
|
|
|
122 |
9539 => 'nueve mil quinientos treinta y nueve'
|
|
|
123 |
);
|
|
|
124 |
foreach ($thousands as $number => $word) {
|
|
|
125 |
$this->assertEquals($word, Numbers_Words::toWords($number, 'es'));
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|