package road import ( "github.com/cyrilix/robocar-protobuf/go/events" "gocv.io/x/gocv" "reflect" "testing" ) func TestDetector_Detect(t *testing.T) { type fields struct { } type args struct { imgName string } tests := []struct { name string fields fields args args want []*events.Point }{ { name: "Straight ahead", fields: fields{}, args: args{imgName: "testdata/input.jpg"}, want: []*events.Point{{X: 2, Y: 53}, {X: 48, Y: 37}, {X: 54, Y: 27}, {X: 72, Y: 26}, {X: 156, Y: 55}, {X: 159, Y: 118}, {X: 20, Y: 114}, {X: 3, Y: 119}}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { d := NewDetector() defer d.Close() img := gocv.IMRead(tt.args.imgName, gocv.IMReadColor) defer func(img *gocv.Mat) { err := img.Close() if err != nil { t.Errorf("unable to close image: %v", err) } }(&img) if img.Empty() { t.Errorf("unable to open image %v", tt.args.imgName) t.Fail() } if got, _ := d.Detect(&img); !reflect.DeepEqual(got, tt.want) { t.Errorf("Detect() = %v, want %v", got, tt.want) } }) } }