BitBufferTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Class BitBufferTest
  4. *
  5. * @filesource BitBufferTest.php
  6. * @created 08.02.2016
  7. * @package chillerlan\QRCodeTest\Common
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2015 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest\Common;
  13. use chillerlan\QRCode\Common\{BitBuffer, Mode};
  14. use PHPUnit\Framework\TestCase;
  15. /**
  16. * BitBuffer coverage test
  17. */
  18. final class BitBufferTest extends TestCase{
  19. protected BitBuffer $bitBuffer;
  20. protected function setUp():void{
  21. $this->bitBuffer = new BitBuffer;
  22. }
  23. public function bitProvider():array{
  24. return [
  25. 'number' => [Mode::DATA_NUMBER, 16],
  26. 'alphanum' => [Mode::DATA_ALPHANUM, 32],
  27. 'byte' => [Mode::DATA_BYTE, 64],
  28. 'kanji' => [Mode::DATA_KANJI, 128],
  29. ];
  30. }
  31. /**
  32. * @dataProvider bitProvider
  33. */
  34. public function testPut(int $data, int $value):void{
  35. $this->bitBuffer->put($data, 4);
  36. $this::assertSame($value, $this->bitBuffer->getBuffer()[0]);
  37. $this::assertSame(4, $this->bitBuffer->getLength());
  38. }
  39. public function testClear():void{
  40. $this->bitBuffer->clear();
  41. $this::assertSame([], $this->bitBuffer->getBuffer());
  42. $this::assertSame(0, $this->bitBuffer->getLength());
  43. }
  44. }