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