github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/workload/movr/movr_test.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package movr 12 13 import ( 14 "testing" 15 16 "github.com/stretchr/testify/require" 17 ) 18 19 func TestCityDistributor(t *testing.T) { 20 for numRows := len(cities); numRows < len(cities)*len(cities); numRows++ { 21 d := cityDistributor{numRows: numRows} 22 for rowIdx := 0; rowIdx < numRows; rowIdx++ { 23 cityIdx := d.cityForRow(rowIdx) 24 if cityIdx < 0 || cityIdx >= len(cities) { 25 t.Fatalf(`city must be in [0,%d) was %d`, len(cities), cityIdx) 26 } 27 min, max := d.rowsForCity(cityIdx) 28 if rowIdx < min || rowIdx >= max { 29 t.Fatalf(`row must be in [%d,%d) was %d`, min, max, rowIdx) 30 } 31 } 32 for cityIdx := range cities { 33 min, max := d.rowsForCity(cityIdx) 34 if min < 0 || min > numRows { 35 t.Fatalf(`min must be in [0,%d] was %d`, numRows, min) 36 } 37 if max < 0 || max > numRows { 38 t.Fatalf(`max must be in [0,%d] was %d`, numRows, max) 39 } 40 if min > max { 41 t.Fatalf(`min %d must be <= max %d`, min, max) 42 } 43 for row := min; row < max; row++ { 44 require.Equal(t, cityIdx, d.cityForRow(row), "rows=%d row=%d", numRows, row) 45 } 46 } 47 } 48 }