Skip to content

Commit

Permalink
add test for creating map when zero size is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
semihbkgr committed Dec 18, 2023
1 parent 249e2f6 commit 33dd687
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ func TestMapCreation(t *testing.T) {
if m.Len() != 0 {
t.Errorf("new map should be empty but has %d items.", m.Len())
}

t.Run("default size is used when zero is provided", func(t *testing.T) {
m := New[int, int](0)
index := m.metadata.Load().index
if len(index) != defaultSize {
t.Error("map index size is not as expected")
}
})
}

func TestOverwrite(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion map.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type (
func New[K hashable, V any](size ...uintptr) *Map[K, V] {
m := &Map[K, V]{listHead: newListHead[K, V]()}
m.numItems.Store(0)
if len(size) > 0 && size[0] > 0 {
if len(size) > 0 && size[0] != 0 {
m.allocate(size[0])
} else {
m.allocate(defaultSize)
Expand Down

0 comments on commit 33dd687

Please sign in to comment.