You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
655 B
22 lines
655 B
8 years ago
|
<?php
|
||
|
namespace Tests\IecType;
|
||
|
|
||
|
use PHPModbus\IecType;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
|
||
|
class IecIntTest extends TestCase
|
||
|
{
|
||
|
private static function unPackInt2HexString($value)
|
||
|
{
|
||
|
return unpack('H*', IecType::iecINT($value))[1];
|
||
|
}
|
||
|
|
||
|
public function testIecInt()
|
||
|
{
|
||
|
$this->assertEquals('0000', self::unPackInt2HexString(0));
|
||
|
$this->assertEquals('0001', self::unPackInt2HexString(1));
|
||
|
$this->assertEquals('ffff', self::unPackInt2HexString(-1));
|
||
|
$this->assertEquals('7fff', self::unPackInt2HexString(pow(2, 15) - 1));
|
||
|
$this->assertEquals('8000', self::unPackInt2HexString(-pow(2, 15)));
|
||
|
}
|
||
|
}
|