Skip to content

Commit a383ebe

Browse files
committed
Add big number calculation test
1 parent c451477 commit a383ebe

4 files changed

Lines changed: 90 additions & 2 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "JVM emulator by PHP",
44
"type": "library",
55
"license": "MIT",
6-
"version": "0.0.7.4-dev",
6+
"version": "0.0.7.5-dev",
77
"authors": [
88
{
99
"name": "memory"

src/Core/PHPJava.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ final class PHPJava
1212
/**
1313
* As same as composer version.
1414
*/
15-
const VERSION = 0x000074;
15+
const VERSION = 0x000075;
1616
}

tests/BigNumberCalculationTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class BigNumberCalculationTest
2+
{
3+
public static long testAdd(long a, long b)
4+
{
5+
return a + b;
6+
}
7+
8+
public static long testSub(long a, long b)
9+
{
10+
return a - b;
11+
}
12+
13+
public static long testMul(long a, long b)
14+
{
15+
return a * b;
16+
}
17+
18+
public static long testDiv(long a, long b)
19+
{
20+
return a / b;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)