Skip to content

Commit

Permalink
add: slice insert index 0
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatDiscovery committed Nov 5, 2024
1 parent 0447b58 commit 313d216
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/basic/collection/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/go-playground/assert/v2"
"sort"
"testing"
)
Expand Down Expand Up @@ -86,3 +87,13 @@ func TestSlice(t *testing.T) {
cutSlice := testCase[2]
fmt.Printf("cutSlice=%v", cutSlice)
}

// 在切片前面添加新元素
func TestInsertIndex0(t *testing.T) {
original := []int{2, 3, 4}
newElement := 1

updated := append([]int{newElement}, original...)
assert.Equal(t, updated, []int{1, 2, 3, 4})
fmt.Println(updated) // 输出: [1 2 3 4]
}

0 comments on commit 313d216

Please sign in to comment.