|
30 | 30 | /** |
31 | 31 | * Test for {@link MurmurHash3}. |
32 | 32 | */ |
| 33 | +@SuppressWarnings("deprecation") |
33 | 34 | public class MurmurHash3Test { |
34 | 35 |
|
35 | 36 | /** Test data for the hash64 method. */ |
@@ -613,6 +614,114 @@ public void testHash128String() { |
613 | 614 | } |
614 | 615 | } |
615 | 616 |
|
| 617 | + /** |
| 618 | + * Test the {@link MurmurHash3#hash128x64(byte[])} algorithm. |
| 619 | + * |
| 620 | + * <p>Reference data is taken from the Python library {@code mmh3}.</p> |
| 621 | + * |
| 622 | + * @see <a href="https://pypi.org/project/mmh3/">mmh3</a> |
| 623 | + */ |
| 624 | + @Test |
| 625 | + public void testHash128x64() { |
| 626 | + // Note: Default seed is zero. |
| 627 | + |
| 628 | + // mmh3.hash64(bytes, 0) |
| 629 | + Assert.assertArrayEquals(new long[] {1972113670104592209L, 5171809317673151911L}, |
| 630 | + MurmurHash3.hash128x64(RANDOM_BYTES)); |
| 631 | + |
| 632 | + // Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to |
| 633 | + // 15 bytes remaining. |
| 634 | + // for x in range(0, 32): |
| 635 | + // print(mmh3.hash64(bytes[:x], 0), ',') |
| 636 | + final long[][] answers = {{0L, 0L}, {-2808653841080383123L, -2531784594030660343L}, |
| 637 | + {-1284575471001240306L, -8226941173794461820L}, {1645529003294647142L, 4109127559758330427L}, |
| 638 | + {-4117979116203940765L, -8362902660322042742L}, {2559943399590596158L, 4738005461125350075L}, |
| 639 | + {-1651760031591552651L, -5386079254924224461L}, {-6208043960690815609L, 7862371518025305074L}, |
| 640 | + {-5150023478423646337L, 8346305334874564507L}, {7658274117911906792L, -4962914659382404165L}, |
| 641 | + {1309458104226302269L, 570003296096149119L}, {7440169453173347487L, -3489345781066813740L}, |
| 642 | + {-5698784298612201352L, 3595618450161835420L}, {-3822574792738072442L, 6878153771369862041L}, |
| 643 | + {3705084673301918328L, 3202155281274291907L}, {-6797166743928506931L, -4447271093653551597L}, |
| 644 | + {5240533565589385084L, -5575481185288758327L}, {-8467620131382649428L, -6450630367251114468L}, |
| 645 | + {3632866961828686471L, -5957695976089313500L}, {-6450283648077271139L, -7908632714374518059L}, |
| 646 | + {226350826556351719L, 8225586794606475685L}, {-2382996224496980401L, 2188369078123678011L}, |
| 647 | + {-1337544762358780825L, 7004253486151757299L}, {2889033453638709716L, -4099509333153901374L}, |
| 648 | + {-8644950936809596954L, -5144522919639618331L}, {-5628571865255520773L, -839021001655132087L}, |
| 649 | + {-5226774667293212446L, -505255961194269502L}, {1337107025517938142L, 3260952073019398505L}, |
| 650 | + {9149852874328582511L, 1880188360994521535L}, {-4035957988359881846L, -7709057850766490780L}, |
| 651 | + {-3842593823306330815L, 3805147088291453755L}, {4030161393619149616L, -2813603781312455238L},}; |
| 652 | + for (int i = 0; i < answers.length; i++) { |
| 653 | + final byte[] bytes = Arrays.copyOf(RANDOM_BYTES, i); |
| 654 | + Assert.assertArrayEquals(answers[i], MurmurHash3.hash128x64(bytes)); |
| 655 | + } |
| 656 | + } |
| 657 | + |
| 658 | + /** |
| 659 | + * Test the {@link MurmurHash3#hash128x64(byte[], int, int, int)} algorithm. |
| 660 | + * |
| 661 | + * <p>Reference data is taken from the Python library {@code mmh3}.</p> |
| 662 | + * |
| 663 | + * @see <a href="https://pypi.org/project/mmh3/">mmh3</a> |
| 664 | + */ |
| 665 | + @Test |
| 666 | + public void testHash128x64WithOffsetLengthAndSeed() { |
| 667 | + // Seed can be positive |
| 668 | + final int seed = 42; |
| 669 | + final int offset = 13; |
| 670 | + |
| 671 | + // Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to |
| 672 | + // 15 bytes remaining. |
| 673 | + // for x in range(0, 32): |
| 674 | + // print(mmh3.hash64(bytes[13:x+13], 42), ',') |
| 675 | + final long[][] answers = {{-1140915396076141277L, -3386313222241793095L}, |
| 676 | + {2745805417334040752L, -3045882272665292331L}, {6807939080212835946L, -1975749467247671127L}, |
| 677 | + {-7924884987449335214L, -4468571497642087939L}, {3005389733967167773L, -5809440073240597398L}, |
| 678 | + {8032745196600164727L, 4545709434702374224L}, {2095398623732573832L, 1778447136435513908L}, |
| 679 | + {4492723708121417255L, -7411125500882394867L}, {8467397417110552178L, -1503802302645548949L}, |
| 680 | + {4189760269121918355L, -8004336343217265057L}, {4939298084211301953L, -8419135013628844658L}, |
| 681 | + {5497136916151148085L, -394028342910298191L}, {3405983294878231737L, -3216533807498089078L}, |
| 682 | + {5833223403351466775L, -1792451370239813325L}, {7730583391236194819L, 5356157313842354092L}, |
| 683 | + {3111977482488580945L, -3119414725698132191L}, {3314524606404365027L, -1923219843083192742L}, |
| 684 | + {7299569240140613949L, 4176392429810027494L}, {6398084683727166117L, 7703960505857395788L}, |
| 685 | + {-8594572031068184774L, 4394224719145783692L}, {-7589785442804461713L, 4110439243215224554L}, |
| 686 | + {-5343610105946840628L, -4423992782020122809L}, {-522490326525787270L, 289136460641968781L}, |
| 687 | + {-5320637070354802556L, -7845553044730489027L}, {1344456408744313334L, 3803048032054968586L}, |
| 688 | + {1131205296221907191L, -6256656049039287019L}, {8583339267101027117L, 8934225022848628726L}, |
| 689 | + {-6379552869905441749L, 8973517768420051734L}, {5076646564516328801L, 8561479196844000567L}, |
| 690 | + {-4610341636137642517L, -6694266039505142069L}, {-758896383254029789L, 4050360662271552727L}, |
| 691 | + {-6123628195475753507L, 4283875822581966645L},}; |
| 692 | + for (int i = 0; i < answers.length; i++) { |
| 693 | + Assert.assertArrayEquals("Length: " + i, answers[i], MurmurHash3.hash128x64(RANDOM_BYTES, offset, i, seed)); |
| 694 | + } |
| 695 | + |
| 696 | + // Seed can be negative |
| 697 | + final int seed2 = -42; |
| 698 | + |
| 699 | + // Test with all sizes up to 31 bytes. This ensures a full round of 16-bytes plus up to |
| 700 | + // 15 bytes remaining. |
| 701 | + // for x in range(0, 32): |
| 702 | + // print(mmh3.hash64(bytes[13:x+13], -42), ',') |
| 703 | + final long[][] answers2 = {{7182599573337898253L, -6490979146667806054L}, |
| 704 | + {-461284136738605467L, 7073284964362976233L}, {-3090354666589400212L, 2978755180788824810L}, |
| 705 | + {5052807367580803906L, -4497188744879598335L}, {5003711854877353474L, -6616808651483337088L}, |
| 706 | + {2043501804923817748L, -760668448196918637L}, {6813003268375229932L, -1818545210475363684L}, |
| 707 | + {4488070015393027916L, 8520186429078977003L}, {4709278711722456062L, -2262080641289046033L}, |
| 708 | + {-5944514262756048380L, 5968714500873552518L}, {-2304397529301122510L, 6451500469518446488L}, |
| 709 | + {-1054078041081348909L, -915114408909600132L}, {1300471646869277217L, -399493387666437046L}, |
| 710 | + {-2821780479886030222L, -9061571187511294733L}, {8005764841242557505L, 4135287855434326053L}, |
| 711 | + {318307346637037498L, -5355856739901286522L}, {3380719536119187025L, 1890890833937151467L}, |
| 712 | + {2691044185935730001L, 7963546423617895734L}, {-5277462388534000227L, 3613853764390780573L}, |
| 713 | + {8504421722476165699L, 2058020162708103700L}, {-6578421288092422241L, 3311200163790829579L}, |
| 714 | + {-5915037218487974215L, -7385137075895184179L}, {659642911937398022L, 854071824595671049L}, |
| 715 | + {-7007237968866727198L, 1372258010932080058L}, {622891376282772539L, -4140783491297489868L}, |
| 716 | + {8357110718969014985L, -4737117827581590306L}, {2208857857926305405L, -8360240839768465042L}, |
| 717 | + {858120048221036376L, -5822288789703639119L}, {-1988334009458340679L, 1262479472434068698L}, |
| 718 | + {-8580307083590783934L, 3634449965473715778L}, {6705664584730187559L, 5192304951463791556L}, |
| 719 | + {-6426410954037604142L, -1579122709247558101L},}; |
| 720 | + for (int i = 0; i < answers.length; i++) { |
| 721 | + Assert.assertArrayEquals("Length: " + i, answers2[i], MurmurHash3.hash128x64(RANDOM_BYTES, offset, i, seed2)); |
| 722 | + } |
| 723 | + } |
| 724 | + |
616 | 725 | /** |
617 | 726 | * Test {@link IncrementalHash32} returns the same values as |
618 | 727 | * {@link MurmurHash3#hash32(byte[], int, int, int)}. |
|
0 commit comments