github.com/grailbio/base@v0.0.11/recordio/estimate_test.go (about) 1 package recordio_test 2 3 import ( 4 "testing" 5 6 "github.com/grailbio/base/recordio" 7 "github.com/grailbio/testutil/assert" 8 ) 9 10 const ( 11 KiB = int64(1024) 12 MiB = int64(1024 * 1024) 13 ) 14 15 func TestRequiredSpaceUpperBound(t *testing.T) { 16 for _, test := range []struct { 17 itemSizes []int64 18 recordSize int64 19 expectedReqSpace int64 20 }{ 21 // internal.ChunkSize == 32KiB 22 23 { // recordSize < chunkSize 24 []int64{1 * KiB, 1 * KiB, 1 * KiB}, 25 1 * KiB, 26 6 * 32 * KiB, 27 }, 28 { // recordSize < chunkSize 29 []int64{1 * KiB, 1 * KiB, 1 * KiB}, 30 2 * KiB, 31 4 * 32 * KiB, 32 }, 33 { // chunkSize < recordSize 34 []int64{5 * MiB, 2 * KiB, 12 * MiB, 3 * MiB}, 35 4 * MiB, 36 776 * 32 * KiB, 37 }, 38 { // recordSize == chunkSize 39 []int64{35 * KiB, 9 * KiB, 1 * MiB, 20 * KiB}, 40 32 * KiB, 41 72 * 32 * KiB, 42 }, 43 { // sizes where no-padding of chunks is required 44 []int64{32736, 32736, 32732 + 32740 + 32736}, 45 32*KiB - 32, 46 8 * 32 * KiB, 47 }, 48 } { 49 req := recordio.RequiredSpaceUpperBound(test.itemSizes, test.recordSize) 50 sum := int64(0) 51 for _, v := range test.itemSizes { 52 sum += v 53 } 54 assert.GT(t, req, sum) 55 assert.EQ(t, req, test.expectedReqSpace) 56 } 57 }