| 1 |
lars |
1 |
<?php
|
|
|
2 |
declare(encoding='iso-8859-15');
|
|
|
3 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
4 |
//
|
|
|
5 |
// +----------------------------------------------------------------------+
|
|
|
6 |
// | PHP version 4 |
|
|
|
7 |
// +----------------------------------------------------------------------+
|
|
|
8 |
// | Copyright (c) 1997-2003 The PHP Group |
|
|
|
9 |
// +----------------------------------------------------------------------+
|
|
|
10 |
// | This source file is subject to version 3.0 of the PHP license, |
|
|
|
11 |
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
12 |
// | available at through the world-wide-web at |
|
|
|
13 |
// | http://www.php.net/license/3_0.txt. |
|
|
|
14 |
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
15 |
// | obtain it through the world-wide-web, please send a note to |
|
|
|
16 |
// | license@php.net so we can mail you a copy immediately. |
|
|
|
17 |
// +----------------------------------------------------------------------+
|
|
|
18 |
// | Authors: Piotr Klaban |
|
|
|
19 |
// +----------------------------------------------------------------------+
|
|
|
20 |
//
|
|
|
21 |
// Numbers_Words class extension to spell numbers in French.
|
|
|
22 |
//
|
|
|
23 |
if (!defined('PHPUnit_MAIN_METHOD')) {
|
|
|
24 |
define('PHPUnit_MAIN_METHOD', 'Numbers_Words_FrenchTest::main');
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
require_once 'Numbers/Words.php';
|
|
|
28 |
require_once 'PHPUnit/Framework.php';
|
|
|
29 |
|
|
|
30 |
class Numbers_Words_FrenchTest extends PHPUnit_Framework_TestCase
|
|
|
31 |
{
|
|
|
32 |
var $handle;
|
|
|
33 |
|
|
|
34 |
public static function main()
|
|
|
35 |
{
|
|
|
36 |
require_once 'PHPUnit/TextUI/TestRunner.php';
|
|
|
37 |
PHPUnit_TextUI_TestRunner::run(
|
|
|
38 |
new PHPUnit_Framework_TestSuite('Numbers_Words_FrenchTest')
|
|
|
39 |
);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
function setUp()
|
|
|
43 |
{
|
|
|
44 |
$this->handle = new Numbers_Words();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Testing numbers between 0 and 9
|
|
|
49 |
*/
|
|
|
50 |
function testDigits()
|
|
|
51 |
{
|
|
|
52 |
$digits = array('zéro',
|
|
|
53 |
'un',
|
|
|
54 |
'deux',
|
|
|
55 |
'trois',
|
|
|
56 |
'quatre',
|
|
|
57 |
'cinq',
|
|
|
58 |
'six',
|
|
|
59 |
'sept',
|
|
|
60 |
'huit',
|
|
|
61 |
'neuf'
|
|
|
62 |
);
|
|
|
63 |
for ($i = 0; $i < 10; $i++) {
|
|
|
64 |
$number = $this->handle->toWords($i, 'fr');
|
|
|
65 |
$this->assertEquals($digits[$i], $number);
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Testing numbers between 10 and 99
|
|
|
71 |
*/
|
|
|
72 |
function testTens()
|
|
|
73 |
{
|
|
|
74 |
$tens = array(11 => 'onze',
|
|
|
75 |
12 => 'douze',
|
|
|
76 |
16 => 'seize',
|
|
|
77 |
19 => 'dix-neuf',
|
|
|
78 |
20 => 'vingt',
|
|
|
79 |
21 => 'vingt et un',
|
|
|
80 |
26 => 'vingt-six',
|
|
|
81 |
30 => 'trente',
|
|
|
82 |
31 => 'trente et un',
|
|
|
83 |
40 => 'quarante',
|
|
|
84 |
43 => 'quarante-trois',
|
|
|
85 |
50 => 'cinquante',
|
|
|
86 |
55 => 'cinquante-cinq',
|
|
|
87 |
60 => 'soixante',
|
|
|
88 |
67 => 'soixante-sept',
|
|
|
89 |
70 => 'soixante-dix',
|
|
|
90 |
71 => 'soixante et onze',
|
|
|
91 |
79 => 'soixante-dix-neuf',
|
|
|
92 |
80 => 'quatre-vingts',
|
|
|
93 |
81 => 'quatre-vingt-un',
|
|
|
94 |
91 => 'quatre-vingt-onze'
|
|
|
95 |
);
|
|
|
96 |
foreach ($tens as $number => $word) {
|
|
|
97 |
$this->assertEquals($word, $this->handle->toWords($number, 'fr'));
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
/**
|
|
|
102 |
* Testing numbers between 100 and 999
|
|
|
103 |
*/
|
|
|
104 |
function testHundreds()
|
|
|
105 |
{
|
|
|
106 |
$hundreds = array(100 => 'cent',
|
|
|
107 |
101 => 'cent un',
|
|
|
108 |
199 => 'cent quatre-vingt-dix-neuf',
|
|
|
109 |
203 => 'deux cent trois',
|
|
|
110 |
287 => 'deux cent quatre-vingt-sept',
|
|
|
111 |
300 => 'trois cents',
|
|
|
112 |
356 => 'trois cent cinquante-six',
|
|
|
113 |
410 => 'quatre cent dix',
|
|
|
114 |
434 => 'quatre cent trente-quatre',
|
|
|
115 |
578 => 'cinq cent soixante-dix-huit',
|
|
|
116 |
689 => 'six cent quatre-vingt-neuf',
|
|
|
117 |
729 => 'sept cent vingt-neuf',
|
|
|
118 |
894 => 'huit cent quatre-vingt-quatorze',
|
|
|
119 |
999 => 'neuf cent quatre-vingt-dix-neuf'
|
|
|
120 |
);
|
|
|
121 |
foreach ($hundreds as $number => $word) {
|
|
|
122 |
$this->assertEquals($word, $this->handle->toWords($number, 'fr'));
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Testing numbers between 1000 and 9999
|
|
|
128 |
*/
|
|
|
129 |
function testThousands()
|
|
|
130 |
{
|
|
|
131 |
$thousands = array(1000 => 'mille',
|
|
|
132 |
1001 => 'mille un',
|
|
|
133 |
1097 => 'mille quatre-vingt-dix-sept',
|
|
|
134 |
1104 => 'mille cent quatre',
|
|
|
135 |
1243 => 'mille deux cent quarante-trois',
|
|
|
136 |
2385 => 'deux mille trois cent quatre-vingt-cinq',
|
|
|
137 |
3766 => 'trois mille sept cent soixante-six',
|
|
|
138 |
4196 => 'quatre mille cent quatre-vingt-seize',
|
|
|
139 |
5846 => 'cinq mille huit cent quarante-six',
|
|
|
140 |
6459 => 'six mille quatre cent cinquante-neuf',
|
|
|
141 |
7232 => 'sept mille deux cent trente-deux',
|
|
|
142 |
8569 => 'huit mille cinq cent soixante-neuf',
|
|
|
143 |
9539 => 'neuf mille cinq cent trente-neuf'
|
|
|
144 |
);
|
|
|
145 |
foreach ($thousands as $number => $word) {
|
|
|
146 |
$this->assertEquals($word, $this->handle->toWords($number, 'fr'));
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
if (PHPUnit_MAIN_METHOD == 'Numbers_Words_FrenchTest::main') {
|
|
|
152 |
Numbers_Words_FrenchTest::main();
|
|
|
153 |
}
|
|
|
154 |
?>
|