PhpiredisCRC16Test.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Cluster\Hash;
  11. use PredisTestCase;
  12. /**
  13. * @group ext-phpiredis
  14. * @requires extension phpiredis
  15. * @requires function phpiredis_utils_crc16
  16. */
  17. class PhpiredisCRC16Test extends PredisTestCase
  18. {
  19. /**
  20. * @group disconnected
  21. */
  22. public function testHashGeneration()
  23. {
  24. $crc16 = new PhpiredisCRC16();
  25. $this->assertSame(58359, $crc16->hash('key:000'));
  26. $this->assertSame(62422, $crc16->hash('key:001'));
  27. $this->assertSame(50101, $crc16->hash('key:002'));
  28. $this->assertSame(54164, $crc16->hash('key:003'));
  29. $this->assertSame(41843, $crc16->hash('key:004'));
  30. $this->assertSame(45906, $crc16->hash('key:005'));
  31. $this->assertSame(33585, $crc16->hash('key:006'));
  32. $this->assertSame(37648, $crc16->hash('key:007'));
  33. $this->assertSame(25343, $crc16->hash('key:008'));
  34. $this->assertSame(29406, $crc16->hash('key:009'));
  35. }
  36. /**
  37. * @group disconnected
  38. */
  39. public function testHashGenerationWithIntegerValues()
  40. {
  41. $crc16 = new PhpiredisCRC16();
  42. $this->assertSame(13907, $crc16->hash(0));
  43. $this->assertSame(55177, $crc16->hash(1234));
  44. }
  45. }