Skip to content

Commit

Permalink
Avoid using more unexported constants in tests
Browse files Browse the repository at this point in the history
This commit avoids using maxInlineArrayElementSize in tests.
  • Loading branch information
fxamacker committed Jan 24, 2025
1 parent 284b10d commit be511dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions array_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
// setup
for i := 0; i < initialArraySize; i++ {
v := RandomValue(r)
storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)
totalRawDataSize += storable.ByteSize()
err = array.Append(v)
Expand All @@ -107,7 +107,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
for i := 0; i < numberOfElements; i++ {
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)

totalRawDataSize += storable.ByteSize()
Expand Down Expand Up @@ -143,7 +143,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
ind := r.Intn(int(array.Count()))
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)

totalRawDataSize += storable.ByteSize()
Expand Down Expand Up @@ -217,7 +217,7 @@ func benchmarkLongTermImpactOnMemory(b *testing.B, initialArraySize, numberOfOps
for i := 0; i < initialArraySize; i++ {
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)

totalRawDataSize += storable.ByteSize()
Expand All @@ -239,7 +239,7 @@ func benchmarkLongTermImpactOnMemory(b *testing.B, initialArraySize, numberOfOps
case 1: // insert
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)

totalRawDataSize += storable.ByteSize()
Expand Down
36 changes: 18 additions & 18 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ func TestArraySetRandomValues(t *testing.T) {

for i := uint64(0); i < arraySize; i++ {
oldValue := values[i]
newValue := randomValue(r, int(maxInlineArrayElementSize))
newValue := randomValue(r, int(MaxInlineArrayElementSize()))
values[i] = newValue

existingStorable, err := array.Set(i, newValue)
Expand Down Expand Up @@ -2490,7 +2490,7 @@ func TestArrayInsertRandomValues(t *testing.T) {

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values[arraySize-i-1] = v

err := array.Insert(0, v)
Expand All @@ -2515,7 +2515,7 @@ func TestArrayInsertRandomValues(t *testing.T) {

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values[i] = v

err := array.Insert(i, v)
Expand All @@ -2541,7 +2541,7 @@ func TestArrayInsertRandomValues(t *testing.T) {
values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
k := r.Intn(int(i) + 1)
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))

copy(values[k+1:], values[k:])
values[k] = v
Expand Down Expand Up @@ -2573,7 +2573,7 @@ func TestArrayRemoveRandomValues(t *testing.T) {
values := make([]Value, arraySize)
// Insert n random values into array
for i := uint64(0); i < arraySize; i++ {
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values[i] = v

err := array.Insert(i, v)
Expand Down Expand Up @@ -2640,15 +2640,15 @@ func testArrayAppendSetInsertRemoveRandomValues(
switch nextOp {

case ArrayAppendOp:
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values = append(values, v)

err := array.Append(v)
require.NoError(t, err)

case ArraySetOp:
k := r.Intn(int(array.Count()))
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))

oldV := values[k]

Expand All @@ -2668,7 +2668,7 @@ func testArrayAppendSetInsertRemoveRandomValues(

case ArrayInsertOp:
k := r.Intn(int(array.Count() + 1))
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))

if k == int(array.Count()) {
values = append(values, v)
Expand Down Expand Up @@ -4457,7 +4457,7 @@ func TestArrayStringElement(t *testing.T) {

r := newRand(t)

stringSize := int(maxInlineArrayElementSize - 3)
stringSize := int(MaxInlineArrayElementSize() - 3)

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
Expand Down Expand Up @@ -4490,7 +4490,7 @@ func TestArrayStringElement(t *testing.T) {

r := newRand(t)

stringSize := int(maxInlineArrayElementSize + 512)
stringSize := int(MaxInlineArrayElementSize() + 512)

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
Expand Down Expand Up @@ -4787,7 +4787,7 @@ func TestArrayFromBatchData(t *testing.T) {
var values []Value
var v Value

v = NewStringValue(strings.Repeat("a", int(maxInlineArrayElementSize-2)))
v = NewStringValue(strings.Repeat("a", int(MaxInlineArrayElementSize()-2)))
values = append(values, v)

err = array.Insert(0, v)
Expand Down Expand Up @@ -4843,7 +4843,7 @@ func TestArrayFromBatchData(t *testing.T) {
require.NoError(t, err)
}

v = NewStringValue(strings.Repeat("a", int(maxInlineArrayElementSize-2)))
v = NewStringValue(strings.Repeat("a", int(MaxInlineArrayElementSize()-2)))
values = append(values, nil)
copy(values[25+1:], values[25:])
values[25] = v
Expand Down Expand Up @@ -4890,7 +4890,7 @@ func TestArrayFromBatchData(t *testing.T) {

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values[i] = v

err := array.Append(v)
Expand Down Expand Up @@ -4939,17 +4939,17 @@ func TestArrayFromBatchData(t *testing.T) {
var values []Value
var v Value

v = NewStringValue(randStr(r, int(maxInlineArrayElementSize-2)))
v = NewStringValue(randStr(r, int(MaxInlineArrayElementSize()-2)))
values = append(values, v)
err = array.Append(v)
require.NoError(t, err)

v = NewStringValue(randStr(r, int(maxInlineArrayElementSize-2)))
v = NewStringValue(randStr(r, int(MaxInlineArrayElementSize()-2)))
values = append(values, v)
err = array.Append(v)
require.NoError(t, err)

v = NewStringValue(randStr(r, int(maxInlineArrayElementSize-2)))
v = NewStringValue(randStr(r, int(MaxInlineArrayElementSize()-2)))
values = append(values, v)
err = array.Append(v)
require.NoError(t, err)
Expand Down Expand Up @@ -5016,7 +5016,7 @@ func TestArrayMaxInlineElement(t *testing.T) {
var values []Value
for i := 0; i < 2; i++ {
// String length is MaxInlineArrayElementSize - 3 to account for string encoding overhead.
v := NewStringValue(randStr(r, int(maxInlineArrayElementSize-3)))
v := NewStringValue(randStr(r, int(MaxInlineArrayElementSize()-3)))
values = append(values, v)

err = array.Append(v)
Expand Down Expand Up @@ -5139,7 +5139,7 @@ func TestArraySlabDump(t *testing.T) {
array, err := NewArray(storage, address, typeInfo)
require.NoError(t, err)

err = array.Append(NewStringValue(strings.Repeat("a", int(maxInlineArrayElementSize))))
err = array.Append(NewStringValue(strings.Repeat("a", int(MaxInlineArrayElementSize()))))
require.NoError(t, err)

want := []string{
Expand Down

0 comments on commit be511dd

Please sign in to comment.