github.com/cockroachdb/pebble@v1.1.2/internal/mkbench/split_test.go (about) 1 // Copyright 2021 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package main 6 7 import ( 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestFindOptimalSplit(t *testing.T) { 14 testCases := []struct { 15 passes, fails []int 16 want int 17 }{ 18 { 19 // Not enough data. 20 passes: []int{}, 21 fails: []int{}, 22 want: -1, 23 }, 24 { 25 // Not enough data. 26 passes: []int{1, 2, 3}, 27 fails: []int{}, 28 want: -1, 29 }, 30 { 31 // Not enough data. 32 passes: []int{}, 33 fails: []int{1, 2, 3}, 34 want: -1, 35 }, 36 { 37 // Trivial example. 38 passes: []int{100}, 39 fails: []int{200}, 40 want: 150, 41 }, 42 { 43 // Example given in the doc comment for the function. 44 passes: []int{100, 210, 300, 380, 450, 470, 490, 510, 520}, 45 fails: []int{310, 450, 560, 610, 640, 700, 720, 810}, 46 want: 550, 47 }, 48 { 49 // Empirical data from an actual test run (~1hr). 50 passes: []int{ 51 1000, 1100, 1300, 1700, 2500, 4100, 7300, 13700, 26500, 52100, 52 52100, 52100, 26500, 26600, 26800, 27200, 28000, 29600, 32800, 53 32800, 32900, 32900, 33000, 33000, 33100, 33100, 33100, 33100, 54 33100, 33100, 33000, 33100, 33000, 32900, 33000, 33200, 33600, 55 34400, 36000, 56 }, 57 fails: []int{ 58 103300, 52200, 52200, 52100, 39200, 33100, 33200, 33300, 33200, 59 33200, 33200, 33200, 33200, 33100, 33300, 33100, 33100, 33000, 60 39200, 36100, 61 }, 62 want: 33100, 63 }, 64 } 65 66 for _, tc := range testCases { 67 t.Run("", func(t *testing.T) { 68 split := findOptimalSplit(tc.passes, tc.fails) 69 require.Equal(t, tc.want, split) 70 }) 71 } 72 }