1 Star 0 Fork 0

Lucius_Van/core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
table_test.go 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
package core
import (
"strings"
"testing"
)
var testsGetColumn = []struct {
name string
idx int
}{
{"Id", 0},
{"Deleted", 0},
{"Caption", 0},
{"Code_1", 0},
{"Code_2", 0},
{"Code_3", 0},
{"Parent_Id", 0},
{"Latitude", 0},
{"Longitude", 0},
}
var table *Table
func init() {
table = NewEmptyTable()
var name string
for i := 0; i < len(testsGetColumn); i++ {
// as in Table.AddColumn func
name = strings.ToLower(testsGetColumn[i].name)
table.columnsMap[name] = append(table.columnsMap[name], &Column{})
}
}
func TestGetColumn(t *testing.T) {
for _, test := range testsGetColumn {
if table.GetColumn(test.name) == nil {
t.Error("Column not found!")
}
}
}
func TestGetColumnIdx(t *testing.T) {
for _, test := range testsGetColumn {
if table.GetColumnIdx(test.name, test.idx) == nil {
t.Errorf("Column %s with idx %d not found!", test.name, test.idx)
}
}
}
func BenchmarkGetColumnWithToLower(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range testsGetColumn {
if _, ok := table.columnsMap[strings.ToLower(test.name)]; !ok {
b.Errorf("Column not found:%s", test.name)
}
}
}
}
func BenchmarkGetColumnIdxWithToLower(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range testsGetColumn {
if c, ok := table.columnsMap[strings.ToLower(test.name)]; ok {
if test.idx < len(c) {
continue
} else {
b.Errorf("Bad idx in: %s, %d", test.name, test.idx)
}
} else {
b.Errorf("Column not found: %s, %d", test.name, test.idx)
}
}
}
}
func BenchmarkGetColumn(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range testsGetColumn {
if table.GetColumn(test.name) == nil {
b.Errorf("Column not found:%s", test.name)
}
}
}
}
func BenchmarkGetColumnIdx(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, test := range testsGetColumn {
if table.GetColumnIdx(test.name, test.idx) == nil {
b.Errorf("Column not found:%s, %d", test.name, test.idx)
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/leuyius/core.git
git@gitee.com:leuyius/core.git
leuyius
core
core
master

搜索帮助