80 lines
1.7 KiB
Go
80 lines
1.7 KiB
Go
package day9
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.bizdoc.ro/private/devkit.git/collections/geometry/v2"
|
|
)
|
|
|
|
func Test_intersect(t *testing.T) {
|
|
type args struct {
|
|
A geometry.Point
|
|
B geometry.Point
|
|
C geometry.Point
|
|
D geometry.Point
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want bool
|
|
}{
|
|
{
|
|
name: "no intersection",
|
|
want: false,
|
|
args: args{
|
|
A: geometry.Point{Line: 3, Col: 3},
|
|
B: geometry.Point{Line: 3, Col: 10},
|
|
C: geometry.Point{Line: 4, Col: 5},
|
|
D: geometry.Point{Line: 4, Col: 10},
|
|
},
|
|
},
|
|
{
|
|
name: "intersection",
|
|
want: true,
|
|
args: args{
|
|
A: geometry.Point{Line: 3, Col: 3},
|
|
B: geometry.Point{Line: 3, Col: 10},
|
|
C: geometry.Point{Line: 2, Col: 5},
|
|
D: geometry.Point{Line: 4, Col: 5},
|
|
},
|
|
},
|
|
{
|
|
name: "on the edge",
|
|
want: false,
|
|
args: args{
|
|
A: geometry.Point{Line: 3, Col: 3},
|
|
B: geometry.Point{Line: 3, Col: 10},
|
|
C: geometry.Point{Line: 3, Col: 3},
|
|
D: geometry.Point{Line: 3, Col: 10},
|
|
},
|
|
},
|
|
//{
|
|
// name: "on the edge but overflow",
|
|
// want: false,
|
|
// args: args{
|
|
// A: geometry.Point{Line: 3, Col: 3},
|
|
// B: geometry.Point{Line: 3, Col: 10},
|
|
// C: geometry.Point{Line: 3, Col: 3},
|
|
// D: geometry.Point{Line: 3, Col: 11},
|
|
// },
|
|
//},
|
|
//{
|
|
// name: "corner",
|
|
// want: false,
|
|
// args: args{
|
|
// A: geometry.Point{Line: 3, Col: 2},
|
|
// B: geometry.Point{Line: 3, Col: 9},
|
|
// C: geometry.Point{Line: 5, Col: 2},
|
|
// D: geometry.Point{Line: 3, Col: 2},
|
|
// },
|
|
//},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := intersect(tt.args.A, tt.args.B, tt.args.C, tt.args.D); got != tt.want {
|
|
t.Errorf("intersect() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|