XxHash64Test.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Nichlas Severinsen
  4. * @license https://opensource.org/licenses/BSD-2-Clause
  5. */
  6. use Necklace\XxHash\XxHash64;
  7. use PHPUnit\Framework\TestCase;
  8. final class XxHash64Test extends TestCase
  9. {
  10. private $x;
  11. protected function setUp(): void
  12. {
  13. $this->x = new XxHash64;
  14. }
  15. protected function teardown(): void
  16. {
  17. unset($this->x);
  18. }
  19. public function testHash(): void
  20. {
  21. $this->assertEquals('4fdcca5ddb678139', $this->x->hash('test'));
  22. }
  23. public function testHashWithSeed(): void
  24. {
  25. $this->assertEquals('99ebbf9ba48f4c5d', $this->x->hash('test', 1));
  26. $this->assertEquals('52afb6bd010e4676', $this->x->hash('test', 10));
  27. $this->assertEquals('69f66fd0f32510c2', $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('4fdcca5ddb678139', $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('99ebbf9ba48f4c5d', $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('52afb6bd010e4676', $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('69f66fd0f32510c2', $this->x->digest());
  53. }
  54. public function testHashFile(): void
  55. {
  56. $this->assertEquals('cee0f97cde3a4cda', $this->x->hashFile(__DIR__ . '/bootstrap.php'));
  57. }
  58. public function testHashFileWithSeed(): void
  59. {
  60. $this->assertEquals('ce66936562b66421', $this->x->hashFile(__DIR__ . '/bootstrap.php', 1));
  61. }
  62. }