Uploaded From CV. Swandhana Server
This commit is contained in:
222
vendor/bacon/bacon-qr-code/test/Common/BitArrayTest.php
vendored
Normal file
222
vendor/bacon/bacon-qr-code/test/Common/BitArrayTest.php
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCodeTest\Common;
|
||||
|
||||
use BaconQrCode\Common\BitArray;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Runner\Version as PHPUnitVersion;
|
||||
|
||||
final class BitArrayTest extends TestCase
|
||||
{
|
||||
private function getPhpUnitMajorVersion(): int
|
||||
{
|
||||
return (int) explode('.', PHPUnitVersion::id())[0];
|
||||
}
|
||||
|
||||
public function testGetSet() : void
|
||||
{
|
||||
$array = new BitArray(33);
|
||||
|
||||
for ($i = 0; $i < 33; ++$i) {
|
||||
$this->assertFalse($array->get($i));
|
||||
$array->set($i);
|
||||
$this->assertTrue($array->get($i));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetNextSet1() : void
|
||||
{
|
||||
$array = new BitArray(32);
|
||||
|
||||
for ($i = 0; $i < $array->getSize(); ++$i) {
|
||||
if ($this->getPhpUnitMajorVersion() === 7) {
|
||||
$this->assertEquals($i, 32, '', $array->getNextSet($i));
|
||||
} else {
|
||||
$this->assertEqualsWithDelta($i, 32, $array->getNextSet($i));
|
||||
}
|
||||
}
|
||||
|
||||
$array = new BitArray(33);
|
||||
|
||||
for ($i = 0; $i < $array->getSize(); ++$i) {
|
||||
if ($this->getPhpUnitMajorVersion() === 7) {
|
||||
$this->assertEquals($i, 33, '', $array->getNextSet($i));
|
||||
} else {
|
||||
$this->assertEqualsWithDelta($i, 33, $array->getNextSet($i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetNextSet2() : void
|
||||
{
|
||||
$array = new BitArray(33);
|
||||
|
||||
for ($i = 0; $i < $array->getSize(); ++$i) {
|
||||
if ($this->getPhpUnitMajorVersion() === 7) {
|
||||
$this->assertEquals($i, $i <= 31 ? 31 : 33, '', $array->getNextSet($i));
|
||||
} else {
|
||||
$this->assertEqualsWithDelta($i, $i <= 31 ? 31 : 33, $array->getNextSet($i));
|
||||
}
|
||||
}
|
||||
|
||||
$array = new BitArray(33);
|
||||
|
||||
for ($i = 0; $i < $array->getSize(); ++$i) {
|
||||
if ($this->getPhpUnitMajorVersion() === 7) {
|
||||
$this->assertEquals($i, 32, '', $array->getNextSet($i));
|
||||
} else {
|
||||
$this->assertEqualsWithDelta($i, 32, $array->getNextSet($i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetNextSet3() : void
|
||||
{
|
||||
$array = new BitArray(63);
|
||||
$array->set(31);
|
||||
$array->set(32);
|
||||
|
||||
for ($i = 0; $i < $array->getSize(); ++$i) {
|
||||
if ($i <= 31) {
|
||||
$expected = 31;
|
||||
} elseif ($i <= 32) {
|
||||
$expected = 32;
|
||||
} else {
|
||||
$expected = 63;
|
||||
}
|
||||
|
||||
if ($this->getPhpUnitMajorVersion() === 7) {
|
||||
$this->assertEquals($i, $expected, '', $array->getNextSet($i));
|
||||
} else {
|
||||
$this->assertEqualsWithDelta($i, $expected, $array->getNextSet($i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetNextSet4() : void
|
||||
{
|
||||
$array = new BitArray(63);
|
||||
$array->set(33);
|
||||
$array->set(40);
|
||||
|
||||
for ($i = 0; $i < $array->getSize(); ++$i) {
|
||||
if ($i <= 33) {
|
||||
$expected = 33;
|
||||
} elseif ($i <= 40) {
|
||||
$expected = 40;
|
||||
} else {
|
||||
$expected = 63;
|
||||
}
|
||||
|
||||
if ($this->getPhpUnitMajorVersion() === 7) {
|
||||
$this->assertEquals($i, $expected, '', $array->getNextSet($i));
|
||||
} else {
|
||||
$this->assertEqualsWithDelta($i, $expected, $array->getNextSet($i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetNextSet5() : void
|
||||
{
|
||||
mt_srand(0xdeadbeef, MT_RAND_PHP);
|
||||
|
||||
for ($i = 0; $i < 10; ++$i) {
|
||||
$array = new BitArray(mt_rand(1, 100));
|
||||
$numSet = mt_rand(0, 19);
|
||||
|
||||
for ($j = 0; $j < $numSet; ++$j) {
|
||||
$array->set(mt_rand(0, $array->getSize() - 1));
|
||||
}
|
||||
|
||||
$numQueries = mt_rand(0, 19);
|
||||
|
||||
for ($j = 0; $j < $numQueries; ++$j) {
|
||||
$query = mt_rand(0, $array->getSize() - 1);
|
||||
$expected = $query;
|
||||
|
||||
while ($expected < $array->getSize() && ! $array->get($expected)) {
|
||||
++$expected;
|
||||
}
|
||||
|
||||
$actual = $array->getNextSet($query);
|
||||
|
||||
if ($actual !== $expected) {
|
||||
$array->getNextSet($query);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testSetBulk() : void
|
||||
{
|
||||
$array = new BitArray(64);
|
||||
$array->setBulk(32, 0xFFFF0000);
|
||||
|
||||
for ($i = 0; $i < 48; ++$i) {
|
||||
$this->assertFalse($array->get($i));
|
||||
}
|
||||
|
||||
for ($i = 48; $i < 64; ++$i) {
|
||||
$this->assertTrue($array->get($i));
|
||||
}
|
||||
}
|
||||
|
||||
public function testClear() : void
|
||||
{
|
||||
$array = new BitArray(32);
|
||||
|
||||
for ($i = 0; $i < 32; ++$i) {
|
||||
$array->set($i);
|
||||
}
|
||||
|
||||
$array->clear();
|
||||
|
||||
for ($i = 0; $i < 32; ++$i) {
|
||||
$this->assertFalse($array->get($i));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetArray() : void
|
||||
{
|
||||
$array = new BitArray(64);
|
||||
$array->set(0);
|
||||
$array->set(63);
|
||||
|
||||
$ints = $array->getBitArray();
|
||||
|
||||
$this->assertSame(1, $ints[0]);
|
||||
$this->assertSame(0x80000000, $ints[1]);
|
||||
}
|
||||
|
||||
public function testIsRange() : void
|
||||
{
|
||||
$array = new BitArray(64);
|
||||
$this->assertTrue($array->isRange(0, 64, false));
|
||||
$this->assertFalse($array->isRange(0, 64, true));
|
||||
|
||||
$array->set(32);
|
||||
$this->assertTrue($array->isRange(32, 33, true));
|
||||
|
||||
$array->set(31);
|
||||
$this->assertTrue($array->isRange(31, 33, true));
|
||||
|
||||
$array->set(34);
|
||||
$this->assertFalse($array->isRange(31, 35, true));
|
||||
|
||||
for ($i = 0; $i < 31; ++$i) {
|
||||
$array->set($i);
|
||||
}
|
||||
|
||||
$this->assertTrue($array->isRange(0, 33, true));
|
||||
|
||||
for ($i = 33; $i < 64; ++$i) {
|
||||
$array->set($i);
|
||||
}
|
||||
|
||||
$this->assertTrue($array->isRange(0, 64, true));
|
||||
$this->assertFalse($array->isRange(0, 64, false));
|
||||
}
|
||||
}
|
||||
115
vendor/bacon/bacon-qr-code/test/Common/BitMatrixTest.php
vendored
Normal file
115
vendor/bacon/bacon-qr-code/test/Common/BitMatrixTest.php
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCodeTest\Common;
|
||||
|
||||
use BaconQrCode\Common\BitArray;
|
||||
use BaconQrCode\Common\BitMatrix;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BitMatrixTest extends TestCase
|
||||
{
|
||||
public function testGetSet() : void
|
||||
{
|
||||
$matrix = new BitMatrix(33);
|
||||
$this->assertEquals(33, $matrix->getHeight());
|
||||
|
||||
for ($y = 0; $y < 33; ++$y) {
|
||||
for ($x = 0; $x < 33; ++$x) {
|
||||
if ($y * $x % 3 === 0) {
|
||||
$matrix->set($x, $y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($y = 0; $y < 33; $y++) {
|
||||
for ($x = 0; $x < 33; ++$x) {
|
||||
$this->assertSame(0 === $x * $y % 3, $matrix->get($x, $y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testSetRegion() : void
|
||||
{
|
||||
$matrix = new BitMatrix(5);
|
||||
$matrix->setRegion(1, 1, 3, 3);
|
||||
|
||||
for ($y = 0; $y < 5; ++$y) {
|
||||
for ($x = 0; $x < 5; ++$x) {
|
||||
$this->assertSame($y >= 1 && $y <= 3 && $x >= 1 && $x <= 3, $matrix->get($x, $y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testRectangularMatrix() : void
|
||||
{
|
||||
$matrix = new BitMatrix(75, 20);
|
||||
$this->assertSame(75, $matrix->getWidth());
|
||||
$this->assertSame(20, $matrix->getHeight());
|
||||
|
||||
$matrix->set(10, 0);
|
||||
$matrix->set(11, 1);
|
||||
$matrix->set(50, 2);
|
||||
$matrix->set(51, 3);
|
||||
$matrix->flip(74, 4);
|
||||
$matrix->flip(0, 5);
|
||||
|
||||
$this->assertTrue($matrix->get(10, 0));
|
||||
$this->assertTrue($matrix->get(11, 1));
|
||||
$this->assertTrue($matrix->get(50, 2));
|
||||
$this->assertTrue($matrix->get(51, 3));
|
||||
$this->assertTrue($matrix->get(74, 4));
|
||||
$this->assertTrue($matrix->get(0, 5));
|
||||
|
||||
$matrix->flip(50, 2);
|
||||
$matrix->flip(51, 3);
|
||||
|
||||
$this->assertFalse($matrix->get(50, 2));
|
||||
$this->assertFalse($matrix->get(51, 3));
|
||||
}
|
||||
|
||||
public function testRectangularSetRegion() : void
|
||||
{
|
||||
$matrix = new BitMatrix(320, 240);
|
||||
$this->assertSame(320, $matrix->getWidth());
|
||||
$this->assertSame(240, $matrix->getHeight());
|
||||
|
||||
$matrix->setRegion(105, 22, 80, 12);
|
||||
|
||||
for ($y = 0; $y < 240; ++$y) {
|
||||
for ($x = 0; $x < 320; ++$x) {
|
||||
$this->assertEquals($y >= 22 && $y < 34 && $x >= 105 && $x < 185, $matrix->get($x, $y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetRow() : void
|
||||
{
|
||||
$matrix = new BitMatrix(102, 5);
|
||||
|
||||
for ($x = 0; $x < 102; ++$x) {
|
||||
if (0 === ($x & 3)) {
|
||||
$matrix->set($x, 2);
|
||||
}
|
||||
}
|
||||
|
||||
$array1 = $matrix->getRow(2, null);
|
||||
$this->assertSame(102, $array1->getSize());
|
||||
|
||||
$array2 = new BitArray(60);
|
||||
$array2 = $matrix->getRow(2, $array2);
|
||||
$this->assertSame(102, $array2->getSize());
|
||||
|
||||
$array3 = new BitArray(200);
|
||||
$array3 = $matrix->getRow(2, $array3);
|
||||
$this->assertSame(200, $array3->getSize());
|
||||
|
||||
for ($x = 0; $x < 102; ++$x) {
|
||||
$on = (0 === ($x & 3));
|
||||
|
||||
$this->assertSame($on, $array1->get($x));
|
||||
$this->assertSame($on, $array2->get($x));
|
||||
$this->assertSame($on, $array3->get($x));
|
||||
}
|
||||
}
|
||||
}
|
||||
25
vendor/bacon/bacon-qr-code/test/Common/BitUtilsTest.php
vendored
Normal file
25
vendor/bacon/bacon-qr-code/test/Common/BitUtilsTest.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCodeTest\Common;
|
||||
|
||||
use BaconQrCode\Common\BitUtils;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BitUtilsTest extends TestCase
|
||||
{
|
||||
public function testUnsignedRightShift() : void
|
||||
{
|
||||
$this->assertSame(1, BitUtils::unsignedRightShift(1, 0));
|
||||
$this->assertSame(1, BitUtils::unsignedRightShift(10, 3));
|
||||
$this->assertSame(536870910, BitUtils::unsignedRightShift(-10, 3));
|
||||
}
|
||||
|
||||
public function testNumberOfTrailingZeros() : void
|
||||
{
|
||||
$this->assertSame(32, BitUtils::numberOfTrailingZeros(0));
|
||||
$this->assertSame(1, BitUtils::numberOfTrailingZeros(10));
|
||||
$this->assertSame(0, BitUtils::numberOfTrailingZeros(15));
|
||||
$this->assertSame(2, BitUtils::numberOfTrailingZeros(20));
|
||||
}
|
||||
}
|
||||
25
vendor/bacon/bacon-qr-code/test/Common/ErrorCorrectionLevelTest.php
vendored
Normal file
25
vendor/bacon/bacon-qr-code/test/Common/ErrorCorrectionLevelTest.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCodeTest\Common;
|
||||
|
||||
use BaconQrCode\Common\ErrorCorrectionLevel;
|
||||
use BaconQrCode\Exception\OutOfBoundsException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ErrorCorrectionLevelTest extends TestCase
|
||||
{
|
||||
public function testBitsMatchConstants() : void
|
||||
{
|
||||
$this->assertSame(0x0, ErrorCorrectionLevel::M()->getBits());
|
||||
$this->assertSame(0x1, ErrorCorrectionLevel::L()->getBits());
|
||||
$this->assertSame(0x2, ErrorCorrectionLevel::H()->getBits());
|
||||
$this->assertSame(0x3, ErrorCorrectionLevel::Q()->getBits());
|
||||
}
|
||||
|
||||
public function testInvalidErrorCorrectionLevelThrowsException() : void
|
||||
{
|
||||
$this->expectException(OutOfBoundsException::class);
|
||||
ErrorCorrectionLevel::forBits(4);
|
||||
}
|
||||
}
|
||||
94
vendor/bacon/bacon-qr-code/test/Common/FormatInformationTest.php
vendored
Normal file
94
vendor/bacon/bacon-qr-code/test/Common/FormatInformationTest.php
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCodeTest\Common;
|
||||
|
||||
use BaconQrCode\Common\ErrorCorrectionLevel;
|
||||
use BaconQrCode\Common\FormatInformation;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormatInformationTest extends TestCase
|
||||
{
|
||||
private const MASKED_TEST_FORMAT_INFO = 0x2bed;
|
||||
private const UNMAKSED_TEST_FORMAT_INFO = self::MASKED_TEST_FORMAT_INFO ^ 0x5412;
|
||||
|
||||
public function testBitsDiffering() : void
|
||||
{
|
||||
$this->assertSame(0, FormatInformation::numBitsDiffering(1, 1));
|
||||
$this->assertSame(1, FormatInformation::numBitsDiffering(0, 2));
|
||||
$this->assertSame(2, FormatInformation::numBitsDiffering(1, 2));
|
||||
$this->assertEquals(32, FormatInformation::numBitsDiffering(-1, 0));
|
||||
}
|
||||
|
||||
public function testDecode() : void
|
||||
{
|
||||
$expected = FormatInformation::decodeFormatInformation(
|
||||
self::MASKED_TEST_FORMAT_INFO,
|
||||
self::MASKED_TEST_FORMAT_INFO
|
||||
);
|
||||
|
||||
$this->assertNotNull($expected);
|
||||
$this->assertSame(7, $expected->getDataMask());
|
||||
$this->assertSame(ErrorCorrectionLevel::Q(), $expected->getErrorCorrectionLevel());
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
FormatInformation::decodeFormatInformation(
|
||||
self::UNMAKSED_TEST_FORMAT_INFO,
|
||||
self::MASKED_TEST_FORMAT_INFO
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testDecodeWithBitDifference() : void
|
||||
{
|
||||
$expected = FormatInformation::decodeFormatInformation(
|
||||
self::MASKED_TEST_FORMAT_INFO,
|
||||
self::MASKED_TEST_FORMAT_INFO
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
FormatInformation::decodeFormatInformation(
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0x1,
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0x1
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
FormatInformation::decodeFormatInformation(
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0x3,
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0x3
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
FormatInformation::decodeFormatInformation(
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0x7,
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0x7
|
||||
)
|
||||
);
|
||||
$this->assertNull(
|
||||
FormatInformation::decodeFormatInformation(
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0xf,
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0xf
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testDecodeWithMisRead() : void
|
||||
{
|
||||
$expected = FormatInformation::decodeFormatInformation(
|
||||
self::MASKED_TEST_FORMAT_INFO,
|
||||
self::MASKED_TEST_FORMAT_INFO
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
FormatInformation::decodeFormatInformation(
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0x3,
|
||||
self::MASKED_TEST_FORMAT_INFO ^ 0xf
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
19
vendor/bacon/bacon-qr-code/test/Common/ModeTest.php
vendored
Normal file
19
vendor/bacon/bacon-qr-code/test/Common/ModeTest.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCodeTest\Common;
|
||||
|
||||
use BaconQrCode\Common\Mode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ModeTest extends TestCase
|
||||
{
|
||||
public function testBitsMatchConstants() : void
|
||||
{
|
||||
$this->assertSame(0x0, Mode::TERMINATOR()->getBits());
|
||||
$this->assertSame(0x1, Mode::NUMERIC()->getBits());
|
||||
$this->assertSame(0x2, Mode::ALPHANUMERIC()->getBits());
|
||||
$this->assertSame(0x4, Mode::BYTE()->getBits());
|
||||
$this->assertSame(0x8, Mode::KANJI()->getBits());
|
||||
}
|
||||
}
|
||||
96
vendor/bacon/bacon-qr-code/test/Common/ReedSolomonCodecTest.php
vendored
Normal file
96
vendor/bacon/bacon-qr-code/test/Common/ReedSolomonCodecTest.php
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCodeTest\Common;
|
||||
|
||||
use BaconQrCode\Common\ReedSolomonCodec;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SplFixedArray;
|
||||
|
||||
class ReedSolomonTest extends TestCase
|
||||
{
|
||||
public function tabs() : array
|
||||
{
|
||||
return [
|
||||
[2, 0x7, 1, 1, 1],
|
||||
[3, 0xb, 1, 1, 2],
|
||||
[4, 0x13, 1, 1, 4],
|
||||
[5, 0x25, 1, 1, 6],
|
||||
[6, 0x43, 1, 1, 8],
|
||||
[7, 0x89, 1, 1, 10],
|
||||
[8, 0x11d, 1, 1, 32],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider tabs
|
||||
*/
|
||||
public function testCodec(int $symbolSize, int $generatorPoly, int $firstRoot, int $primitive, int $numRoots) : void
|
||||
{
|
||||
mt_srand(0xdeadbeef, MT_RAND_PHP);
|
||||
|
||||
$blockSize = (1 << $symbolSize) - 1;
|
||||
$dataSize = $blockSize - $numRoots;
|
||||
$codec = new ReedSolomonCodec($symbolSize, $generatorPoly, $firstRoot, $primitive, $numRoots, 0);
|
||||
|
||||
for ($errors = 0; $errors <= $numRoots / 2; ++$errors) {
|
||||
// Load block with random data and encode
|
||||
$block = SplFixedArray::fromArray(array_fill(0, $blockSize, 0), false);
|
||||
|
||||
for ($i = 0; $i < $dataSize; ++$i) {
|
||||
$block[$i] = mt_rand(0, $blockSize);
|
||||
}
|
||||
|
||||
// Make temporary copy
|
||||
$tBlock = clone $block;
|
||||
$parity = SplFixedArray::fromArray(array_fill(0, $numRoots, 0), false);
|
||||
$errorLocations = SplFixedArray::fromArray(array_fill(0, $blockSize, 0), false);
|
||||
$erasures = [];
|
||||
|
||||
// Create parity
|
||||
$codec->encode($block, $parity);
|
||||
|
||||
// Copy parity into test blocks
|
||||
for ($i = 0; $i < $numRoots; ++$i) {
|
||||
$block[$i + $dataSize] = $parity[$i];
|
||||
$tBlock[$i + $dataSize] = $parity[$i];
|
||||
}
|
||||
|
||||
// Seed with errors
|
||||
for ($i = 0; $i < $errors; ++$i) {
|
||||
$errorValue = mt_rand(1, $blockSize);
|
||||
|
||||
do {
|
||||
$errorLocation = mt_rand(0, $blockSize);
|
||||
} while (0 !== $errorLocations[$errorLocation]);
|
||||
|
||||
$errorLocations[$errorLocation] = 1;
|
||||
|
||||
if (mt_rand(0, 1)) {
|
||||
$erasures[] = $errorLocation;
|
||||
}
|
||||
|
||||
$tBlock[$errorLocation] ^= $errorValue;
|
||||
}
|
||||
|
||||
$erasures = SplFixedArray::fromArray($erasures, false);
|
||||
|
||||
// Decode the errored block
|
||||
$foundErrors = $codec->decode($tBlock, $erasures);
|
||||
|
||||
if ($errors > 0 && null === $foundErrors) {
|
||||
$this->assertSame($block, $tBlock, 'Decoder failed to correct errors');
|
||||
}
|
||||
|
||||
$this->assertSame($errors, $foundErrors, 'Found errors do not equal expected errors');
|
||||
|
||||
for ($i = 0; $i < $foundErrors; ++$i) {
|
||||
if (0 === $errorLocations[$erasures[$i]]) {
|
||||
$this->fail(sprintf('Decoder indicates error in location %d without error', $erasures[$i]));
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals($block, $tBlock, 'Decoder did not correct errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
78
vendor/bacon/bacon-qr-code/test/Common/VersionTest.php
vendored
Normal file
78
vendor/bacon/bacon-qr-code/test/Common/VersionTest.php
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace BaconQrCodeTest\Common;
|
||||
|
||||
use BaconQrCode\Common\ErrorCorrectionLevel;
|
||||
use BaconQrCode\Common\Version;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class VersionTest extends TestCase
|
||||
{
|
||||
public function versions() : array
|
||||
{
|
||||
$array = [];
|
||||
|
||||
for ($i = 1; $i <= 40; ++$i) {
|
||||
$array[] = [$i, 4 * $i + 17];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function decodeInformation() : array
|
||||
{
|
||||
return [
|
||||
[7, 0x07c94],
|
||||
[12, 0x0c762],
|
||||
[17, 0x1145d],
|
||||
[22, 0x168c9],
|
||||
[27, 0x1b08e],
|
||||
[32, 0x209d5],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider versions
|
||||
*/
|
||||
public function testVersionForNumber(int $versionNumber, int $dimension) : void
|
||||
{
|
||||
$version = Version::getVersionForNumber($versionNumber);
|
||||
|
||||
$this->assertNotNull($version);
|
||||
$this->assertEquals($versionNumber, $version->getVersionNumber());
|
||||
$this->assertNotNull($version->getAlignmentPatternCenters());
|
||||
|
||||
if ($versionNumber > 1) {
|
||||
$this->assertTrue(count($version->getAlignmentPatternCenters()) > 0);
|
||||
}
|
||||
|
||||
$this->assertEquals($dimension, $version->getDimensionForVersion());
|
||||
$this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::H()));
|
||||
$this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::L()));
|
||||
$this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::M()));
|
||||
$this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::Q()));
|
||||
$this->assertNotNull($version->buildFunctionPattern());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider versions
|
||||
*/
|
||||
public function testGetProvisionalVersionForDimension(int $versionNumber, int $dimension) : void
|
||||
{
|
||||
$this->assertSame(
|
||||
$versionNumber,
|
||||
Version::getProvisionalVersionForDimension($dimension)->getVersionNumber()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider decodeInformation
|
||||
*/
|
||||
public function testDecodeVersionInformation(int $expectedVersion, int $mask) : void
|
||||
{
|
||||
$version = Version::decodeVersionInformation($mask);
|
||||
$this->assertNotNull($version);
|
||||
$this->assertSame($expectedVersion, $version->getVersionNumber());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user