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 British English.
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    Christian Weiske <cweiske@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: EnglishGbTest.php 277160 2009-03-14 18:54:15Z kouber $
21
 * @link      http://pear.php.net/package/Numbers_Words
22
 * @since     File available only in CVS
23
 */
24
if (!defined('PHPUnit_MAIN_METHOD')) {
25
    define('PHPUnit_MAIN_METHOD', 'Numbers_Words_EnglishGbTest::main');
26
}
27
 
28
require_once 'Numbers/Words.php';
29
require_once 'PHPUnit/Framework.php';
30
 
31
class Numbers_Words_EnglishGbTest extends PHPUnit_Framework_TestCase
32
{
33
    var $handle;
34
    var $lang = 'en_GB';
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_EnglishGbTest')
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('zero',
55
                        'one',
56
                        'two',
57
                        'three',
58
                        'four',
59
                        'five',
60
                        'six',
61
                        'seven',
62
                        'eight',
63
                        'nine'
64
                       );
65
        for ($i = 0; $i < 10; $i++) {
66
            $number = $this->handle->toWords($i, $this->lang);
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 => 'eleven',
77
                      12 => 'twelve',
78
                      16 => 'sixteen',
79
                      19 => 'nineteen',
80
                      20 => 'twenty',
81
                      21 => 'twenty-one',
82
                      26 => 'twenty-six',
83
                      30 => 'thirty',
84
                      31 => 'thirty-one',
85
                      40 => 'forty',
86
                      43 => 'forty-three',
87
                      50 => 'fifty',
88
                      55 => 'fifty-five',
89
                      60 => 'sixty',
90
                      67 => 'sixty-seven',
91
                      70 => 'seventy',
92
                      79 => 'seventy-nine'
93
                     );
94
        foreach ($tens as $number => $word) {
95
            $this->assertEquals($word, $this->handle->toWords($number, $this->lang));
96
        }
97
    }
98
 
99
    /**
100
     * Testing numbers between 100 and 999
101
     */
102
    function testHundreds()
103
    {
104
        $hundreds = array(100 => 'one hundred',
105
                          101 => 'one hundred one',
106
                          199 => 'one hundred ninety-nine',
107
                          203 => 'two hundred three',
108
                          287 => 'two hundred eighty-seven',
109
                          300 => 'three hundred',
110
                          356 => 'three hundred fifty-six',
111
                          410 => 'four hundred ten',
112
                          434 => 'four hundred thirty-four',
113
                          578 => 'five hundred seventy-eight',
114
                          689 => 'six hundred eighty-nine',
115
                          729 => 'seven hundred twenty-nine',
116
                          894 => 'eight hundred ninety-four',
117
                          999 => 'nine hundred ninety-nine'
118
                         );
119
        foreach ($hundreds as $number => $word) {
120
            $this->assertEquals($word, $this->handle->toWords($number, $this->lang));
121
        }
122
    }
123
 
124
    /**
125
     * Testing numbers between 1000 and 9999
126
     */
127
    function testThousands()
128
    {
129
        $thousands = array(1000 => 'one thousand',
130
                           1001 => 'one thousand one',
131
                           1097 => 'one thousand ninety-seven',
132
                           1104 => 'one thousand one hundred four',
133
                           1243 => 'one thousand two hundred forty-three',
134
                           2385 => 'two thousand three hundred eighty-five',
135
                           3766 => 'three thousand seven hundred sixty-six',
136
                           4196 => 'four thousand one hundred ninety-six',
137
                           5846 => 'five thousand eight hundred forty-six',
138
                           6459 => 'six thousand four hundred fifty-nine',
139
                           7232 => 'seven thousand two hundred thirty-two',
140
                           8569 => 'eight thousand five hundred sixty-nine',
141
                           9539 => 'nine thousand five hundred thirty-nine'
142
                          );
143
        foreach ($thousands as $number => $word) {
144
            $this->assertEquals($word, $this->handle->toWords($number, $this->lang));
145
        }
146
    }
147
 
148
    /**
149
    * en_GB (old version) and en_US differentiate in their millions/billions/trillions
150
    * because en_GB once used the long scale, and en_US the short scale.
151
    * GB abandoned the long scale in 1974, though.
152
    *
153
    * Numbers_Words still provides the long scale. Use en_US to get short scaled numbers.
154
    */
155
    function testMore()
156
    {
157
 
158
        $this->assertEquals('one million', $this->handle->toWords(1000000, $this->lang));
159
 
160
        $this->assertEquals('two thousand million', $this->handle->toWords(2000000000, $this->lang));
161
 
162
 
163
        // 32 bit systems vs PHP_INT_SIZE - 3 billion is a little high, so use a string version.
164
        $number = '3000000000000' > PHP_INT_SIZE? '3000000000000' : 3000000000000;
165
 
166
        $this->assertEquals('three billion', $this->handle->toWords($number, $this->lang));
167
 
168
    }
169
}
170
 
171
if (PHPUnit_MAIN_METHOD == 'Numbers_Words_EnglishGbTest::main') {
172
    Numbers_Words_EnglishGbTest::main();
173
}
174
?>