Ai
1 Star 0 Fork 0

鹏程/studygolang

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
convert_test.go 825 Bytes
一键复制 编辑 原始数据 按行查看 历史
xuxinhua 提交于 2017-06-20 14:44 +08:00 . gofmt -s
// Copyright 2016 The StudyGolang Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// http://studygolang.com
// Author: polaris polaris@studygolang.com
package util_test
import (
"testing"
. "util"
)
type model struct {
Id int
Name string
}
func TestModels2Intslice(t *testing.T) {
models := []*model{
{12, "polaris"},
{13, "xuxinhua"},
}
actualResult := Models2Intslice(models, "Id")
expectResult := []int{12, 13}
if !sliceIsEqual(actualResult, expectResult) {
t.Fatalf("expect:%v, actual:%v", expectResult, actualResult)
}
}
func sliceIsEqual(slice1, slice2 []int) bool {
if len(slice1) != len(slice2) {
return false
}
for i, v := range slice1 {
if v != slice2[i] {
return false
}
}
return true
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/barry_zpc/studygolang.git
git@gitee.com:barry_zpc/studygolang.git
barry_zpc
studygolang
studygolang
master

搜索帮助