1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SKien\Test\PNServer; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use SKien\PNServer\Utils\Point; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Stefanius <[email protected]> |
11
|
|
|
* @copyright MIT License - see the LICENSE file for details |
12
|
|
|
*/ |
13
|
|
|
class UtilsPointTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function test_create() : void |
16
|
|
|
{ |
17
|
|
|
$pt = Point::create(gmp_init(20, 10), gmp_init(30, 10)); |
18
|
|
|
$this->assertEquals(gmp_cmp($pt->getX(), gmp_init(20, 10)), 0); |
19
|
|
|
$this->assertEquals(gmp_cmp($pt->getY(), gmp_init(30, 10)), 0); |
20
|
|
|
$this->assertEquals(gmp_cmp($pt->getOrder(), gmp_init(0, 10)), 0); |
21
|
|
|
$this->assertFalse($pt->isInfinity()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function test_infinity() : void |
25
|
|
|
{ |
26
|
|
|
$pt = Point::infinity(); |
27
|
|
|
$this->assertEquals(gmp_cmp($pt->getX(), gmp_init(0, 10)), 0); |
28
|
|
|
$this->assertEquals(gmp_cmp($pt->getY(), gmp_init(0, 10)), 0); |
29
|
|
|
$this->assertTrue($pt->isInfinity()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function test_csswap() : void |
33
|
|
|
{ |
34
|
|
|
$ptA = Point::create(gmp_init(20, 10), gmp_init(30, 10)); |
35
|
|
|
$ptB = Point::create(gmp_init(40, 10), gmp_init(50, 10)); |
36
|
|
|
Point::cswap($ptA, $ptB, 1); |
37
|
|
|
$this->assertEquals(gmp_cmp($ptA->getX(), gmp_init(40, 10)), 0); |
38
|
|
|
$this->assertEquals(gmp_cmp($ptA->getY(), gmp_init(50, 10)), 0); |
39
|
|
|
$this->assertEquals(gmp_cmp($ptB->getX(), gmp_init(20, 10)), 0); |
40
|
|
|
$this->assertEquals(gmp_cmp($ptB->getY(), gmp_init(30, 10)), 0); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|