We have reverse.go where the function Reverse is described. We create reverse_test.go file:
reverse.go
Reverse
reverse_test.go
package main import ( "testing" ) func TestReverse(t *testing.T) { testcases := []struct { in, want string }{ {"Hello, world", "dlrow ,olleH"}, {" ", " "}, {"!12345", "54321!"}, } for _, tc := range testcases { rev := Reverse(tc.in) if rev != tc.want { t.Errorf("Reverse: %q, want %q", rev, tc.want) } } }
Run code:
$ go test
Last updated 2 years ago