QRMatrixTest.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?php
  2. /**
  3. * Class QRMatrixTest
  4. *
  5. * @created 17.11.2017
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2017 Smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeTest\Data;
  11. use chillerlan\QRCode\{QRCode, QROptions};
  12. use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version};
  13. use chillerlan\QRCode\Data\{QRCodeDataException, QRMatrix};
  14. use chillerlan\QRCode\Output\{QROutputInterface, QRString};
  15. use PHPUnit\Framework\TestCase;
  16. use Generator;
  17. use function defined;
  18. /**
  19. * Tests the QRMatrix class
  20. */
  21. final class QRMatrixTest extends TestCase{
  22. private const version = 40;
  23. private QRMatrix $matrix;
  24. /**
  25. * invokes a QRMatrix object
  26. */
  27. protected function setUp():void{
  28. $this->matrix = new QRMatrix(
  29. new Version($this::version),
  30. new EccLevel(EccLevel::L)
  31. );
  32. }
  33. /**
  34. * Matrix debugging console output
  35. */
  36. public static function debugMatrix(QRMatrix $matrix):void{
  37. /** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */
  38. if(defined('TEST_IS_CI') && TEST_IS_CI === true){
  39. return;
  40. }
  41. $opt = new QROptions;
  42. $opt->outputType = QROutputInterface::STRING_TEXT;
  43. $opt->eol = "\n";
  44. $opt->moduleValues = [
  45. // finder
  46. QRMatrix::M_FINDER_DARK => QRString::ansi8('██', 124), // dark (true)
  47. QRMatrix::M_FINDER => QRString::ansi8('░░', 124), // light (false)
  48. QRMatrix::M_FINDER_DOT => QRString::ansi8('██', 124), // finder dot, dark (true)
  49. // alignment
  50. QRMatrix::M_ALIGNMENT_DARK => QRString::ansi8('██', 2),
  51. QRMatrix::M_ALIGNMENT => QRString::ansi8('░░', 2),
  52. // timing
  53. QRMatrix::M_TIMING_DARK => QRString::ansi8('██', 184),
  54. QRMatrix::M_TIMING => QRString::ansi8('░░', 184),
  55. // format
  56. QRMatrix::M_FORMAT_DARK => QRString::ansi8('██', 200),
  57. QRMatrix::M_FORMAT => QRString::ansi8('░░', 200),
  58. // version
  59. QRMatrix::M_VERSION_DARK => QRString::ansi8('██', 21),
  60. QRMatrix::M_VERSION => QRString::ansi8('░░', 21),
  61. // data
  62. QRMatrix::M_DATA_DARK => QRString::ansi8('██', 166),
  63. QRMatrix::M_DATA => QRString::ansi8('░░', 166),
  64. // dark module
  65. QRMatrix::M_DARKMODULE => QRString::ansi8('██', 53),
  66. // separator
  67. QRMatrix::M_SEPARATOR => QRString::ansi8('░░', 219),
  68. // quiet zone
  69. QRMatrix::M_QUIETZONE => QRString::ansi8('░░', 195),
  70. // logo space
  71. QRMatrix::M_LOGO => QRString::ansi8('░░', 105),
  72. // empty
  73. QRMatrix::M_NULL => QRString::ansi8('░░', 231),
  74. // data
  75. QRMatrix::M_TEST_DARK => QRString::ansi8('██', 127),
  76. QRMatrix::M_TEST => QRString::ansi8('░░', 127),
  77. ];
  78. $out = (new QRString($opt, $matrix))->dump();
  79. echo "\n\n".$out."\n\n";
  80. }
  81. /**
  82. * debugging shortcut - limit to a single version when using with matrixProvider
  83. *
  84. * @see QRMatrixTest::matrixProvider()
  85. */
  86. protected function dm(QRMatrix $matrix):void{
  87. // limit
  88. if($matrix->getVersion()->getVersionNumber() !== 7){
  89. return;
  90. }
  91. self::debugMatrix($matrix);
  92. }
  93. /**
  94. * Validates the QRMatrix instance
  95. */
  96. public function testInstance():void{
  97. $this::assertInstanceOf(QRMatrix::class, $this->matrix);
  98. }
  99. /**
  100. * Tests if size() returns the actual matrix size/count
  101. */
  102. public function testSize():void{
  103. $this::assertCount($this->matrix->getSize(), $this->matrix->getMatrix(true));
  104. }
  105. /**
  106. * Tests if version() returns the current (given) version
  107. */
  108. public function testVersion():void{
  109. $this::assertSame($this::version, $this->matrix->getVersion()->getVersionNumber());
  110. }
  111. /**
  112. * Tests if eccLevel() returns the current (given) ECC level
  113. */
  114. public function testECC():void{
  115. $this::assertSame(EccLevel::L, $this->matrix->getEccLevel()->getLevel());
  116. }
  117. /**
  118. * Tests if maskPattern() returns the current (or default) mask pattern
  119. */
  120. public function testMaskPattern():void{
  121. // set via matrix evaluation
  122. $matrix = (new QRCode)->addByteSegment('testdata')->getQRMatrix();
  123. $this::assertInstanceOf(MaskPattern::class, $matrix->getMaskPattern());
  124. $this::assertSame(MaskPattern::PATTERN_100, $matrix->getMaskPattern()->getPattern());
  125. }
  126. /**
  127. * Tests the set(), get() and check() methods
  128. */
  129. public function testGetSetCheck():void{
  130. $this->matrix->set(10, 10, true, QRMatrix::M_TEST);
  131. $this::assertSame(QRMatrix::M_TEST_DARK, $this->matrix->get(10, 10));
  132. $this::assertTrue($this->matrix->check(10, 10));
  133. $this->matrix->set(20, 20, false, QRMatrix::M_TEST);
  134. $this::assertSame(QRMatrix::M_TEST, $this->matrix->get(20, 20));
  135. $this::assertFalse($this->matrix->check(20, 20));
  136. // get proper results when using a *_DARK constant
  137. $this->matrix->set(30, 30, true, QRMatrix::M_TEST_DARK);
  138. $this::assertSame(QRMatrix::M_TEST_DARK, $this->matrix->get(30, 30));
  139. $this->matrix->set(40, 40, false, QRMatrix::M_TEST_DARK);
  140. $this::assertSame(QRMatrix::M_TEST, $this->matrix->get(40, 40));
  141. // out of range
  142. $this::assertFalse($this->matrix->check(-1, -1));
  143. $this::assertSame(-1, $this->matrix->get(-1, -1));
  144. }
  145. /**
  146. * Version data provider for several pattern tests
  147. */
  148. public static function matrixProvider():Generator{
  149. $ecc = new EccLevel(EccLevel::L);
  150. for($i = 1; $i <= 40; $i++){
  151. yield 'version: '.$i => [new QRMatrix(new Version($i), $ecc)];
  152. }
  153. }
  154. /**
  155. * Tests setting the dark module and verifies its position
  156. *
  157. * @dataProvider matrixProvider
  158. */
  159. public function testSetDarkModule(QRMatrix $matrix):void{
  160. $matrix->setDarkModule();
  161. $this->dm($matrix);
  162. $this::assertSame(QRMatrix::M_DARKMODULE, $matrix->get(8, ($matrix->getSize() - 8)));
  163. }
  164. /**
  165. * Tests setting the finder patterns and verifies their positions
  166. *
  167. * @dataProvider matrixProvider
  168. */
  169. public function testSetFinderPattern(QRMatrix $matrix):void{
  170. $matrix->setFinderPattern();
  171. $this->dm($matrix);
  172. $this::assertSame(QRMatrix::M_FINDER_DARK, $matrix->get(0, 0));
  173. $this::assertSame(QRMatrix::M_FINDER_DARK, $matrix->get(0, ($matrix->getSize() - 1)));
  174. $this::assertSame(QRMatrix::M_FINDER_DARK, $matrix->get(($matrix->getSize() - 1), 0));
  175. }
  176. /**
  177. * Tests the separator patterns and verifies their positions
  178. *
  179. * @dataProvider matrixProvider
  180. */
  181. public function testSetSeparators(QRMatrix $matrix):void{
  182. $matrix->setSeparators();
  183. $this->dm($matrix);
  184. $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(7, 0));
  185. $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(0, 7));
  186. $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(0, ($matrix->getSize() - 8)));
  187. $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(($matrix->getSize() - 8), 0));
  188. }
  189. /**
  190. * Tests the alignment patterns and verifies their positions - version 1 (no pattern) skipped
  191. *
  192. * @dataProvider matrixProvider
  193. */
  194. public function testSetAlignmentPattern(QRMatrix $matrix):void{
  195. $version = $matrix->getVersion();
  196. if($version->getVersionNumber() === 1){
  197. /** @noinspection PhpUnitTestFailedLineInspection */
  198. $this::markTestSkipped('N/A (Version 1 has no alignment pattern)');
  199. }
  200. $matrix
  201. ->setFinderPattern()
  202. ->setAlignmentPattern()
  203. ;
  204. $this->dm($matrix);
  205. $alignmentPattern = $version->getAlignmentPattern();
  206. foreach($alignmentPattern as $py){
  207. foreach($alignmentPattern as $px){
  208. // skip finder pattern
  209. if(!$matrix->checkTypeIn($px, $py, [QRMatrix::M_FINDER, QRMatrix::M_FINDER_DOT])){
  210. $this::assertSame(QRMatrix::M_ALIGNMENT_DARK, $matrix->get($px, $py));
  211. }
  212. }
  213. }
  214. }
  215. /**
  216. * Tests the timing patterns and verifies their positions
  217. *
  218. * @dataProvider matrixProvider
  219. */
  220. public function testSetTimingPattern(QRMatrix $matrix):void{
  221. $matrix
  222. ->setFinderPattern()
  223. ->setAlignmentPattern()
  224. ->setTimingPattern()
  225. ;
  226. $this->dm($matrix);
  227. $size = $matrix->getSize();
  228. for($i = 7; $i < ($size - 7); $i++){
  229. if(($i % 2) === 0){
  230. // skip alignment pattern
  231. if(!$matrix->checkTypeIn(6, $i, [QRMatrix::M_ALIGNMENT])){
  232. $this::assertSame(QRMatrix::M_TIMING_DARK, $matrix->get(6, $i));
  233. $this::assertSame(QRMatrix::M_TIMING_DARK, $matrix->get($i, 6));
  234. }
  235. }
  236. }
  237. }
  238. /**
  239. * Tests the version patterns and verifies their positions - version < 7 skipped
  240. *
  241. * @dataProvider matrixProvider
  242. */
  243. public function testSetVersionNumber(QRMatrix $matrix):void{
  244. if($matrix->getVersion()->getVersionNumber() < 7){
  245. /** @noinspection PhpUnitTestFailedLineInspection */
  246. $this::markTestSkipped('N/A (Version < 7)');
  247. }
  248. $matrix->setVersionNumber();
  249. $this->dm($matrix);
  250. $this::assertTrue($matrix->checkType(($matrix->getSize() - 9), 0, QRMatrix::M_VERSION));
  251. $this::assertTrue($matrix->checkType(($matrix->getSize() - 11), 5, QRMatrix::M_VERSION));
  252. $this::assertTrue($matrix->checkType(0, ($matrix->getSize() - 9), QRMatrix::M_VERSION));
  253. $this::assertTrue($matrix->checkType(5, ($matrix->getSize() - 11), QRMatrix::M_VERSION));
  254. }
  255. /**
  256. * Tests the format patterns and verifies their positions
  257. *
  258. * @dataProvider matrixProvider
  259. */
  260. public function testSetFormatInfo(QRMatrix $matrix):void{
  261. $matrix->setFormatInfo(new MaskPattern(MaskPattern::PATTERN_000));
  262. $this->dm($matrix);
  263. $this::assertTrue($matrix->checkType(8, 0, QRMatrix::M_FORMAT));
  264. $this::assertTrue($matrix->checkType(0, 8, QRMatrix::M_FORMAT));
  265. $this::assertTrue($matrix->checkType(($matrix->getSize() - 1), 8, QRMatrix::M_FORMAT));
  266. $this::assertTrue($matrix->checkType(($matrix->getSize() - 8), 8, QRMatrix::M_FORMAT));
  267. }
  268. /**
  269. * Tests the quiet zone pattern and verifies its position
  270. *
  271. * @dataProvider matrixProvider
  272. */
  273. public function testSetQuietZone(QRMatrix $matrix):void{
  274. $size = $matrix->getSize();
  275. $quietZoneSize = 5;
  276. $matrix->set(0, 0, true, QRMatrix::M_TEST);
  277. $matrix->set(($size - 1), ($size - 1), true, QRMatrix::M_TEST);
  278. $matrix->setQuietZone($quietZoneSize);
  279. $s = ($size + 2 * $quietZoneSize);
  280. $this::assertCount($s, $matrix->getMatrix(true));
  281. $this::assertCount($s, $matrix->getMatrix(true)[($size - 1)]);
  282. $size = $matrix->getSize();
  283. $this->dm($matrix);
  284. $this::assertTrue($matrix->checkType(0, 0, QRMatrix::M_QUIETZONE));
  285. $this::assertTrue($matrix->checkType(($size - 1), ($size - 1), QRMatrix::M_QUIETZONE));
  286. $s = ($size - 1 - $quietZoneSize);
  287. $this::assertSame(QRMatrix::M_TEST_DARK, $matrix->get($quietZoneSize, $quietZoneSize));
  288. $this::assertSame(QRMatrix::M_TEST_DARK, $matrix->get($s, $s));
  289. }
  290. /**
  291. * Tests if an exception is thrown in an attempt to create the quiet zone before data was written
  292. */
  293. public function testSetQuietZoneException():void{
  294. $this->expectException(QRCodeDataException::class);
  295. $this->expectExceptionMessage('use only after writing data');
  296. $this->matrix->setQuietZone(42);
  297. }
  298. /**
  299. * Tests rotating the matrix by 90 degrees CW
  300. *
  301. * @dataProvider matrixProvider
  302. */
  303. public function testRotate90(QRMatrix $matrix):void{
  304. $matrix->initFunctionalPatterns();
  305. // matrix size
  306. $size = $matrix->getSize();
  307. // quiet zone size
  308. $qz = (($size - $matrix->getVersion()->getDimension()) / 2);
  309. // initial dark module position
  310. $this::assertSame(QRMatrix::M_DARKMODULE, $matrix->get((8 + $qz), ($size - 8 - $qz)));
  311. // first rotation
  312. $matrix->rotate90();
  313. $this->dm($matrix);
  314. $this::assertSame(QRMatrix::M_DARKMODULE, $matrix->get((7 + $qz), (8 + $qz)));
  315. // second rotation
  316. $matrix->rotate90();
  317. $this->dm($matrix);
  318. $this::assertSame(QRMatrix::M_DARKMODULE, $matrix->get(($size - 9 - $qz), (7 + $qz)));
  319. // third rotation
  320. $matrix->rotate90();
  321. $this->dm($matrix);
  322. $this::assertSame(QRMatrix::M_DARKMODULE, $matrix->get(($size - 8 - $qz), ($size - 9 - $qz)));
  323. // fourth rotation
  324. $matrix->rotate90();
  325. $this->dm($matrix);
  326. $this::assertSame(QRMatrix::M_DARKMODULE, $matrix->get((8 + $qz), ($size - 8 - $qz)));
  327. }
  328. /**
  329. * Tests if the logo space is drawn square if one of the dimensions is omitted
  330. */
  331. public function testSetLogoSpaceOmitHeight():void{
  332. $o = new QROptions;
  333. $o->version = 2;
  334. $o->eccLevel = EccLevel::H;
  335. $o->addQuietzone = false;
  336. $o->addLogoSpace = true;
  337. $o->logoSpaceHeight = 5;
  338. $matrix = (new QRCode($o))->addByteSegment('testdata')->getQRMatrix();
  339. self::debugMatrix($matrix);
  340. $this::assertFalse($matrix->checkType(9, 9, QRMatrix::M_LOGO));
  341. $this::assertTrue($matrix->checkType(10, 10, QRMatrix::M_LOGO));
  342. $this::assertTrue($matrix->checkType(14, 14, QRMatrix::M_LOGO));
  343. $this::assertFalse($matrix->checkType(15, 15, QRMatrix::M_LOGO));
  344. }
  345. /**
  346. * Tests the auto orientation of the logo space
  347. */
  348. public function testSetLogoSpaceOrientation():void{
  349. $o = new QROptions;
  350. $o->version = 10;
  351. $o->eccLevel = EccLevel::H;
  352. $o->addQuietzone = false;
  353. $matrix = (new QRCode($o))->addByteSegment('testdata')->getQRMatrix();
  354. // also testing size adjustment to uneven numbers
  355. $matrix->setLogoSpace(20, 14);
  356. self::debugMatrix($matrix);
  357. // NW corner
  358. $this::assertFalse($matrix->checkType(17, 20, QRMatrix::M_LOGO));
  359. $this::assertTrue($matrix->checkType(18, 21, QRMatrix::M_LOGO));
  360. // SE corner
  361. $this::assertTrue($matrix->checkType(38, 35, QRMatrix::M_LOGO));
  362. $this::assertFalse($matrix->checkType(39, 36, QRMatrix::M_LOGO));
  363. }
  364. /**
  365. * Tests the manual positioning of the logo space
  366. */
  367. public function testSetLogoSpacePosition():void{
  368. $o = new QROptions;
  369. $o->version = 10;
  370. $o->eccLevel = EccLevel::H;
  371. $o->addQuietzone = true;
  372. $o->quietzoneSize = 10;
  373. $matrix = (new QRCode($o))->addByteSegment('testdata')->getQRMatrix();
  374. self::debugMatrix($matrix);
  375. // logo space should not overwrite quiet zone & function patterns
  376. $matrix->setLogoSpace(21, 21, -10, -10);
  377. $this::assertSame(QRMatrix::M_QUIETZONE, $matrix->get(9, 9));
  378. $this::assertSame(QRMatrix::M_FINDER_DARK, $matrix->get(10, 10));
  379. $this::assertSame(QRMatrix::M_FINDER_DARK, $matrix->get(16, 16));
  380. $this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(17, 17));
  381. $this::assertSame(QRMatrix::M_FORMAT_DARK, $matrix->get(18, 18));
  382. $this::assertSame(QRMatrix::M_LOGO, $matrix->get(19, 19));
  383. $this::assertSame(QRMatrix::M_LOGO, $matrix->get(20, 20));
  384. $this::assertNotSame(QRMatrix::M_LOGO, $matrix->get(21, 21));
  385. // Ii just realized that setLogoSpace() could be called multiple times
  386. // on the same instance, and I'm not going to do anything about it :P
  387. $matrix->setLogoSpace(21, 21, 45, 45);
  388. $this::assertNotSame(QRMatrix::M_LOGO, $matrix->get(54, 54));
  389. $this::assertSame(QRMatrix::M_LOGO, $matrix->get(55, 55));
  390. $this::assertSame(QRMatrix::M_QUIETZONE, $matrix->get(67, 67));
  391. }
  392. /**
  393. * Tests whether an exception is thrown when an ECC level other than "H" is set when attempting to add logo space
  394. */
  395. public function testSetLogoSpaceInvalidEccException():void{
  396. $this->expectException(QRCodeDataException::class);
  397. $this->expectExceptionMessage('ECC level "H" required to add logo space');
  398. (new QRCode)->addByteSegment('testdata')->getQRMatrix()->setLogoSpace(50, 50);
  399. }
  400. /**
  401. * Tests whether an exception is thrown when width or height exceed the matrix size
  402. */
  403. public function testSetLogoSpaceExceedsException():void{
  404. $this->expectException(QRCodeDataException::class);
  405. $this->expectExceptionMessage('logo dimensions exceed matrix size');
  406. $o = new QROptions;
  407. $o->version = 5;
  408. $o->eccLevel = EccLevel::H;
  409. (new QRCode($o))->addByteSegment('testdata')->getQRMatrix()->setLogoSpace(69, 1);
  410. }
  411. /**
  412. * Tests whether an exception is thrown when the logo space size exceeds the maximum ECC capacity
  413. */
  414. public function testSetLogoSpaceMaxSizeException():void{
  415. $this->expectException(QRCodeDataException::class);
  416. $this->expectExceptionMessage('logo space exceeds the maximum error correction capacity');
  417. $o = new QROptions;
  418. $o->version = 5;
  419. $o->eccLevel = EccLevel::H;
  420. (new QRCode($o))->addByteSegment('testdata')->getQRMatrix()->setLogoSpace(37, 37);
  421. }
  422. /**
  423. * Tests flipping the value of a module
  424. */
  425. public function testFlip():void{
  426. $this->matrix->set(20, 20, true, QRMatrix::M_TEST);
  427. // cover checkType()
  428. $this::assertTrue($this->matrix->checkType(20, 20, QRMatrix::M_TEST));
  429. // verify the current state (dark)
  430. $this::assertSame(QRMatrix::M_TEST_DARK, $this->matrix->get(20, 20));
  431. // flip
  432. $this->matrix->flip(20, 20);
  433. // verify flip
  434. $this::assertSame(QRMatrix::M_TEST, $this->matrix->get(20, 20));
  435. // flip again
  436. $this->matrix->flip(20, 20);
  437. // verify flip
  438. $this::assertSame(QRMatrix::M_TEST_DARK, $this->matrix->get(20, 20));
  439. }
  440. /**
  441. * Tests checking whether the M_TYPE of a module is not one of an array of M_TYPES
  442. */
  443. public function testCheckTypeIn():void{
  444. $this->matrix->set(10, 10, true, QRMatrix::M_QUIETZONE);
  445. $this::assertFalse($this->matrix->checkTypeIn(10, 10, [QRMatrix::M_DATA, QRMatrix::M_FINDER]));
  446. $this::assertTrue($this->matrix->checkTypeIn(10, 10, [QRMatrix::M_QUIETZONE, QRMatrix::M_FINDER]));
  447. }
  448. /**
  449. * Tests checking the adjacent modules
  450. */
  451. public function testCheckNeighbours():void{
  452. $this->matrix
  453. ->setFinderPattern()
  454. ->setAlignmentPattern()
  455. ;
  456. /*
  457. * center of finder pattern (surrounded by all dark)
  458. *
  459. * # # # # # # #
  460. * # #
  461. * # # # # #
  462. * # # 0 # #
  463. * # # # # #
  464. * # #
  465. * # # # # # # #
  466. */
  467. $this::assertSame(0b11111111, $this->matrix->checkNeighbours(3, 3));
  468. /*
  469. * center of alignment pattern (surrounded by all light)
  470. *
  471. * # # # # #
  472. * # #
  473. * # 0 #
  474. * # #
  475. * # # # # #
  476. */
  477. $this::assertSame(0b00000000, $this->matrix->checkNeighbours(30, 30));
  478. /*
  479. * top left light block of finder pattern
  480. *
  481. * # # #
  482. * # 0
  483. * # #
  484. */
  485. $this::assertSame(0b11010111, $this->matrix->checkNeighbours(1, 1));
  486. /*
  487. * bottom left light block of finder pattern
  488. *
  489. * # #
  490. * # 0
  491. * # # #
  492. */
  493. $this::assertSame(0b11110101, $this->matrix->checkNeighbours(1, 5));
  494. /*
  495. * top right light block of finder pattern
  496. *
  497. * # # #
  498. * 0 #
  499. * # #
  500. */
  501. $this::assertSame(0b01011111, $this->matrix->checkNeighbours(5, 1));
  502. /*
  503. * bottom right light block of finder pattern
  504. *
  505. * # #
  506. * 0 #
  507. * # # #
  508. */
  509. $this::assertSame(0b01111101, $this->matrix->checkNeighbours(5, 5));
  510. /*
  511. * M_TYPE check
  512. *
  513. * # # #
  514. * 0
  515. * X X X
  516. */
  517. $this::assertSame(0b00000111, $this->matrix->checkNeighbours(3, 1, QRMatrix::M_FINDER));
  518. $this::assertSame(0b01110000, $this->matrix->checkNeighbours(3, 1, QRMatrix::M_FINDER_DOT));
  519. }
  520. }