90 lines
1.6 KiB
Go
90 lines
1.6 KiB
Go
package throttle
|
|
|
|
import (
|
|
"github.com/cyrilix/robocar-throttle/pkg/types"
|
|
"testing"
|
|
)
|
|
|
|
func TestSteeringProcessor_Process(t *testing.T) {
|
|
type fields struct {
|
|
minThrottle types.Throttle
|
|
maxThrottle types.Throttle
|
|
}
|
|
type args struct {
|
|
steering float32
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|