github.com/rolandhe/saber@v0.0.4/hash/cityhash_test.go (about) 1 // Package hash, Golang concurrent tools like java juc. 2 // 3 // Copyright 2023 The saber Authors. All rights reserved. 4 5 package hash 6 7 import ( 8 "fmt" 9 "testing" 10 ) 11 12 func TestCityHash32Le4(t *testing.T) { 13 s := "中" 14 15 hash := CityHash32String(s) 16 if hash != 0x94f00d7d { 17 t.Error("error") 18 } 19 } 20 21 func TestCityHash32From5To12(t *testing.T) { 22 s := "中国" 23 24 hash := CityHash32String(s) 25 if hash != 0xb342166b { 26 t.Error("error") 27 } 28 } 29 30 func TestCityHash32From12To24(t *testing.T) { 31 s := "中国人民了" 32 33 hash := CityHash32String(s) 34 if hash != 0xbc72f21a { 35 t.Error("error") 36 } 37 } 38 39 func TestCityHash32Ge24(t *testing.T) { 40 s := "我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件" 41 42 hash := CityHash32String(s) 43 if hash != 0x51020cae { 44 t.Error("error") 45 } 46 } 47 48 func TestCityHash64Le4(t *testing.T) { 49 s := "中" 50 51 hash := CityHash64String(s) 52 if hash != 0xac065168c34af7fe { 53 t.Error("error") 54 } 55 } 56 57 func TestCityHash64From4To8(t *testing.T) { 58 s := "中国" 59 60 hash := CityHash64String(s) 61 if hash != 0xe4499ba8daad0087 { 62 t.Error("error") 63 } 64 } 65 66 func TestCityHash64From8To16(t *testing.T) { 67 s := "中国人民" 68 69 hash := CityHash64String(s) 70 if hash != 0x155f37b6451fcd43 { 71 t.Error("error") 72 } 73 } 74 75 func TestCityHash64From17To32(t *testing.T) { 76 s := "中国人民共和国" 77 78 hash := CityHash64String(s) 79 if hash != 0xe0665a552991a515 { 80 t.Error("error") 81 } 82 } 83 84 func TestCityHash64From33To64(t *testing.T) { 85 s := "中国人民共和国站起来了鼓掌" 86 87 hash := CityHash64String(s) 88 if hash != 0xaf216c93667b7d75 { 89 t.Error("error") 90 } 91 } 92 93 func TestCityHash64Ge64(t *testing.T) { 94 s := "我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件" 95 96 hash := CityHash64String(s) 97 if hash != 0x8db857dd3d4b22e1 { 98 t.Error("error") 99 } 100 } 101 102 func TestCityHash128Less16(t *testing.T) { 103 s := "中国人民" 104 105 hash := CityHash128String(s) 106 if hash.low != 0xdb49338f94e45026 || hash.high != 0xb57c012f2ec4ee25 { 107 t.Error("error") 108 } 109 } 110 111 func TestCityHash128Ge16(t *testing.T) { 112 s := "中国人民站起来了胡扯" 113 114 hash := CityHash128String(s) 115 if hash.low != 0xd44fe88bbed69110 || hash.high != 0x731d6d9846735ecd { 116 t.Error("error") 117 } 118 } 119 120 func TestCityHash128Ge16Big(t *testing.T) { 121 s := "我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件" 122 123 hash := CityHash128String(s) 124 if hash.low != 0x73b63e8cd44766c5 || hash.high != 0x9ed8d2c68d45b293 { 125 t.Error("error") 126 } 127 } 128 129 func TestCityHashCrc256StringLess240(t *testing.T) { 130 s := "我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件" 131 132 hash, err := CityHashCrc256String(s) 133 if err != nil { 134 fmt.Println(err) 135 } 136 fmt.Println(hash, err) 137 if hash[0] != 0x3A7D187FB7F66B24 || hash[1] != 0xF1A46DAFEDEA9745 || hash[2] != 0x59C56C88A14437CD || hash[3] != 0xE266B7432F21E8AF { 138 t.Error("error") 139 } 140 } 141 142 func TestCityHashCrc256StringGreat240(t *testing.T) { 143 s := "我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件Width and precision are measured in units of Unicode code points, that is, runes. (This differs from C's printf where the units are always measured in bytes.) Either or both of the flags may be replaced with the character '*', causing their values to be obtained from the next operand (preceding the one to format), which must be of type int." 144 145 hash, err := CityHashCrc256String(s) 146 147 if err != nil { 148 fmt.Println(err) 149 } 150 fmt.Println(hash, err) 151 if hash[0] != 0x5C0042CE0214D738 || hash[1] != 0x73B87E64358B3FC || hash[2] != 0xC9DD169C8EA1C7B7 || hash[3] != 0x794CF48A69E4E2BA { 152 t.Error("error") 153 } 154 } 155 156 func TestCityHashCrc256String240(t *testing.T) { 157 s := "我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件Width and precision are measured in units of Unicode code points, that is, runes. (This differs from C" 158 159 hash, err := CityHashCrc256String(s) 160 if err != nil { 161 fmt.Println(err) 162 } 163 fmt.Println(hash, err) 164 if hash[0] != 0xFDF2DAF446298495 || hash[1] != 0x8EED1340BE726CEA || hash[2] != 0x63702635D7CE52F9 || hash[3] != 0x616FD421E1014D0C { 165 t.Error("error") 166 } 167 }