github.com/gogf/gf/v2@v2.7.4/encoding/ghash/ghash_z_unit_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package ghash_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/gogf/gf/v2/encoding/ghash"
    13  	"github.com/gogf/gf/v2/test/gtest"
    14  )
    15  
    16  var (
    17  	strBasic = []byte("This is the test string for hash.")
    18  )
    19  
    20  func Test_BKDR(t *testing.T) {
    21  	gtest.C(t, func(t *gtest.T) {
    22  		x := uint32(200645773)
    23  		j := ghash.BKDR(strBasic)
    24  		t.Assert(j, x)
    25  	})
    26  	gtest.C(t, func(t *gtest.T) {
    27  		x := uint64(4214762819217104013)
    28  		j := ghash.BKDR64(strBasic)
    29  		t.Assert(j, x)
    30  	})
    31  }
    32  
    33  func Test_SDBM(t *testing.T) {
    34  	gtest.C(t, func(t *gtest.T) {
    35  		x := uint32(1069170245)
    36  		j := ghash.SDBM(strBasic)
    37  		t.Assert(j, x)
    38  	})
    39  	gtest.C(t, func(t *gtest.T) {
    40  		x := uint64(9881052176572890693)
    41  		j := ghash.SDBM64(strBasic)
    42  		t.Assert(j, x)
    43  	})
    44  }
    45  
    46  func Test_RS(t *testing.T) {
    47  	gtest.C(t, func(t *gtest.T) {
    48  		x := uint32(1944033799)
    49  		j := ghash.RS(strBasic)
    50  		t.Assert(j, x)
    51  	})
    52  	gtest.C(t, func(t *gtest.T) {
    53  		x := uint64(13439708950444349959)
    54  		j := ghash.RS64(strBasic)
    55  		t.Assert(j, x)
    56  	})
    57  }
    58  
    59  func Test_JS(t *testing.T) {
    60  	gtest.C(t, func(t *gtest.T) {
    61  		x := uint32(498688898)
    62  		j := ghash.JS(strBasic)
    63  		t.Assert(j, x)
    64  	})
    65  	gtest.C(t, func(t *gtest.T) {
    66  		x := uint64(13410163655098759877)
    67  		j := ghash.JS64(strBasic)
    68  		t.Assert(j, x)
    69  	})
    70  }
    71  
    72  func Test_PJW(t *testing.T) {
    73  	gtest.C(t, func(t *gtest.T) {
    74  		x := uint32(7244206)
    75  		j := ghash.PJW(strBasic)
    76  		t.Assert(j, x)
    77  	})
    78  	gtest.C(t, func(t *gtest.T) {
    79  		x := uint64(31150)
    80  		j := ghash.PJW64(strBasic)
    81  		t.Assert(j, x)
    82  	})
    83  }
    84  
    85  func Test_ELF(t *testing.T) {
    86  	gtest.C(t, func(t *gtest.T) {
    87  		x := uint32(7244206)
    88  		j := ghash.ELF(strBasic)
    89  		t.Assert(j, x)
    90  	})
    91  	gtest.C(t, func(t *gtest.T) {
    92  		x := uint64(31150)
    93  		j := ghash.ELF64(strBasic)
    94  		t.Assert(j, x)
    95  	})
    96  }
    97  
    98  func Test_DJB(t *testing.T) {
    99  	gtest.C(t, func(t *gtest.T) {
   100  		x := uint32(959862602)
   101  		j := ghash.DJB(strBasic)
   102  		t.Assert(j, x)
   103  	})
   104  	gtest.C(t, func(t *gtest.T) {
   105  		x := uint64(2519720351310960458)
   106  		j := ghash.DJB64(strBasic)
   107  		t.Assert(j, x)
   108  	})
   109  }
   110  
   111  func Test_AP(t *testing.T) {
   112  	gtest.C(t, func(t *gtest.T) {
   113  		x := uint32(3998202516)
   114  		j := ghash.AP(strBasic)
   115  		t.Assert(j, x)
   116  	})
   117  	gtest.C(t, func(t *gtest.T) {
   118  		x := uint64(2531023058543352243)
   119  		j := ghash.AP64(strBasic)
   120  		t.Assert(j, x)
   121  	})
   122  }