github.com/cilium/cilium@v1.16.2/pkg/murmur3/murmur3_test.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package murmur3
     5  
     6  import (
     7  	"testing"
     8  )
     9  
    10  func TestMurmur3(t *testing.T) {
    11  	var tests = []struct {
    12  		seed uint32
    13  		h1   uint64
    14  		h2   uint64
    15  		s    string
    16  	}{
    17  		{0, 0x0000000000000000, 0x0000000000000000, ""},
    18  		{1234, 0x1629cce705a7069c, 0x316c1fbd953aaecd, "hello world"},
    19  		{500, 0x188f69f0abbd67de, 0x1b0eeb31b4c00cb6, "lorem ipsum dolor sit amet"},
    20  		{31, 0x24b05ffca412286a, 0x7d81ac914b62fe96, "this is a test of 31 bytes long"},
    21  		{0xd09, 0x5e0fd714b3169ae6, 0x2f36e811c1535dc7, "The quick brown fox jumps over the lazy dog."},
    22  	}
    23  
    24  	for _, tt := range tests {
    25  		t.Run(tt.s, func(t *testing.T) {
    26  			h1, h2 := Hash128([]byte(tt.s), tt.seed)
    27  			if want, got := tt.h1, h1; want != got {
    28  				t.Errorf("Unexpected h1:\n\twant:\t0x%x,\n\tgot:\t0x%x", want, got)
    29  			}
    30  			if want, got := tt.h2, h2; want != got {
    31  				t.Errorf("Unexpected h2:\n\twant:\t0x%x,\n\tgot:\t0x%x", want, got)
    32  			}
    33  		})
    34  	}
    35  }