github.com/cnotch/ipchub@v1.1.0/utils/murmur/murmur_test.go (about)

     1  /**********************************************************************************
     2  * Copyright (c) 2009-2019 Misakai Ltd.
     3  * This program is free software: you can redistribute it and/or modify it under the
     4  * terms of the GNU Affero General Public License as published by the  Free Software
     5  * Foundation, either version 3 of the License, or(at your option) any later version.
     6  *
     7  * This program is distributed  in the hope that it  will be useful, but WITHOUT ANY
     8  * WARRANTY;  without even  the implied warranty of MERCHANTABILITY or FITNESS FOR A
     9  * PARTICULAR PURPOSE.  See the GNU Affero General Public License  for  more details.
    10  *
    11  * You should have  received a copy  of the  GNU Affero General Public License along
    12  * with this program. If not, see<http://www.gnu.org/licenses/>.
    13  ************************************************************************************/
    14  
    15  package murmur
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  )
    22  
    23  // BenchmarkOf-8   	100000000	        14.5 ns/op	       0 B/op	       0 allocs/op
    24  func BenchmarkOf(b *testing.B) {
    25  	v := []byte("a/b/c/d/e/f/g/h/this/is/ipchub")
    26  
    27  	b.ReportAllocs()
    28  	b.ResetTimer()
    29  	for i := 0; i < b.N; i++ {
    30  		_ = Of(v)
    31  	}
    32  }
    33  
    34  // BenchmarkOfString-8   	100000000	        18.4 ns/op	       0 B/op	       0 allocs/op
    35  func BenchmarkOfString(b *testing.B) {
    36  	v := "a/b/c/d/e/f/g/h/this/is/ipchub"
    37  
    38  	b.ReportAllocs()
    39  	b.ResetTimer()
    40  	for i := 0; i < b.N; i++ {
    41  		_ = OfString(v)
    42  	}
    43  }
    44  
    45  func TestMeHash(t *testing.T) {
    46  	h := OfString("me")
    47  	assert.Equal(t, uint32(2539734036), h)
    48  }
    49  
    50  func TestShareHash(t *testing.T) {
    51  	h := Of([]byte("$share"))
    52  	assert.Equal(t, uint32(1480642916), h)
    53  }
    54  
    55  func TestLinkHash(t *testing.T) {
    56  	h := Of([]byte("link"))
    57  	assert.Equal(t, uint32(2667034312), h)
    58  }
    59  
    60  func TestGetHash(t *testing.T) {
    61  	h := Of([]byte("+"))
    62  	if h != 1815237614 {
    63  		t.Errorf("Hash %d is not equal to %d", h, 1815237614)
    64  	}
    65  }
    66  
    67  func TestGetHash2(t *testing.T) {
    68  	h := Of([]byte("hello world"))
    69  	if h != 4008393376 {
    70  		t.Errorf("Hash %d is not equal to %d", h, 1815237614)
    71  	}
    72  }