mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-16 16:17:43 +03:00
Depend on brick/math for arbitrary-precision math
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Uuid\Test\Math;
|
||||
|
||||
use Ramsey\Uuid\Math\BrickMathCalculator;
|
||||
use Ramsey\Uuid\Math\RoundingMode;
|
||||
use Ramsey\Uuid\Test\TestCase;
|
||||
use Ramsey\Uuid\Type\Hexadecimal;
|
||||
use Ramsey\Uuid\Type\IntegerValue;
|
||||
|
||||
class BrickMathCalculatorTest extends TestCase
|
||||
{
|
||||
public function testAdd()
|
||||
{
|
||||
$int1 = new IntegerValue(5);
|
||||
$int2 = new IntegerValue(6);
|
||||
$int3 = new IntegerValue(7);
|
||||
|
||||
$calculator = new BrickMathCalculator();
|
||||
|
||||
$result = $calculator->add($int1, $int2, $int3);
|
||||
|
||||
$this->assertSame('18', $result->toString());
|
||||
}
|
||||
|
||||
public function testSubtract()
|
||||
{
|
||||
$int1 = new IntegerValue(5);
|
||||
$int2 = new IntegerValue(6);
|
||||
$int3 = new IntegerValue(7);
|
||||
|
||||
$calculator = new BrickMathCalculator();
|
||||
|
||||
$result = $calculator->subtract($int1, $int2, $int3);
|
||||
|
||||
$this->assertSame('-8', $result->toString());
|
||||
}
|
||||
|
||||
public function testMultiply()
|
||||
{
|
||||
$int1 = new IntegerValue(5);
|
||||
$int2 = new IntegerValue(6);
|
||||
$int3 = new IntegerValue(7);
|
||||
|
||||
$calculator = new BrickMathCalculator();
|
||||
|
||||
$result = $calculator->multiply($int1, $int2, $int3);
|
||||
|
||||
$this->assertSame('210', $result->toString());
|
||||
}
|
||||
|
||||
public function testDivide()
|
||||
{
|
||||
$int1 = new IntegerValue(1023);
|
||||
$int2 = new IntegerValue(6);
|
||||
$int3 = new IntegerValue(7);
|
||||
|
||||
$calculator = new BrickMathCalculator();
|
||||
|
||||
$result = $calculator->divide(RoundingMode::HALF_UP, $int1, $int2, $int3);
|
||||
|
||||
$this->assertSame('24', $result->toString());
|
||||
}
|
||||
|
||||
public function testFromBase()
|
||||
{
|
||||
$calculator = new BrickMathCalculator();
|
||||
|
||||
$result = $calculator->fromBase('ffffffffffffffffffff', 16);
|
||||
|
||||
$this->assertInstanceOf(IntegerValue::class, $result);
|
||||
$this->assertSame('1208925819614629174706175', $result->toString());
|
||||
}
|
||||
|
||||
public function testToBase()
|
||||
{
|
||||
$intValue = new IntegerValue('1208925819614629174706175');
|
||||
$calculator = new BrickMathCalculator();
|
||||
|
||||
$this->assertSame('ffffffffffffffffffff', $calculator->toBase($intValue, 16));
|
||||
}
|
||||
|
||||
public function testToHexadecimal()
|
||||
{
|
||||
$intValue = new IntegerValue('1208925819614629174706175');
|
||||
$calculator = new BrickMathCalculator();
|
||||
|
||||
$result = $calculator->toHexadecimal($intValue);
|
||||
|
||||
$this->assertInstanceOf(Hexadecimal::class, $result);
|
||||
$this->assertSame('ffffffffffffffffffff', $result->toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user