1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

List: add cap (#51)

Cap return cap of the inner data
This commit is contained in:
donutloop
2022-07-25 14:50:31 +02:00
committed by GitHub
parent 3d7600a9e4
commit c1b7500bcb
3 changed files with 48 additions and 0 deletions

View File

@@ -248,6 +248,11 @@ func (l *List[T]) Size() int {
return len(l.data)
}
// Cap return cap of the inner data
func (l *List[T]) Cap() int {
return cap(l.data)
}
// Swap the value of index i and j in list
func (l *List[T]) Swap(i, j int) {
size := len(l.data)

View File

@@ -261,6 +261,18 @@ func TestSize(t *testing.T) {
assert.Equal(0, empty.Size())
}
func TestCap(t *testing.T) {
assert := internal.NewAssert(t, "TestCap")
data := make([]int, 0, 100)
list := NewList(data)
assert.Equal(100, list.Cap())
data = make([]int, 0)
list = NewList(data)
assert.Equal(0, list.Cap())
}
func TestSwap(t *testing.T) {
assert := internal.NewAssert(t, "TestSwap")