robocar-throttle/pkg/throttle/processor_test.go

90 lines
1.6 KiB
Go
Raw Normal View History

package throttle
2022-09-05 13:30:26 +00:00
import (
"github.com/cyrilix/robocar-throttle/pkg/types"
"testing"
)
func TestSteeringProcessor_Process(t *testing.T) {
type fields struct {
2022-09-05 13:30:26 +00:00
minThrottle types.Throttle
maxThrottle types.Throttle
}
type args struct {
steering float32
}
tests := []struct {
name string
fields fields
args args
2022-09-05 13:30:26 +00:00
want types.Throttle
}{
{
name: "steering straight",
fields: fields{
minThrottle: 0.2,
maxThrottle: 0.5,
},
args: args{
steering: 0.,
},
want: 0.5,
},
{
name: "steering full left should return min throttle",
fields: fields{
minThrottle: 0.2,
maxThrottle: 0.5,
},
args: args{
steering: -1.,
},
want: 0.2,
},
{
name: "steering full right should return min throttle",
fields: fields{
minThrottle: 0.2,
maxThrottle: 0.5,
},
args: args{
steering: 1.,
},
want: 0.2,
},
{
name: "steering mid-left should return intermediate throttle",
fields: fields{
minThrottle: 0.3,
maxThrottle: 0.5,
},
args: args{
steering: -0.5,
},
want: 0.4,
},
{
name: "steering mid-right should return intermediate throttle",
fields: fields{
minThrottle: 0.3,
maxThrottle: 0.5,
},
args: args{
steering: 0.5,
},
want: 0.4,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sp := &SteeringProcessor{
minThrottle: tt.fields.minThrottle,
maxThrottle: tt.fields.maxThrottle,
}
if got := sp.Process(tt.args.steering); got != tt.want {
t.Errorf("Process() = %v, want %v", got, tt.want)
}
})
}
}