我正在嘗試在GO中執行測試。但是我在結構中苦於列表的語法。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'
我感謝你的幫助。謝謝。
完美。謝謝。 – 2015-01-26 21:25:21