robocar-base/mode/mode_test.go

41 lines
742 B
Go
Raw Normal View History

2019-11-30 20:49:19 +00:00
package mode
import "testing"
func TestToString(t *testing.T) {
cases := []struct{
value DriveMode
expected string
}{
{DriveModeUser, "user"},
{DriveModePilot, "pilot"},
{DriveModeInvalid, ""},
}
for _, c := range cases{
val := ToString(c.value)
if val != c.expected{
t.Errorf("ToString(%v): %v, wants %v", c.value, val, c.expected)
}
}
}
func TestParseString(t *testing.T) {
cases := []struct{
value string
expected DriveMode
}{
{"user", DriveModeUser},
{"pilot",DriveModePilot},
{"", DriveModeInvalid},
{"invalid", DriveModeInvalid},
}
for _, c := range cases{
val := ParseString(c.value)
if val != c.expected{
t.Errorf("ParseString(%v): %v, wants %v", c.value, val, c.expected)
}
}
}