Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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