I'm trying to implement a test in GO. But I'm struggling with the list's syntax inside the struct.
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)
}
}
}
The output error I have is:
expected ']', found ','
: expected operand, found '{'
: expected ';', found 'for'
I appreciate your help. Thanks.
Aucun commentaire:
Enregistrer un commentaire