Files
xxx/tests/php/Unit/NumberWordsTest.php
T
tim ed959888b4 Add PHP unit tests and page tests.
Run "composer install", then "composer test".
2026-09-26 03:48:09 +02:00

56 lines
1.8 KiB
PHP

<?php
namespace Xxx\Tests\Unit;
use PHPUnit\Framework\Attributes\DataProvider;
use Xxx\Tests\Support\TestCase;
// number_words() in navigation.lib.php
class NumberWordsTest extends TestCase {
public static function numbers(): array {
return array(
array(0, 'zero'),
array(1, 'one'),
array(5, 'five'),
array(10, 'ten'),
array(13, 'thirteen'),
array(19, 'nineteen'),
array(20, 'twenty'),
array(21, 'twenty-one'),
array(25, 'twenty-five'),
array(50, 'fifty'),
array(99, 'ninety-nine'),
array(100, 'one hundred'),
array(101, 'one hundred and one'),
array(105, 'one hundred and five'),
array(110, 'one hundred and ten'),
array(999, 'nine hundred and ninety-nine'),
array(1000, 'one thousand'),
array(1001, 'one thousand and one'),
array(1099, 'one thousand and ninety-nine'),
array(1100, 'one thousand one hundred'),
array(12345, 'twelve thousand three hundred and forty-five'),
array(100000, 'one hundred thousand'),
array(1000000, 'one million'),
array(2000300, 'two million three hundred'),
array(1000000001, 'one billion and one'),
array(-7, 'minus seven'),
array(-121, 'minus one hundred and twenty-one'),
);
}
#[DataProvider('numbers')]
public function testWords(int $number, string $words): void {
$this->assertSame($words, number_words($number));
}
public function testNumericStringsAreAccepted(): void {
$this->assertSame('forty-two', number_words('42'));
}
// The pager shows between 1 and MAX_SHOW stories
public function testEveryPageSizeHasWords(): void {
for ($n = 1; $n <= MAX_SHOW; $n++)
$this->assertMatchesRegularExpression('/^[a-z]+(-[a-z]+)?$/', number_words($n), "for $n");
}
}