IntegerFormatterTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Test\Unit;
  3. use Test\TestCase;
  4. use Web3\Formatters\IntegerFormatter;
  5. class IntegerFormatterTest extends TestCase
  6. {
  7. /**
  8. * formatter
  9. *
  10. * @var \Web3\Formatters\IntegerFormatter
  11. */
  12. protected $formatter;
  13. /**
  14. * setUp
  15. *
  16. * @return void
  17. */
  18. public function setUp()
  19. {
  20. parent::setUp();
  21. $this->formatter = new IntegerFormatter;
  22. }
  23. /**
  24. * testFormat
  25. *
  26. * @return void
  27. */
  28. public function testFormat()
  29. {
  30. $formatter = $this->formatter;
  31. $hex = $formatter->format('1');
  32. $this->assertEquals($hex, implode('', array_fill(0, 63, '0')) . '1');
  33. $hex = $formatter->format('-1');
  34. $this->assertEquals($hex, implode('', array_fill(0, 64, 'f')));
  35. $hex = $formatter->format('ae');
  36. $this->assertEquals($hex, implode('', array_fill(0, 62, '0')) . 'ae');
  37. $hex = $formatter->format('1', 20);
  38. $this->assertEquals($hex, implode('', array_fill(0, 19, '0')) . '1');
  39. $hex = $formatter->format(48);
  40. $this->assertEquals($hex, implode('', array_fill(0, 62, '0')) . '30');
  41. $hex = $formatter->format('48');
  42. $this->assertEquals($hex, implode('', array_fill(0, 62, '0')) . '30');
  43. }
  44. }