diff --git a/composer.lock b/composer.lock index af0f667..82581a1 100644 --- a/composer.lock +++ b/composer.lock @@ -8,19 +8,20 @@ "packages": [ { "name": "poseidon2/math", - "version": "1.0.0", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/FrankMarkwort/Math.git", - "reference": "7b4263ff03801fe18bded99a03fdbf5cb3568c49" + "reference": "70999367939f953b9fe640799ee482d16b0cd920" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FrankMarkwort/Math/zipball/7b4263ff03801fe18bded99a03fdbf5cb3568c49", - "reference": "7b4263ff03801fe18bded99a03fdbf5cb3568c49", + "url": "https://api.github.com/repos/FrankMarkwort/Math/zipball/70999367939f953b9fe640799ee482d16b0cd920", + "reference": "70999367939f953b9fe640799ee482d16b0cd920", "shasum": "" }, "require": { + "ext-bcmath": "*", "php": ">= 8.3" }, "require-dev": { @@ -43,12 +44,12 @@ "role": "Developer" } ], - "description": "Math vector", + "description": "Math-Vector library", "support": { "issues": "https://github.com/FrankMarkwort/Math/issues", - "source": "https://github.com/FrankMarkwort/Math/tree/1.0" + "source": "https://github.com/FrankMarkwort/Math/tree/1.0.3" }, - "time": "2024-09-15T14:53:12+00:00" + "time": "2024-09-18T22:53:05+00:00" } ], "packages-dev": [ diff --git a/src/Core/Parser/Decode/DecodeNmea2000.php b/src/Core/Parser/Decode/DecodeNmea2000.php index f475e4b..b851ad0 100644 --- a/src/Core/Parser/Decode/DecodeNmea2000.php +++ b/src/Core/Parser/Decode/DecodeNmea2000.php @@ -5,7 +5,7 @@ use Exception; use Core\Parser\ParserException; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; class DecodeNmea2000 implements DecoderInterface { diff --git a/src/Core/Parser/Lib/BinDec.php b/src/Core/Parser/Lib/BinDec.php deleted file mode 100644 index b970de1..0000000 --- a/src/Core/Parser/Lib/BinDec.php +++ /dev/null @@ -1,136 +0,0 @@ -= 1; - } - - /** - * @throws Exception - */ - private static function validBitLength(string $bin):void - { - if (! in_array(strlen($bin), [4 ,8, 16 ,32 ,64])) { - throw new Exception('can only convert 4 ,8, 16 ,32 ,64 length to dec'); - } - } - - private static function bitFlip(string $bin):string - { - for($i = 0; $i < strlen($bin); $i++) { - $bin[$i] = $bin[$i] == '1' ? '0' : '1'; - } - - return $bin; - } - - private static function is_32bit():bool - { - return PHP_INT_SIZE === 4; - } -} diff --git a/test/Core/Parser/Data/DataPartTest.php b/test/Core/Parser/Data/DataPartTest.php index 31139af..408296c 100644 --- a/test/Core/Parser/Data/DataPartTest.php +++ b/test/Core/Parser/Data/DataPartTest.php @@ -5,7 +5,7 @@ use Core\Parser\Decode\DecodeNmea2000; use Core\Config\ConfigPgn; use Core\Config\PngFieldConfig; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; diff --git a/test/Core/Parser/DataFacadeFactoryTest.php b/test/Core/Parser/DataFacadeFactoryTest.php index 8591e42..fccb05c 100644 --- a/test/Core/Parser/DataFacadeFactoryTest.php +++ b/test/Core/Parser/DataFacadeFactoryTest.php @@ -9,7 +9,7 @@ use Core\Parser\Data\DataPart; use Core\Parser\Data\MainPart; use Core\Parser\Decode\DecodeNmea2000; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Core\Parser\DataFacadeFactory; diff --git a/test/Core/Parser/DataFacadeTest.php b/test/Core/Parser/DataFacadeTest.php index 5059ffd..288d90d 100644 --- a/test/Core/Parser/DataFacadeTest.php +++ b/test/Core/Parser/DataFacadeTest.php @@ -11,7 +11,7 @@ use Core\Parser\Data\MainPart; use Core\Parser\DataFacadeFactory; use Core\Parser\Decode\DecodeNmea2000; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; diff --git a/test/Core/Parser/Decode/DecodeNmea2000Test.php b/test/Core/Parser/Decode/DecodeNmea2000Test.php index 2716878..f781697 100644 --- a/test/Core/Parser/Decode/DecodeNmea2000Test.php +++ b/test/Core/Parser/Decode/DecodeNmea2000Test.php @@ -2,7 +2,7 @@ namespace TestCore\Parser\Decode; use Core\Parser\Decode\Request; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\CoversClass; use Core\Parser\Decode\DecodeNmea2000; diff --git a/test/Core/Parser/Lib/BinDecTest.php b/test/Core/Parser/Lib/BinDecTest.php deleted file mode 100644 index 7cf601b..0000000 --- a/test/Core/Parser/Lib/BinDecTest.php +++ /dev/null @@ -1,97 +0,0 @@ -assertEquals(1, BinDec::bin2dec('0001', true)); - $this->assertEquals(1, BinDec::bin2dec('0001', false)); - $this->assertEquals(2, BinDec::bin2dec('0010', true)); - $this->assertEquals(2, BinDec::bin2dec('0010', false)); - $this->assertEquals(3, BinDec::bin2dec('0011', true)); - $this->assertEquals(3, BinDec::bin2dec('0011', false)); - $this->assertEquals(7, BinDec::bin2dec('0111', true)); - $this->assertEquals(7, BinDec::bin2dec('0111', false)); - $this->assertEquals(-1, BinDec::bin2dec('1111', true)); - $this->assertEquals(15, BinDec::bin2dec('1111', false)); - $this->assertEquals(-7, BinDec::bin2dec('1001', true)); - $this->assertEquals(9, BinDec::bin2dec('1001', false)); - $this->assertEquals(-6, BinDec::bin2dec('1010', true)); - $this->assertEquals(10, BinDec::bin2dec('1010', false)); - $this->assertEquals(-5, BinDec::bin2dec('1011', true)); - $this->assertEquals(11, BinDec::bin2dec('1011', false)); - $this->assertEquals(22, BinDec::bin2dec('1011', false, 2)); - } - - public static function dataProviderbindec64BitSame():array - { - return [ - ['1111'], - ['11111111'], - ['1111111111111111'], - ['11111111111111111111111111111111'], - ['1111111111111111111111111111111111111111111111111111111111111111'], - ['0111011111110001111001111110001111111011111111110111111111111111'] - ]; - } - #[DataProvider('dataProviderbindec64BitSame')] - public function testInternelAgainst64BitSame(string $bin) - { - $this->assertEquals(bindec($bin), BinDec::bin2dec64BitSystem($bin), strlen($bin)); - } - public static function dataProvider32And64BitSame():array - { - return [ - ['1111'], - ['11111111'], - ['1111111111111111'], - ['11111111111111111111111111111111'], - ['1111111111111111111111111111111111111111111111111111111111111111'], - ['1111', true], - ['11111111',true], - ['1111111111111111',true], - ['11111111111111111111111111111111',true], - ['1111111111111111111111111111111111111111111111111111111111111111',true], - ['1111', true], - ['11111111',true], - ['1111111111111111',true], - ['11111111111111111111111111111111',true], - ['1111111111111111111111111111111111111111111111111111111111111111',true, 1E-16], - ['0000010100100111000110011101010111110100010111111100001000000000',true, 1E-16], - ['1000000000000000000000000000000000000000000000000000000000000000',true, 0,001] - ]; - } - #[DataProvider('dataProvider32And64BitSame')] - public function test32And64BitSame(string $bin, bool $signed = false, float $resolution = 1) - { - $this->assertEquals(BinDec::bin2dec64BitSystem($bin, $signed, $resolution), BinDec::bin2dec32BitSystem($bin, $signed, $resolution), strlen($bin)); - } - - public function testResult32BitSystem() - { - $this->assertEquals(37.1293901, BinDec::bin2dec32BitSystem('0000010100100111000110011101010111110100010111111100001000000000', true, 1E-16)); - $this->assertEquals(37.1293901, BinDec::bin2dec64BitSystem('0000010100100111000110011101010111110100010111111100001000000000', true, 1E-16)); - } - - public function testIsNotBinaryException() - { - $this->expectException('\Exception'); - BinDec::bin2dec('0a01', true); - } - - public function testWrongLengt() - { - $this->expectException('\Exception'); - BinDec::bin2dec('00011', true); - } -} diff --git a/test/miniTest32BitSystem.php b/test/miniTest32BitSystem.php deleted file mode 100644 index 3b0951b..0000000 --- a/test/miniTest32BitSystem.php +++ /dev/null @@ -1,8 +0,0 @@ -