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: */
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 German.
22
//
23
if (!defined('PHPUnit_MAIN_METHOD')) {
24
    define('PHPUnit_MAIN_METHOD', 'Numbers_Words_English100Test::main');
25
}
26
 
27
require_once 'Numbers/Words.php';
28
require_once 'PHPUnit/Framework.php';
29
 
30
class Numbers_Words_English100Test extends PHPUnit_Framework_TestCase
31
{
32
    var $handle;
33
    var $lang = 'en_100';
34
 
35
    public static function main()
36
    {
37
        require_once 'PHPUnit/TextUI/TestRunner.php';
38
        PHPUnit_TextUI_TestRunner::run(
39
            new PHPUnit_Framework_TestSuite('Numbers_Words_English100Test')
40
        );
41
    }
42
 
43
    function setUp()
44
    {
45
        $this->handle = new Numbers_Words();
46
    }
47
 
48
    /**
49
     * Testing numbers between 0 and 9
50
     */
51
    function testDigits()
52
    {
53
        $digits = array('zero',
54
                        'one',
55
                        'two',
56
                        'three',
57
                        'four',
58
                        'five',
59
                        'six',
60
                        'seven',
61
                        'eight',
62
                        'nine'
63
                       );
64
        for ($i = 0; $i < 10; $i++) {
65
            $number = $this->handle->toWords($i, $this->lang);
66
            $this->assertEquals($digits[$i], $number);
67
        }
68
    }
69
 
70
    /**
71
     * Testing numbers between 10 and 99
72
     */
73
    function testTens()
74
    {
75
        $tens = array(11 => 'eleven',
76
                      12 => 'twelve',
77
                      16 => 'sixteen',
78
                      19 => 'nineteen',
79
                      20 => 'twenty',
80
                      21 => 'twenty-one',
81
                      26 => 'twenty-six',
82
                      30 => 'thirty',
83
                      31 => 'thirty-one',
84
                      40 => 'forty',
85
                      43 => 'forty-three',
86
                      50 => 'fifty',
87
                      55 => 'fifty-five',
88
                      60 => 'sixty',
89
                      67 => 'sixty-seven',
90
                      70 => 'seventy',
91
                      79 => 'seventy-nine'
92
                     );
93
        foreach ($tens as $number => $word) {
94
            $this->assertEquals($word, $this->handle->toWords($number, $this->lang));
95
        }
96
    }
97
 
98
    /**
99
     * Testing numbers between 100 and 999
100
     */
101
    function testHundreds()
102
    {
103
        $hundreds = array(100 => 'one hundred',
104
                          101 => 'one hundred one',
105
                          199 => 'one hundred ninety-nine',
106
                          203 => 'two hundred three',
107
                          287 => 'two hundred eighty-seven',
108
                          300 => 'three hundred',
109
                          356 => 'three hundred fifty-six',
110
                          410 => 'four hundred ten',
111
                          434 => 'four hundred thirty-four',
112
                          578 => 'five hundred seventy-eight',
113
                          689 => 'six hundred eighty-nine',
114
                          729 => 'seven hundred twenty-nine',
115
                          894 => 'eight hundred ninety-four',
116
                          999 => 'nine hundred ninety-nine'
117
                         );
118
        foreach ($hundreds as $number => $word) {
119
            $this->assertEquals($word, $this->handle->toWords($number, $this->lang));
120
        }
121
    }
122
 
123
    /**
124
     * Testing numbers between 1000 and 9999
125
     */
126
    function testThousands()
127
    {
128
        $thousands = array(1000 => 'ten hundred',
129
                           1001 => 'ten hundred one',
130
                           1097 => 'ten hundred ninety-seven',
131
                           1104 => 'eleven hundred four',
132
                           1243 => 'twelve hundred forty-three',
133
                           2385 => 'twenty-three hundred eighty-five',
134
                           3766 => 'thirty-seven hundred sixty-six',
135
                           4196 => 'forty-one hundred ninety-six',
136
                           5846 => 'fifty-eight hundred forty-six',
137
                           6459 => 'sixty-four hundred fifty-nine',
138
                           7232 => 'seventy-two hundred thirty-two',
139
                           8569 => 'eighty-five hundred sixty-nine',
140
                           9539 => 'ninety-five hundred thirty-nine'
141
                          );
142
        foreach ($thousands as $number => $word) {
143
            $this->assertEquals($word, $this->handle->toWords($number, $this->lang));
144
        }
145
    }
146
 
147
    /**
148
    * Test *yllions and *ylliards
149
    */
150
    function testMore()
151
    {
152
        $morers = array(
153
                    50000 => 'five myriad',
154
                   600000 => 'sixty myriad',
155
                  7000000 => 'seven hundred myriad',
156
                 80000000 => 'eighty hundred myriad',
157
                900000000 => 'nine myllion',
158
               1000000000 => 'ten myllion'
159
        );
160
        foreach ($morers as $number => $word) {
161
            $this->assertEquals($word, $this->handle->toWords($number, $this->lang));
162
        }
163
 
164
    }
165
}
166
 
167
if (PHPUnit_MAIN_METHOD == 'Numbers_Words_English100Test::main') {
168
    Numbers_Words_English100Test::main();
169
}
170
?>