-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
- Loading branch information
1 parent
965f793
commit 4d84665
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package descriptor | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tetratelabs/wazero/internal/testing/require" | ||
) | ||
|
||
func Test_sizeOfTable(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
operation func(*Table[int32, string]) | ||
expectedSize int | ||
}{ | ||
{ | ||
name: "empty table", | ||
operation: func(table *Table[int32, string]) {}, | ||
expectedSize: 0, | ||
}, | ||
{ | ||
name: "1 insert", | ||
operation: func(table *Table[int32, string]) { | ||
table.Insert("a") | ||
}, | ||
expectedSize: 1, | ||
}, | ||
{ | ||
name: "32 inserts", | ||
operation: func(table *Table[int32, string]) { | ||
for i := 0; i < 32; i++ { | ||
table.Insert("a") | ||
} | ||
}, | ||
expectedSize: 1, | ||
}, | ||
{ | ||
name: "257 inserts", | ||
operation: func(table *Table[int32, string]) { | ||
for i := 0; i < 257; i++ { | ||
table.Insert("a") | ||
} | ||
}, | ||
expectedSize: 5, | ||
}, | ||
{ | ||
name: "1 insert at 63", | ||
operation: func(table *Table[int32, string]) { | ||
table.InsertAt("a", 63) | ||
}, | ||
expectedSize: 1, | ||
}, | ||
{ | ||
name: "1 insert at 64", | ||
operation: func(table *Table[int32, string]) { | ||
table.InsertAt("a", 64) | ||
}, | ||
expectedSize: 2, | ||
}, | ||
{ | ||
name: "1 insert at 257", | ||
operation: func(table *Table[int32, string]) { | ||
table.InsertAt("a", 257) | ||
}, | ||
expectedSize: 5, | ||
}, | ||
{ | ||
name: "insert at until 320", | ||
operation: func(table *Table[int32, string]) { | ||
for i := int32(0); i < 320; i++ { | ||
table.InsertAt("a", i) | ||
} | ||
}, | ||
expectedSize: 5, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tc := tt | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
table := new(Table[int32, string]) | ||
tc.operation(table) | ||
require.Equal(t, tc.expectedSize, len(table.masks)) | ||
require.Equal(t, tc.expectedSize*64, len(table.items)) | ||
}) | ||
} | ||
} |