2009-02-05 03:33:00 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-02-05 03:33:00 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class PercentageTest extends SapphireTest {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testNice() {
|
2009-02-05 03:33:00 +01:00
|
|
|
/* Test the default Nice() output of Percentage */
|
|
|
|
$cases = array(
|
|
|
|
'0.01' => '1.00%',
|
|
|
|
'0.10' => '10.00%',
|
|
|
|
'1' => '100.00%',
|
|
|
|
'1.5' => '150.00%',
|
|
|
|
'1.5000' => '150.00%',
|
|
|
|
'1.05' => '105.00%',
|
|
|
|
'1.0500' => '105.00%',
|
|
|
|
'0.95' => '95.00%'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-02-05 03:33:00 +01:00
|
|
|
foreach($cases as $original => $expected) {
|
|
|
|
$percentage = new Percentage('Probability');
|
|
|
|
$percentage->setValue($original);
|
|
|
|
$this->assertEquals($expected, $percentage->Nice());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCustomPrecision() {
|
2009-02-05 03:33:00 +01:00
|
|
|
/* Set a precision that's different from the default with Nice() output */
|
|
|
|
$cases = array(
|
|
|
|
'0.01' => '1%',
|
|
|
|
'0.1' => '10%',
|
|
|
|
'1' => '100%',
|
|
|
|
'1.5' => '150%',
|
|
|
|
'1.05' => '105%',
|
|
|
|
'1.0500' => '105%'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-02-05 03:33:00 +01:00
|
|
|
foreach($cases as $original => $expected) {
|
|
|
|
$percentage = new Percentage('Probability', 2);
|
|
|
|
$percentage->setValue($original);
|
|
|
|
$this->assertEquals($expected, $percentage->Nice());
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-02-05 03:33:00 +01:00
|
|
|
}
|