Skip to content

Instantly share code, notes, and snippets.

@wahyuoi
Created March 30, 2021 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wahyuoi/c08d7e88c950f7884f928b1b27471a26 to your computer and use it in GitHub Desktop.
Save wahyuoi/c08d7e88c950f7884f928b1b27471a26 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"testing"
)
func Test_slice(t *testing.T) {
arr := make([]int, 0)
for i := 0; i < 10; i++ {
arr = append(arr, i)
}
offset := 0
limit := 5
start := offset
end := limit + offset -1
sliced := arr[start:end]
fmt.Printf("%d %d\n", start, end)
fmt.Printf("%v\n", sliced)
if len(sliced) != limit {
t.Fail()
}
}
@wahyuoi
Copy link
Author

wahyuoi commented Mar 30, 2021

Line 18 should be end := limit + offset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment