...

Source file src/golang.org/x/mod/sumdb/tlog/tile_test.go

Documentation: golang.org/x/mod/sumdb/tlog

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package tlog
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  // FuzzParseTilePath tests that ParseTilePath never crashes
    13  func FuzzParseTilePath(f *testing.F) {
    14  	f.Add("tile/4/0/001")
    15  	f.Add("tile/4/0/001.p/5")
    16  	f.Add("tile/3/5/x123/x456/078")
    17  	f.Add("tile/3/5/x123/x456/078.p/2")
    18  	f.Add("tile/1/0/x003/x057/500")
    19  	f.Add("tile/3/5/123/456/078")
    20  	f.Add("tile/3/-1/123/456/078")
    21  	f.Add("tile/1/data/x003/x057/500")
    22  	f.Fuzz(func(t *testing.T, path string) {
    23  		ParseTilePath(path)
    24  	})
    25  }
    26  
    27  func TestNewTilesForSize(t *testing.T) {
    28  	for _, tt := range []struct {
    29  		old, new int64
    30  		want     int
    31  	}{
    32  		{1, 1, 0},
    33  		{100, 101, 1},
    34  		{1023, 1025, 3},
    35  		{1024, 1030, 1},
    36  		{1030, 2000, 1},
    37  		{1030, 10000, 10},
    38  		{49516517, 49516586, 3},
    39  	} {
    40  		t.Run(fmt.Sprintf("%d-%d", tt.old, tt.new), func(t *testing.T) {
    41  			tiles := NewTiles(10, tt.old, tt.new)
    42  			if got := len(tiles); got != tt.want {
    43  				t.Errorf("got %d, want %d", got, tt.want)
    44  				for _, tile := range tiles {
    45  					t.Logf("%+v", tile)
    46  				}
    47  			}
    48  		})
    49  	}
    50  }
    51  

View as plain text