Add test for HSplitCellsReversed

This commit is contained in:
Matthew Coleman 2024-03-07 17:26:16 -05:00
parent 275c62fc47
commit 610a070aab
1 changed files with 85 additions and 0 deletions

View File

@ -452,6 +452,91 @@ func TestHSplitCells(t *testing.T) {
}
}
func TestHSplitCellsReversed(t *testing.T) {
tests := []struct {
desc string
area image.Rectangle
cells int
wantTop image.Rectangle
wantBottom image.Rectangle
wantErr bool
}{
{
desc: "fails on negative cells",
area: image.Rect(1, 1, 2, 2),
cells: -1,
wantErr: true,
},
{
desc: "returns area as bottom on cells too large",
area: image.Rect(1, 1, 2, 2),
cells: 2,
wantTop: image.ZR,
wantBottom: image.Rect(1, 1, 2, 2),
},
{
desc: "returns area as bottom on cells equal area width",
area: image.Rect(1, 1, 2, 2),
cells: 1,
wantTop: image.ZR,
wantBottom: image.Rect(1, 1, 2, 2),
},
{
desc: "returns area as top on zero cells",
area: image.Rect(1, 1, 2, 2),
cells: 0,
wantBottom: image.ZR,
wantTop: image.Rect(1, 1, 2, 2),
},
{
desc: "zero area to begin with",
area: image.ZR,
cells: 0,
wantTop: image.ZR,
wantBottom: image.ZR,
},
{
desc: "splits area with even height",
area: image.Rect(1, 1, 3, 3),
cells: 1,
wantTop: image.Rect(1, 1, 3, 2),
wantBottom: image.Rect(1, 2, 3, 3),
},
{
desc: "splits area with odd width",
area: image.Rect(1, 1, 4, 4),
cells: 1,
wantTop: image.Rect(1, 1, 4, 3),
wantBottom: image.Rect(1, 3, 4, 4),
},
{
desc: "splits to unequal areas",
area: image.Rect(0, 0, 4, 4),
cells: 3,
wantTop: image.Rect(0, 0, 4, 1),
wantBottom: image.Rect(0, 1, 4, 4),
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
gotTop, gotBottom, err := HSplitCellsReversed(tc.area, tc.cells)
if (err != nil) != tc.wantErr {
t.Errorf("HSplitCells => unexpected error:%v, wantErr:%v", err, tc.wantErr)
}
if err != nil {
return
}
if diff := pretty.Compare(tc.wantTop, gotTop); diff != "" {
t.Errorf("HSplitCells => left value unexpected diff (-want, +got):\n%s", diff)
}
if diff := pretty.Compare(tc.wantBottom, gotBottom); diff != "" {
t.Errorf("HSplitCells => right value unexpected diff (-want, +got):\n%s", diff)
}
})
}
}
func TestExcludeBorder(t *testing.T) {
tests := []struct {
desc string