github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/bitpack/offset_array_test.go (about)

     1  package bitpack_test
     2  
     3  import (
     4  	"fmt"
     5  	"math"
     6  	"testing"
     7  
     8  	"github.com/bananabytelabs/wazero/internal/bitpack"
     9  	"github.com/bananabytelabs/wazero/internal/testing/require"
    10  )
    11  
    12  func TestOffsetArray(t *testing.T) {
    13  	tests := [][]uint64{
    14  		{},
    15  		{0},
    16  		{1, 2, 3, 4, 5, 6, 7, 8, 9},
    17  		{16: 1},
    18  		{17: math.MaxUint16 + 1},
    19  		{21: 10, 22: math.MaxUint16},
    20  		{0: 42, 100: math.MaxUint64},
    21  		{0: 42, 1: math.MaxUint32, 101: math.MaxUint64},
    22  	}
    23  
    24  	for _, test := range tests {
    25  		t.Run(fmt.Sprintf("len=%d", len(test)), func(t *testing.T) {
    26  			array := bitpack.NewOffsetArray(test)
    27  			require.Equal(t, len(test), array.Len())
    28  
    29  			for i, v := range test {
    30  				require.Equal(t, v, array.Index(i))
    31  			}
    32  		})
    33  	}
    34  }