-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1951 from mtrmac/set-pointer
Use a pointer receiver for internal/set.Set
- Loading branch information
Showing
2 changed files
with
68 additions
and
2 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
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,66 @@ | ||
package set | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
s := New[int]() | ||
assert.True(t, s.Empty()) | ||
} | ||
|
||
func TestNewWithValues(t *testing.T) { | ||
s := NewWithValues(1, 3) | ||
assert.True(t, s.Contains(1)) | ||
assert.False(t, s.Contains(2)) | ||
assert.True(t, s.Contains(3)) | ||
} | ||
|
||
func TestAdd(t *testing.T) { | ||
s := NewWithValues(1) | ||
assert.False(t, s.Contains(2)) | ||
s.Add(2) | ||
assert.True(t, s.Contains(2)) | ||
s.Add(2) // Adding an already-present element | ||
assert.True(t, s.Contains(2)) | ||
// Unrelated elements are unaffected | ||
assert.True(t, s.Contains(1)) | ||
assert.False(t, s.Contains(3)) | ||
} | ||
|
||
func TestDelete(t *testing.T) { | ||
s := NewWithValues(1, 2) | ||
assert.True(t, s.Contains(2)) | ||
s.Delete(2) | ||
assert.False(t, s.Contains(2)) | ||
s.Delete(2) // Deleting a missing element | ||
assert.False(t, s.Contains(2)) | ||
// Unrelated elements are unaffected | ||
assert.True(t, s.Contains(1)) | ||
} | ||
|
||
func TestContains(t *testing.T) { | ||
s := NewWithValues(1, 2) | ||
assert.True(t, s.Contains(1)) | ||
assert.True(t, s.Contains(2)) | ||
assert.False(t, s.Contains(3)) | ||
} | ||
|
||
func TestEmpty(t *testing.T) { | ||
s := New[int]() | ||
assert.True(t, s.Empty()) | ||
s.Add(1) | ||
assert.False(t, s.Empty()) | ||
s.Delete(1) | ||
assert.True(t, s.Empty()) | ||
} | ||
|
||
func TestValues(t *testing.T) { | ||
s := New[int]() | ||
assert.Empty(t, s.Values()) | ||
s.Add(1) | ||
s.Add(2) | ||
assert.ElementsMatch(t, []int{1, 2}, s.Values()) | ||
} |