44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
class DecimalTest extends DatabaseTestCase
|
|
{
|
|
public function testMax()
|
|
{
|
|
$first = toDecimal('1.2');
|
|
$second = toDecimal('1.5');
|
|
|
|
$this->assertEquals($second, Decimal::max($first, $second));
|
|
}
|
|
|
|
public function testDecimalComma()
|
|
{
|
|
$this->assertEquals(toDecimal('1,2'), toDecimal('1.2'));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider data_testCompare
|
|
*/
|
|
public function testCompareSurprisinglyWorks($lower, $greater)
|
|
{
|
|
$this->assertTrue($lower < $greater);
|
|
$this->assertTrue($greater > $lower);
|
|
$this->assertFalse($lower > $greater);
|
|
$this->assertFalse($greater < $lower);
|
|
}
|
|
|
|
public function data_testCompare()
|
|
{
|
|
return [
|
|
[toDecimal('0.1'), toDecimal('0.2')],
|
|
[toDecimal('5'), toDecimal('10')],
|
|
[toDecimal('01'), toDecimal('2')],
|
|
[toDecimal('-1'), DecimalConstants::zero()],
|
|
[toDecimal('-2'), DecimalConstants::negativeOne()],
|
|
[\Decimal::fromString('-2', 8), \Decimal::fromString('-1', 4)],
|
|
[\Decimal::fromString('-2', 4), \Decimal::fromString('-1', 8)],
|
|
[toDecimal('0.1'), '0.2'],
|
|
['0.1', toDecimal('0.2')],
|
|
];
|
|
}
|
|
}
|