|
| 1 | +<?php |
| 2 | +namespace PHPJava\Tests; |
| 3 | + |
| 4 | +use Brick\Math\BigInteger; |
| 5 | +use PHPJava\Kernel\Types\_Long; |
| 6 | + |
| 7 | +class BigNumberCalculationTest extends Base |
| 8 | +{ |
| 9 | + protected $fixtures = [ |
| 10 | + 'BigNumberCalculationTest', |
| 11 | + ]; |
| 12 | + |
| 13 | + private function call($method, ...$arguments) |
| 14 | + { |
| 15 | + return $this->initiatedJavaClasses['BigNumberCalculationTest'] |
| 16 | + ->getInvoker() |
| 17 | + ->getStatic() |
| 18 | + ->getMethods() |
| 19 | + ->call($method, ...$arguments); |
| 20 | + } |
| 21 | + |
| 22 | + public function testAdd() |
| 23 | + { |
| 24 | + $result = $this->call( |
| 25 | + explode('::', __METHOD__)[1], |
| 26 | + _Long::get(PHP_INT_MAX), |
| 27 | + _Long::get(PHP_INT_MAX) |
| 28 | + ); |
| 29 | + |
| 30 | + $this->assertEquals('18446744073709551614', (string) $result); |
| 31 | + } |
| 32 | + |
| 33 | + public function testSub() |
| 34 | + { |
| 35 | + $result = $this->call( |
| 36 | + explode('::', __METHOD__)[1], |
| 37 | + _Long::get((string) BigInteger::of(PHP_INT_MAX)->multipliedBy(2)), |
| 38 | + _Long::get(PHP_INT_MAX) |
| 39 | + ); |
| 40 | + |
| 41 | + $this->assertEquals('9223372036854775807', (string) $result); |
| 42 | + } |
| 43 | + |
| 44 | + public function testMul() |
| 45 | + { |
| 46 | + $result = $this->call( |
| 47 | + explode('::', __METHOD__)[1], |
| 48 | + _Long::get(PHP_INT_MAX), |
| 49 | + _Long::get(3) |
| 50 | + ); |
| 51 | + |
| 52 | + $this->assertEquals('27670116110564327421', (string) $result); |
| 53 | + } |
| 54 | + |
| 55 | + public function testDiv() |
| 56 | + { |
| 57 | + $result = $this->call( |
| 58 | + explode('::', __METHOD__)[1], |
| 59 | + _Long::get((string) BigInteger::of(PHP_INT_MAX)->multipliedBy(2)), |
| 60 | + _Long::get(2) |
| 61 | + ); |
| 62 | + |
| 63 | + $this->assertEquals('9223372036854775807', (string) $result); |
| 64 | + } |
| 65 | +} |
0 commit comments