github.com/matrixorigin/matrixone@v1.2.0/pkg/container/hashtable/hash_test.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package hashtable 16 17 import ( 18 //"fmt" 19 20 "reflect" 21 "testing" 22 ) 23 24 var data = [][]byte{ 25 []byte(""), 26 []byte("a"), 27 []byte("ab"), 28 []byte("abc"), 29 []byte("abcd"), 30 []byte("abcde"), 31 []byte("abcdef"), 32 []byte("abcdefg"), 33 []byte("abcdefgh"), 34 []byte("abcdefghi"), 35 []byte("abcdefghij"), 36 []byte("abcdefghijk"), 37 []byte("abcdefghijkl"), 38 []byte("abcdefghijklm"), 39 []byte("abcdefghijklmn"), 40 []byte("abcdefghijklmno"), 41 []byte("abcdefghijklmnop"), 42 43 []byte("aaaaaaaaaaaaaaaa"), 44 []byte("aaaaaaaaaaaaaaab"), 45 []byte("aaaaaaaaaaaaaabb"), 46 []byte("aaaaaaaaaaaaabbb"), 47 []byte("aaaaaaaaaaaabbbb"), 48 []byte("aaaaaaaaaaabbbbb"), 49 []byte("aaaaaaaaaabbbbbb"), 50 []byte("aaaaaaaaabbbbbbb"), 51 []byte("aaaaaaaabbbbbbbb"), 52 []byte("aaaaaaabbbbbbbbb"), 53 []byte("aaaaaabbbbbbbbbb"), 54 []byte("aaaaabbbbbbbbbbb"), 55 []byte("aaaabbbbbbbbbbbb"), 56 []byte("aaabbbbbbbbbbbbb"), 57 []byte("aabbbbbbbbbbbbbb"), 58 []byte("abbbbbbbbbbbbbbb"), 59 []byte("bbbbbbbbbbbbbbbb"), 60 61 []byte("Discard medicine more than two years old."), 62 []byte("He who has a shady past knows that nice guys finish last."), 63 []byte("I wouldn't marry him with a ten foot pole."), 64 []byte("Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave"), 65 []byte("The days of the digital watch are numbered. -Tom Stoppard"), 66 []byte("Nepal premier won't resign."), 67 []byte("For every action there is an equal and opposite government program."), 68 []byte("His money is twice tainted: 'taint yours and 'taint mine."), 69 []byte("There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977"), 70 []byte("It's a tiny change to the code and not completely disgusting. - Bob Manchek"), 71 []byte("size: a.out: bad magic"), 72 []byte("The major problem is with sendmail. -Mark Horton"), 73 []byte("Give me a rock, paper and scissors and I will move the world. CCFestoon"), 74 []byte("If the enemy is within range, then so are you."), 75 []byte("It's well we cannot hear the screams/That we create in others' dreams."), 76 []byte("You remind me of a TV show, but that's all right: I watch it anyway."), 77 []byte("C is as portable as Stonehedge!!"), 78 []byte("Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley"), 79 []byte("The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule"), 80 []byte("How can you write a big system without C++? -Paul Glick"), 81 } 82 83 var golden = [][3]uint64{ 84 {0x57231643ef445469, 0x907b30e073265f45, 0x3dbe062192314be7}, 85 {0xac9e9519156d61b6, 0x907b30e0cb4e3795, 0x3dbe062192314be7}, 86 {0xfc172bf910cfb489, 0x907b30e0cb4e3795, 0xa92a358692314be7}, 87 {0xe380e8838517d5ad, 0x907b30e0cb4e3795, 0xa92a3586b2712bc7}, 88 {0xd6615c5690de91e7, 0xd3949c4ccb4e3795, 0xa92a3586b2712bc7}, 89 {0x664c36842476f444, 0x5c18104fcb4e3795, 0xa92a3586b2712bc7}, 90 {0xbc9df67caa16e686, 0x5c18104f7bfe4c5e, 0xa92a3586b2712bc7}, 91 {0x5286f5c9d84260e7, 0x5c18104f7bfe4c5e, 0x0d79c222b2712bc7}, 92 {0xcec5a6d57bc08698, 0x5c18104f7bfe4c5e, 0x0d79c222aa6527cb}, 93 {0x148024510ca2054d, 0x5c18104f7bfe4c5e, 0x0d79c2226ed092ba}, 94 {0x95c7ef559e3bf783, 0xb1f5d1637bfe4c5e, 0x0d79c2226ed092ba}, 95 {0x44cfbb1713178bd8, 0xb1f5d163234ea406, 0x0d79c2226ed092ba}, 96 {0xb3eb6026586bdac5, 0xb1f5d163234ea406, 0x8c350fef6ed092ba}, 97 {0xb47e6fe3421b9ad8, 0xb1f5d163234ea406, 0xdbf1cb7c6ed092ba}, 98 {0x0d58855ff3dd27e5, 0xb1f5d163234ea406, 0xdbf1cb7c07b94001}, 99 {0x86a874e7541aba8e, 0xb8e7ca6a234ea406, 0xdbf1cb7c07b94001}, 100 {0x178ce76052430bc8, 0xb8e7ca6a1ee03795, 0xdbf1cb7c07b94001}, 101 102 {0x12ad178c4d1ee33b, 0x124ef5b524b71cc7, 0x05243bcb3234f68d}, 103 {0x9e7bcd3bc92bdfd3, 0x124ef5b502820fd4, 0x05243bcb3234f68d}, 104 {0x4d703e8106cf3b74, 0x40ea03e702820fd4, 0x05243bcb3234f68d}, 105 {0x280c1b48b6c5177a, 0x40ea03e702820fd4, 0x05243bcba7a1c729}, 106 {0xc964aa8f22b4d041, 0x40ea03e702820fd4, 0xa5445b0ba7a1c729}, 107 {0xdfcd7ebebe26864b, 0x40ea03e702820fd4, 0xbd505707a7a1c729}, 108 {0x5d853b1cacc46e97, 0x40ea03e7008609d6, 0xbd505707a7a1c729}, 109 {0x5fad2c4d4bd151b3, 0xf75d7625008609d6, 0xbd505707a7a1c729}, 110 {0x32b4f455dcbf1a09, 0xf75d7625008609d6, 0xbd50570775ef89b5}, 111 {0xcbca8bcc5aa76096, 0xf75d7625008609d6, 0xbd5057071236370b}, 112 {0xf4487c5c7a272dff, 0xf75d7625008609d6, 0xe8faa8521236370b}, 113 {0x5527e6f273cfdf58, 0xf75d762544c2811a, 0xe8faa8521236370b}, 114 {0x7b43f98ad98f9496, 0xd7b49fec44c2811a, 0xe8faa8521236370b}, 115 {0x21653a5986192010, 0x925e304344c2811a, 0xe8faa8521236370b}, 116 {0x8a2be0cc55ee347e, 0x925e304344c2811a, 0xe8faa85260d2a179}, 117 {0x980b3114e71025f6, 0x925e304344c2811a, 0xf0e2987a60d2a179}, 118 {0xa7a33d25621c7562, 0x925e3043f85f1c3b, 0xf0e2987a60d2a179}, 119 120 {0xcff785df0b9b7d75, 0xfc0dd3539c80a99b, 0x61df14a1ab58ac9d}, 121 {0x96edc6e7be627a8f, 0x8df9e77e349fe316, 0xc87a0e284077850b}, 122 {0x66074051b892e14f, 0xd899939659baad31, 0x94a1828a15d7bb78}, 123 {0x206fb007ed76faf6, 0x58eecddfc68f169b, 0x33edca360805b586}, 124 {0xe8a83b6ba5105479, 0x8f33cf4f35c14090, 0x5a8cd440eae9b5f4}, 125 {0x909a31af7e26a48b, 0x559da96ebc928032, 0xb169282fbbbbf10d}, 126 {0xa802665115f68538, 0x280d3c804a4abb4f, 0x4aa68bb0f57a03da}, 127 {0x4a1925e05b4f60dc, 0x28ca4e72b699af7f, 0x6ef7148e66bc3ba0}, 128 {0xd970d0bd5edfe09d, 0x8975e8361e5c8613, 0x85066606aed75163}, 129 {0x18fcd7e6d51dfa35, 0xcf4540b6236bc67b, 0x5f28d41c24fd0ff4}, 130 {0xa4b08260426fd42b, 0xfd4d6f337735decc, 0x7612fdeeb417d78c}, 131 {0x25c2c14672724512, 0x545ad07a08a1a27f, 0x11ef0ad25b765a6c}, 132 {0x65590dcfdeb24a70, 0x926c6391b4edc372, 0x5ab9892ff2ec06f9}, 133 {0xb0b9c6ca8ddbecbd, 0xaffede505f89dcd6, 0x5c7504907eb2ae4b}, 134 {0x14a86da1e44ac18c, 0xbaffb312e4131a1f, 0xf20a893495216a46}, 135 {0x797ef5ae825df0fe, 0x23341f9f2abee954, 0x8d5c49cf932b17b8}, 136 {0x7c02cc3aa4da2f0d, 0x0e257b27eab088d3, 0xd07ca91c7439b4e4}, 137 {0x48d223630a9b37d5, 0xc37d3048537c6093, 0x902a07e6f97ce01d}, 138 {0xfd0df89810f88825, 0x85798a1253c0bbbb, 0x52df1e6ecf6d5505}, 139 {0x66fa326f6a2d8954, 0x98da25cf7a2638f8, 0x7b091be3b213701a}, 140 } 141 142 func TestHashFn(t *testing.T) { 143 fp1 := reflect.ValueOf(BytesBatchGenHashStates) 144 fp2 := reflect.ValueOf(aesBytesBatchGenHashStates) 145 if fp1.Pointer() != fp2.Pointer() { 146 return 147 } 148 149 states := make([][3]uint64, len(data)) 150 for i := range data { 151 if l := len(data[i]); l < 16 { 152 data[i] = append(data[i], StrKeyPadding[l:]...) 153 } 154 } 155 BytesBatchGenHashStates(&data[0], &states[0], len(data)) 156 for i := range data { 157 if states[i] != golden[i] { 158 t.Errorf("AesBytesHashState(%s) = {0x%016x, 0x%016x, 0x%016x} want {0x%016x, 0x%016x, 0x%016x}", 159 data[i], 160 states[i][0], states[i][1], states[i][2], 161 golden[i][0], golden[i][1], golden[i][2]) 162 163 } 164 } 165 }