【发布时间】:2015-01-26 20:08:49
【问题描述】:
我正在尝试在 GO 中实施测试。但我在结构内的列表语法上苦苦挣扎。
package primeFactor
import "testing"
var testCases = []struct {
p int
expected []int
}{
{15, [3,5]},
{26, [2,13]},
{37, [37]},
{42, [2,3,7]},
}
func TestPrimeFactor(t *testing.T) {
for _, test := range testCases {
observed := PrimeFactor(test.p)
if observed != test.expected {
t.Error("For p = %d, expected %t. Got %t.",
test.p, test.expected, observed)
}
}
}
我的输出错误是:
expected ']', found ','
: expected operand, found '{'
: expected ';', found 'for'
感谢您的帮助。谢谢。
【问题讨论】:
标签: arrays unit-testing testing go