adding to git.i0t.app
This commit is contained in:
35
internal/compositor/compositor_test.go
Normal file
35
internal/compositor/compositor_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package compositor
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGridRectsCoverExactly(t *testing.T) {
|
||||
cases := []struct {
|
||||
w, h, cols, rows int
|
||||
}{
|
||||
{1920, 1080, 2, 2},
|
||||
{1920, 1080, 3, 3},
|
||||
{1920, 1080, 1, 1},
|
||||
{1366, 768, 3, 2}, // odd dimensions to exercise remainder handling
|
||||
}
|
||||
for _, tc := range cases {
|
||||
rects := GridRects(tc.w, tc.h, tc.cols, tc.rows)
|
||||
if len(rects) != tc.cols*tc.rows {
|
||||
t.Fatalf("%dx%d grid %dx%d: got %d rects", tc.w, tc.h, tc.cols, tc.rows, len(rects))
|
||||
}
|
||||
// Sum of areas must equal the whole output with no gaps or overlap on
|
||||
// the axis boundaries: verify the last column reaches the right edge
|
||||
// and the last row reaches the bottom edge.
|
||||
last := rects[len(rects)-1]
|
||||
if last.X+last.W != tc.w {
|
||||
t.Errorf("%dx%d grid %dx%d: last cell right edge %d != %d", tc.w, tc.h, tc.cols, tc.rows, last.X+last.W, tc.w)
|
||||
}
|
||||
if last.Y+last.H != tc.h {
|
||||
t.Errorf("%dx%d grid %dx%d: last cell bottom edge %d != %d", tc.w, tc.h, tc.cols, tc.rows, last.Y+last.H, tc.h)
|
||||
}
|
||||
for i, r := range rects {
|
||||
if r.W <= 0 || r.H <= 0 {
|
||||
t.Errorf("cell %d has non-positive size %+v", i, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user