comments update for package gstr (#3233)

This commit is contained in:
John Guo
2024-01-02 20:16:51 +08:00
committed by GitHub
parent 4876ae0e2b
commit 6abd8bd864
8 changed files with 139 additions and 26 deletions

View File

@ -173,7 +173,11 @@ func (a *IntArray) InsertBefore(index int, values ...int) error {
a.mu.Lock()
defer a.mu.Unlock()
if index < 0 || index >= len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
return gerror.NewCodef(
gcode.CodeInvalidParameter,
"index %d out of array range %d",
index, len(a.array),
)
}
rear := append([]int{}, a.array[index:]...)
a.array = append(a.array[0:index], values...)
@ -186,7 +190,11 @@ func (a *IntArray) InsertAfter(index int, values ...int) error {
a.mu.Lock()
defer a.mu.Unlock()
if index < 0 || index >= len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
return gerror.NewCodef(
gcode.CodeInvalidParameter,
"index %d out of array range %d",
index, len(a.array),
)
}
rear := append([]int{}, a.array[index+1:]...)
a.array = append(a.array[0:index+1], values...)
@ -583,7 +591,11 @@ func (a *IntArray) Fill(startIndex int, num int, value int) error {
a.mu.Lock()
defer a.mu.Unlock()
if startIndex < 0 || startIndex > len(a.array) {
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", startIndex, len(a.array))
return gerror.NewCodef(
gcode.CodeInvalidParameter,
"index %d out of array range %d",
startIndex, len(a.array),
)
}
for i := startIndex; i < startIndex+num; i++ {
if i > len(a.array)-1 {

View File

@ -75,7 +75,8 @@ func TestQueue_Close(t *testing.T) {
q1 := gqueue.New()
q1.Push(1)
q1.Push(2)
time.Sleep(time.Millisecond)
// wait sync to channel
time.Sleep(10 * time.Millisecond)
t.Assert(q1.Len(), 2)
q1.Close()
})
@ -83,7 +84,8 @@ func TestQueue_Close(t *testing.T) {
q1 := gqueue.New(2)
q1.Push(1)
q1.Push(2)
time.Sleep(time.Millisecond)
// wait sync to channel
time.Sleep(10 * time.Millisecond)
t.Assert(q1.Len(), 2)
q1.Close()
})