当前路径:vendor/maennchen/zipstream-php/test/BigintTest.php <?php declare(strict_types=1); namespace BigintTest; use OverflowException; use PHPUnit\Framework\TestCase; use ZipStream\Bigint; class BigintTest extends TestCase { public function testConstruct(): void { $bigint = new Bigint(0x12345678); $this->assertSame('0x0000000012345678', $bigint->getHex64()); $this->assertSame(0x12345678, $bigint->getLow32()); $this->assertSame(0, $bigint->getHigh32()); } public function testConstructLarge(): void { $bigint = new Bigint(0x87654321); $this->assertSame('0x0000000087654321', $bigint->getHex64()); $this->assertSame('87654321', bin2hex(pack('N', $bigint->getLow32()))); $this->assertSame(0, $bigint->getHigh32()); } public function testAddSmallValue(): void { $bigint = new Bigint(1); $bigint = $bigint->add(Bigint::init(2)); $this->assertSame(3, $bigint->getLow32()); $this->assertFalse($bigint->isOver32()); $this->assertTrue($bigint->isOver32(true)); $this->assertSame($bigint->getLowFF(), (float)$bigint->getLow32()); $this->assertSame($bigint->getLowFF(true), (float)0xFFFFFFFF); } public function testAddWithOverflowAtLowestByte(): void { $bigint = new Bigint(0xFF); $bigint = $bigint->add(Bigint::init(0x01)); $this->assertSame(0x100, $bigint->getLow32()); } public function testAddWithOverflowAtInteger32(): void { $bigint = new Bigint(0xFFFFFFFE); $this->assertFalse($bigint->isOver32()); $bigint = $bigint->add(Bigint::init(0x01)); $this->assertTrue($bigint->isOver32()); $bigint = $bigint->add(Bigint::init(0x01)); $this->assertSame('0x0000000100000000', $bigint->getHex64()); $this->assertTrue($bigint->isOver32()); $this->assertSame((float)0xFFFFFFFF, $bigint->getLowFF()); } public function testAddWithOverflowAtInteger64(): void { $bigint = Bigint::fromLowHigh(0xFFFFFFFF, 0xFFFFFFFF); $this->assertSame('0xFFFFFFFFFFFFFFFF', $bigint->getHex64()); $this->expectException(OverflowException::class); $bigint->add(Bigint::init(1)); } }
相关源码
- 可旋转的彩色立方体C#源代码2021-10-29
- 在线考试系统2021-10-15
- EduSoho开源网校系统源码2019-06-27
- 仿拼多多小程序商城源码2019-06-06
- PHP5网站运行监测系统源码2017-04-14
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2023. 京ICP备09089570号 | 京公网安备11010702000869号
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2023. 京ICP备09089570号 | 京公网安备11010702000869号