Пример #1
0
 /**
  * @test roundModes
  * @dataProvider roundValues
  *
  * @param int    $mode
  * @param string $value
  * @param int    $scale
  * @param string $result
  */
 public function roundModes($mode, $value, $scale, $result)
 {
     $decimal = new BigDecimal($value);
     $rounded = $decimal->round($scale, $mode);
     $this->assertSame($result, $rounded->value(), sprintf('Round "%s" with mode "%d" and scale "%d"', $value, $mode, $scale));
 }
Пример #2
0
 /**
  * @test comparisonFunctions
  * @dataProvider comparisonData
  */
 public function comparisonFunctionTest($val1, $val2, $expectedResult)
 {
     $num1 = new BigDecimal($val1);
     $num2 = new BigDecimal($val2);
     $this->assertEquals($expectedResult, $num1->compareTo($num2));
     if ($expectedResult == -1) {
         $this->assertEquals(true, $num1->isLessThan($num2));
         $this->assertEquals(true, $num1->isLessThanOrEqualTo($num2));
         $this->assertEquals(false, $num1->isEqualTo($num2));
         $this->assertEquals(false, $num1->isGreaterThan($num2));
         $this->assertEquals(false, $num1->isGreaterThanOrEqualTo($num2));
     }
     if ($expectedResult == 0) {
         $this->assertEquals(false, $num1->isLessThan($num2));
         $this->assertEquals(true, $num1->isLessThanOrEqualTo($num2));
         $this->assertEquals(true, $num1->isEqualTo($num2));
         $this->assertEquals(false, $num1->isGreaterThan($num2));
         $this->assertEquals(true, $num1->isGreaterThanOrEqualTo($num2));
     }
     if ($expectedResult == 1) {
         $this->assertEquals(false, $num1->isLessThan($num2));
         $this->assertEquals(false, $num1->isLessThanOrEqualTo($num2));
         $this->assertEquals(false, $num1->isEqualTo($num2));
         $this->assertEquals(true, $num1->isGreaterThan($num2));
         $this->assertEquals(true, $num1->isGreaterThanOrEqualTo($num2));
     }
 }