v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/hash/jump/jump_test.go (about) 1 package jump 2 3 import "testing" 4 5 func TestJumpConsistentHash(t *testing.T) { 6 type args struct { 7 key uint64 8 num_buckets int32 9 } 10 tests := []struct { 11 name string 12 args args 13 want int32 14 }{ 15 { 16 name: "TestJumpConsistentHash 1 1", 17 args: args{ 18 key: 1, 19 num_buckets: 1, 20 }, 21 want: 0, 22 }, 23 { 24 name: "TestJumpConsistentHash 10 1", 25 args: args{ 26 key: 10, 27 num_buckets: 1, 28 }, 29 want: 0, 30 }, 31 { 32 name: "TestJumpConsistentHash 10 1024", 33 args: args{ 34 key: 10, 35 num_buckets: 1024, 36 }, 37 want: 751, 38 }, 39 { 40 name: "TestJumpConsistentHash 1024 1024", 41 args: args{ 42 key: 1024, 43 num_buckets: 1024, 44 }, 45 want: 465, 46 }, 47 { 48 name: "TestJumpConsistentHash 2048 1024", 49 args: args{ 50 key: 2048, 51 num_buckets: 1024, 52 }, 53 want: 10, 54 }, 55 { 56 name: "TestJumpConsistentHash 2048 65536", 57 args: args{ 58 key: 2048, 59 num_buckets: 65536, 60 }, 61 want: 41753, 62 }, 63 { 64 name: "TestJumpConsistentHash 2048 65537", 65 args: args{ 66 key: 2048, 67 num_buckets: 65537, 68 }, 69 want: 41753, 70 }, 71 { 72 name: "TestJumpConsistentHash 2048 65538", 73 args: args{ 74 key: 2048, 75 num_buckets: 65538, 76 }, 77 want: 41753, 78 }, 79 { 80 name: "TestJumpConsistentHash 2048 100000", 81 args: args{ 82 key: 2048, 83 num_buckets: 100000, 84 }, 85 want: 41753, 86 }, 87 } 88 for _, tt := range tests { 89 t.Run(tt.name, func(t *testing.T) { 90 if got := JumpConsistentHash(tt.args.key, tt.args.num_buckets); got != tt.want { 91 t.Errorf("JumpConsistentHash() = %v, want %v", got, tt.want) 92 } 93 }) 94 } 95 } 96 97 func BenchmarkJumpConsistentHash(b *testing.B) { 98 for i := 0; i < b.N; i++ { 99 _ = JumpConsistentHash(2048, 100000) 100 } 101 }