Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 autoindent: */
3
/**
4
 * Numbers_Words class extension to spell numbers in Italian.
5
 *
6
 * PHP versions 4 and 5
7
 *
8
 * LICENSE: This source file is subject to version 3.01 of the PHP license
9
 * that is available through the world-wide-web at the following URI:
10
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
11
 * the PHP License and are unable to obtain it through the web, please
12
 * send a note to license@php.net so we can mail you a copy immediately.
13
 *
14
 * @category   Numbers
15
 * @package    Numbers_Words
16
 * @author     Lorenzo Alberton <l.alberton@quipo.it>
17
 * @copyright  1997-2008 The PHP Group
18
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
19
 * @version    CVS: $Id: ItalianTest.php 277000 2009-03-11 15:37:42Z kouber $
20
 * @link       http://pear.php.net/package/Numbers_Words
21
 * @since      File available only in CVS
22
 */
23
 
24
require_once 'Numbers/Words.php';
25
require_once 'PHPUnit/Framework/TestCase.php';
26
 
27
class Numbers_Words_ItalianTest extends PHPUnit_Framework_TestCase
28
{
29
 
30
    /**
31
     * Testing numbers between 0 and 9
32
     */
33
    function testDigits()
34
    {
35
        $digits = array(
36
            'zero',
37
            'uno',
38
            'due',
39
            'tre',
40
            'quattro',
41
            'cinque',
42
            'sei',
43
            'sette',
44
            'otto',
45
            'nove',
46
        );
47
        for ($i = 0; $i < 10; $i++) {
48
            $number = Numbers_Words::toWords($i, 'it_IT');
49
            $this->assertEquals($digits[$i], $number);
50
        }
51
    }
52
 
53
    /**
54
     * Testing numbers between 10 and 99
55
     */
56
    function testTens()
57
    {
58
        $tens = array(
59
            11 => 'undici',
60
            12 => 'dodici',
61
            16 => 'sedici',
62
            19 => 'diciannove',
63
            20 => 'venti',
64
            21 => 'ventuno',
65
            26 => 'ventisei',
66
            30 => 'trenta',
67
            31 => 'trentuno',
68
            40 => 'quaranta',
69
            43 => 'quarantatre',
70
            50 => 'cinquanta',
71
            55 => 'cinquantacinque',
72
            60 => 'sessanta',
73
            67 => 'sessantasette',
74
            70 => 'settanta',
75
            79 => 'settantanove',
76
        );
77
        foreach ($tens as $number => $word) {
78
            $this->assertEquals($word, Numbers_Words::toWords($number, 'it_IT'));
79
        }
80
    }
81
 
82
    /**
83
     * Testing numbers between 100 and 999
84
     */
85
    function testHundreds()
86
    {
87
        $hundreds = array(
88
            100 => 'cento',
89
            101 => 'centouno',
90
            199 => 'centonovantanove',
91
            203 => 'duecentotre',
92
            287 => 'duecentoottantasette',
93
            300 => 'trecento',
94
            356 => 'trecentocinquantasei',
95
            410 => 'quattrocentodieci',
96
            434 => 'quattrocentotrentaquattro',
97
            578 => 'cinquecentosettantotto',
98
            689 => 'seicentoottantanove',
99
            729 => 'settecentoventinove',
100
            894 => 'ottocentonovantaquattro',
101
            999 => 'novecentonovantanove'
102
        );
103
        foreach ($hundreds as $number => $word) {
104
            $this->assertEquals($word, Numbers_Words::toWords($number, 'it_IT'));
105
        }
106
    }
107
 
108
    /**
109
     * Testing numbers between 1000 and 9999
110
     */
111
    function testThousands()
112
    {
113
        $thousands = array(
114
            1000 => 'mille',
115
            1001 => 'milleuno',
116
            1097 => 'millenovantasette',
117
            1104 => 'millecentoquattro',
118
            1243 => 'milleduecentoquarantatre',
119
            2385 => 'duemilatrecentoottantacinque',
120
            3766 => 'tremilasettecentosessantasei',
121
            4196 => 'quattromilacentonovantasei',
122
            5846 => 'cinquemilaottocentoquarantasei',
123
            6459 => 'seimilaquattrocentocinquantanove',
124
            7232 => 'settemiladuecentotrentadue',
125
            8569 => 'ottomilacinquecentosessantanove',
126
            9539 => 'novemilacinquecentotrentanove',
127
        );
128
 
129
        foreach ($thousands as $number => $word) {
130
            $this->assertEquals($word, Numbers_Words::toWords($number, 'it_IT'));
131
        }
132
    }
133
}
134