XxHash32Test.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Nichlas Severinsen
  4. * @license https://opensource.org/licenses/BSD-2-Clause
  5. */
  6. use Necklace\XxHash\XxHash32;
  7. use PHPUnit\Framework\TestCase;
  8. final class XxHash32Test extends TestCase
  9. {
  10. private $x;
  11. protected function setUp(): void
  12. {
  13. $this->x = new XxHash32;
  14. }
  15. protected function teardown(): void
  16. {
  17. unset($this->x);
  18. }
  19. public function testHash(): void
  20. {
  21. $this->assertEquals('3e2023cf', $this->x->hash('test'));
  22. }
  23. public function testHashWithSeed(): void
  24. {
  25. $this->assertEquals('f782311e', $this->x->hash('test', 1));
  26. $this->assertEquals('6e111138', $this->x->hash('test', 10));
  27. $this->assertEquals('9bc28b61', $this->x->hash('test', 100));
  28. }
  29. public function testReset(): void
  30. {
  31. $this->assertEquals(true, $this->x->reset());
  32. }
  33. public function testUpdateAndDigest(): void
  34. {
  35. $this->assertEquals(true, $this->x->update('te'));
  36. $this->assertEquals(true, $this->x->update('st'));
  37. $this->assertEquals('3e2023cf', $this->x->digest());
  38. }
  39. public function testResetWithSeed(): void
  40. {
  41. $this->assertEquals(true, $this->x->reset(1));
  42. $this->assertEquals(true, $this->x->update('te'));
  43. $this->assertEquals(true, $this->x->update('st'));
  44. $this->assertEquals('f782311e', $this->x->digest());
  45. $this->assertEquals(true, $this->x->reset(10));
  46. $this->assertEquals(true, $this->x->update('te'));
  47. $this->assertEquals(true, $this->x->update('st'));
  48. $this->assertEquals('6e111138', $this->x->digest());
  49. $this->assertEquals(true, $this->x->reset(100));
  50. $this->assertEquals(true, $this->x->update('te'));
  51. $this->assertEquals(true, $this->x->update('st'));
  52. $this->assertEquals('9bc28b61', $this->x->digest());
  53. }
  54. public function testHashFile(): void
  55. {
  56. $this->assertEquals('1dd21d01', $this->x->hashFile(__DIR__ . '/bootstrap.php'));
  57. }
  58. public function testHashFileWithSeed(): void
  59. {
  60. $this->assertEquals('0b3eb334', $this->x->hashFile(__DIR__ . '/bootstrap.php', 1));
  61. }
  62. }