Slide 10
Slide 10 text
4VC5FTU
func TestJanken(t *testing.T) {
tests := []struct {
name string
user, computer Hand
want Result
}{
{"RockEven", Rock, Rock, Even},
{"RockLose", Rock, Paper, Lose},
{"RockWin", Rock, Scissors, Win},
…
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Janken(tt.user, tt.computer)
if got != tt.want {
t.Errorf("%v, want %v", got, tt.want)
}
})
}
}
=== RUN TestJanken
=== RUN TestJanken/RockEven
=== RUN TestJanken/RockLose
=== RUN TestJanken/RockWin
--- PASS: TestJanken (0.00s)
--- PASS: TestJanken/RockEven (0.00s)
--- PASS: TestJanken/RockLose (0.00s)
--- PASS: TestJanken/RockWin (0.00s)
PASS
All tests passed.