github.com/Jeffail/benthos/v3@v3.65.0/lib/util/hash/murmur2/murmur2_test.go (about)

     1  package murmur2
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  )
     7  
     8  func TestMurmur2SanityCheck(t *testing.T) {
     9  	tests := []struct {
    10  		data     []string
    11  		expected int32
    12  	}{
    13  		{[]string{"hello world"}, 1221641059},
    14  		{[]string{"hello" + " " + "world"}, 1221641059},
    15  		// examples from: https://stackoverflow.com/questions/48582589/porting-kafkas-murmur2-implementation-to-go
    16  		{[]string{"21"}, -973932308},
    17  		{[]string{"foobar"}, -790332482},
    18  		{[]string{"a-little-bit-long-string"}, -985981536},
    19  		{[]string{"a-little-bit-longer-string"}, -1486304829},
    20  		{[]string{"lkjh234lh9fiuh90y23oiuhsafujhadof229phr9h19h89h8"}, -58897971},
    21  		{[]string{"a", "b", "c"}, 479470107},
    22  	}
    23  	for i, tt := range tests {
    24  		t.Run(strconv.Itoa(i)+". ", func(t *testing.T) {
    25  			mur := New32()
    26  			for _, datum := range tt.data {
    27  				_, _ = mur.Write([]byte(datum))
    28  			}
    29  			calculated := mur.Sum32()
    30  			if int32(calculated) != tt.expected {
    31  				t.Errorf("murmur2 hash failed: is -> %v != %v <- should be", calculated, tt.expected)
    32  				return
    33  			}
    34  		})
    35  	}
    36  }