Skip to content

Commit ec64bc6

Browse files
committed
Add imitation decrementExact to java.lang.Math
1 parent 5f7bd7a commit ec64bc6

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/Imitation/java/lang/Math.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ public static function abs($number)
1616
{
1717
return abs($number);
1818
}
19+
20+
/**
21+
* This decrease 1 from parameters
22+
*
23+
* @see https://docs.oracle.com/javase/jp/8/docs/api/java/lang/Math.html#decrementExact-int-
24+
* @param int $a
25+
* @return int
26+
*/
27+
public static function decrementExact($a)
28+
{
29+
return $a - 1;
30+
}
1931
}

tests/ImitateJavaLangMathTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
namespace PHPJava\Tests;
3+
4+
use PHPJava\Core\JavaArchive;
5+
use PHPUnit\Framework\TestCase;
6+
7+
class ImitateJavaLangMathTest extends Base
8+
{
9+
protected $fixtures = [
10+
'ImitateJavaLangMathTest',
11+
];
12+
13+
public function testDecrementExact()
14+
{
15+
ob_start();
16+
$this->initiatedJavaClasses['ImitateJavaLangMathTest']
17+
->getInvoker()
18+
->getStatic()
19+
->getMethods()
20+
->call(
21+
'decrementExact',
22+
1234
23+
);
24+
$value = (int) ob_get_clean();
25+
$this->assertEquals(1233, $value);
26+
}
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class ImitateJavaLangMathTest
2+
{
3+
public static void decrementExact(int a)
4+
{
5+
System.out.println(Math.decrementExact(a));
6+
}
7+
}

0 commit comments

Comments
 (0)