Skip to content

Commit

Permalink
Add test for HSplitCellsReversed
Browse files Browse the repository at this point in the history
  • Loading branch information
spacez320 committed Mar 7, 2024
1 parent 275c62f commit 610a070
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions private/area/area_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 610a070

Please sign in to comment.