- 将现有练习及 module 文件迁移至 go/practice,保持代码和依赖不变 - 新增 go/projects 项目区说明,更新目录约定与开发命令 BREAKING CHANGE: Go 练习命令需改在 go/practice 目录下执行
19 lines
340 B
Go
19 lines
340 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func appendSlice(s []int, n int) {
|
|
s = append(s, n)
|
|
fmt.Printf("len=%d,cap=%d\n", len(s), cap(s))
|
|
}
|
|
func TestSliceAppend(t *testing.T) {
|
|
s1 := make([]int, 5)
|
|
appendSlice(s1, 10)
|
|
if len(s1) != 5 || cap(s1) != 5 {
|
|
t.Errorf("Expected len=5, cap=5; got len=%d, cap=%d", len(s1), cap(s1))
|
|
}
|
|
}
|