Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/areyouinorout-unittest' into are…
Browse files Browse the repository at this point in the history
…youinorout

# Conflicts:
#	snap/snap.go
  • Loading branch information
roelarents committed Feb 15, 2024
2 parents 2e31eef + b6dc854 commit 0813b0d
Showing 1 changed file with 126 additions and 8 deletions.
134 changes: 126 additions & 8 deletions snap/snap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,23 +733,123 @@ func Test_dedupeInnersOuters(t *testing.T) {
wantOuters [][][2]float64
wantInners [][][2]float64
}{
{
name: "#outer, #inner = 0, 0",
args: args{
outers: squareRingArray(0, true),
inners: squareRingArray(0, false),
},
wantOuters: squareRingArray(0, true),
wantInners: squareRingArray(0, false),
},
{
name: "#outer, #inner = 1, 0",
args: args{
outers: [][][2]float64{{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}, // square, counter clockwise
inners: [][][2]float64{{{}}},
outers: squareRingArray(1, true),
inners: squareRingArray(0, false),
},
wantOuters: [][][2]float64{{{0, 0}, {1, 0}, {1, 1}, {0, 1}}},
wantInners: [][][2]float64{{{}}},
wantOuters: squareRingArray(1, true),
wantInners: squareRingArray(0, false),
},
{
name: "#outer, #inner = 1, 1",
args: args{
outers: [][][2]float64{{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}, // square, counter clockwise
inners: [][][2]float64{{{0, 0}, {0, 1}, {1, 1}, {1, 0}}}, // square, clockwise
outers: squareRingArray(1, true),
inners: squareRingArray(1, false),
},
wantOuters: squareRingArray(1, true),
wantInners: squareRingArray(1, false),
},
{
name: "#outer, #inner = 2, 1",
args: args{
outers: squareRingArray(2, true),
inners: squareRingArray(1, false),
},
wantOuters: squareRingArray(1, true),
wantInners: squareRingArray(0, false),
},
{
name: "#outer, #inner = 2, 2",
args: args{
outers: squareRingArray(2, true),
inners: squareRingArray(2, false),
},
wantOuters: squareRingArray(1, true),
wantInners: squareRingArray(1, false),
},
{
name: "#outer, #inner = 0, 1",
args: args{
outers: squareRingArray(0, true),
inners: squareRingArray(1, false),
},
wantOuters: squareRingArray(0, true),
wantInners: squareRingArray(1, false),
},
{
name: "#outer, #inner = 1, 2",
args: args{
outers: squareRingArray(1, true),
inners: squareRingArray(2, false),
},
wantOuters: squareRingArray(0, true),
wantInners: squareRingArray(1, false),
},
{
name: "#outer, #inner = 2, 0",
args: args{
outers: squareRingArray(2, true),
inners: squareRingArray(0, false),
},
wantOuters: [][][2]float64{{{0, 0}, {1, 0}, {1, 1}, {0, 1}}},
wantInners: [][][2]float64{{{0, 0}, {0, 1}, {1, 1}, {1, 0}}},
wantOuters: squareRingArray(2, true),
wantInners: squareRingArray(0, false),
},
{
name: "#outer, #inner = 0, 2",
args: args{
outers: squareRingArray(0, true),
inners: squareRingArray(2, false),
},
wantOuters: squareRingArray(0, true),
wantInners: squareRingArray(2, false),
},
{
name: "#outer, #inner = 3, 1",
args: args{
outers: squareRingArray(3, true),
inners: squareRingArray(1, false),
},
wantOuters: squareRingArray(2, true),
wantInners: squareRingArray(0, false),
},
{
name: "#outer, #inner = 1, 3",
args: args{
outers: squareRingArray(1, true),
inners: squareRingArray(3, false),
},
wantOuters: squareRingArray(0, true),
wantInners: squareRingArray(2, false),
},
// add different ring, which should be left alone
{
name: "#outer, #inner = 1, 1 + dummy ring",
args: args{
outers: squareRingArray(1, true),
inners: append(squareRingArray(1, false), [][2]float64{{0, 0}, {1, 0}, {2, 1}}),
},
wantOuters: squareRingArray(1, true),
wantInners: append(squareRingArray(1, false), [][2]float64{{0, 0}, {1, 0}, {2, 1}}),
},
{
name: "#outer, #inner = 3, 1 + dummy ring",
args: args{
outers: squareRingArray(3, true),
inners: append(squareRingArray(1, false), [][2]float64{{0, 0}, {1, 0}, {2, 1}}),
},
wantOuters: squareRingArray(2, true),
wantInners: append(squareRingArray(0, false), [][2]float64{{0, 0}, {1, 0}, {2, 1}}),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -831,3 +931,21 @@ func wktMustEncode(g geom.Geometry) (s string) {
}
return s
}

func squareRingArray(number int, isOuter bool) [][][2]float64 {
outerSquare := [][2]float64{{0, 0}, {1, 0}, {1, 1}, {0, 1}} // square, counter clockwise
innerSquare := [][2]float64{{0, 0}, {0, 1}, {1, 1}, {1, 0}} // square, clockwise
var squares = [][][2]float64{}
var square [][2]float64
// outer or inner
if isOuter {
square = outerSquare
} else {
square = innerSquare
}
// add squares
for i := 0; i < number; i++ {
squares = append(squares, square)
}
return squares
}

0 comments on commit 0813b0d

Please sign in to comment.