mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 10:36:16 +00:00
bringing the numbers helper to 100% coverage
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6850 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
99874c60d9
commit
4621e68803
1 changed files with 55 additions and 0 deletions
|
@ -48,6 +48,10 @@ class NumberTest extends UnitTestCase {
|
||||||
$expected = '#100,100,100';
|
$expected = '#100,100,100';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$result = $this->Number->format($value, 3);
|
||||||
|
$expected = '100,100,100.000';
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$result = $this->Number->format($value);
|
$result = $this->Number->format($value);
|
||||||
$expected = '100,100,100';
|
$expected = '100,100,100';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
@ -222,10 +226,61 @@ class NumberTest extends UnitTestCase {
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testToReadableSize() {
|
function testToReadableSize() {
|
||||||
$result = $this->Number->toReadableSize(0);
|
$result = $this->Number->toReadableSize(0);
|
||||||
$expected = '0 Bytes';
|
$expected = '0 Bytes';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$result = $this->Number->toReadableSize(1);
|
||||||
|
$expected = '1 Byte';
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$under1KB = 45;
|
||||||
|
$result = $this->Number->toReadableSize($under1KB);
|
||||||
|
$expected = $under1KB.' Bytes';
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$under1MB = 1024*1024-1;
|
||||||
|
$result = $this->Number->toReadableSize($under1MB);
|
||||||
|
$expected = sprintf("%01.0f", $under1MB/1024).' KB';
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$under1GB = (float) 1024*1024*1024-1;
|
||||||
|
$result = $this->Number->toReadableSize($under1GB);
|
||||||
|
$expected = sprintf("%01.2f", $under1GB/1024/1024).' MB';
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$float = (float) 1024*1024*1024*1023-1;
|
||||||
|
$result = $this->Number->toReadableSize($float);
|
||||||
|
$expected = sprintf("%01.2f", $float/1024/1024/1024).' GB';
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$float = (float) 1024*1024*1024*1024*1023-1;
|
||||||
|
$result = $this->Number->toReadableSize($float);
|
||||||
|
$expected = sprintf("%01.2f", $float/1024/1024/1024/1024).' TB';
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testToPercentage() {
|
||||||
|
$result = $this->Number->toPercentage(45, 0);
|
||||||
|
$expected = '45%';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Number->toPercentage(45, 2);
|
||||||
|
$expected = '45.00%';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Number->toPercentage(0, 0);
|
||||||
|
$expected = '0%';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Number->toPercentage(0, 4);
|
||||||
|
$expected = '0.0000%';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue