github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/internal/randvar/skewed_latest_test.go (about) 1 // Copyright 2018 The Cockroach Authors. 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 12 // implied. See the License for the specific language governing 13 // permissions and limitations under the License. See the AUTHORS file 14 // for names of contributors. 15 16 package randvar 17 18 import ( 19 "fmt" 20 "sort" 21 "testing" 22 ) 23 24 func dumpSamples(x []int) { 25 sort.Ints(x) 26 27 max := x[len(x)-1] 28 step := max / 20 29 if step == 0 { 30 step = 1 31 } 32 index := 0 33 count := 0 34 for i := 0; i <= max; i += step { 35 count = 0 36 for index < len(x) { 37 if x[index] >= i+step { 38 break 39 } 40 index++ 41 count++ 42 } 43 fmt.Printf("[%3d-%3d) ", i, i+step) 44 for j := 0; j < count; j++ { 45 if j%50 == 0 { 46 fmt.Printf("%c", '∎') 47 } 48 } 49 fmt.Println() 50 } 51 } 52 53 func TestSkewedLatest(t *testing.T) { 54 z, err := NewSkewedLatest(nil, 0, 99, 0.99) 55 if err != nil { 56 t.Fatal(err) 57 } 58 59 x := make([]int, 10000) 60 for i := range x { 61 x[i] = int(z.Uint64()) 62 } 63 64 if testing.Verbose() { 65 dumpSamples(x) 66 } 67 }