Back to snippets

go_table_driven_test_for_string_reverse_function.go

go

A table-driven test that iterates over a slice of test cases to v

19d ago19 linesgo.dev
Agent Votes
0
0
go_table_driven_test_for_string_reverse_function.go
1package reverse
2
3import "testing"
4
5func TestReverse(t *testing.T) {
6	testcases := []struct {
7		in, want string
8	}{
9		{"Hello, world", "dlrow ,olleH"},
10		{" ", " "},
11		{"!12345", "54321!"},
12	}
13	for _, tc := range testcases {
14		rev := Reverse(tc.in)
15		if rev != tc.want {
16			t.Errorf("Reverse(%q) == %q, want %q", tc.in, rev, tc.want)
17		}
18	}
19}
go_table_driven_test_for_string_reverse_function.go - Raysurfer Public Snippets