package world import ( "testing" "github.com/stretchr/testify/require" ) func TestTakeCatchUpRects_RespectsAreaLimit(t *testing.T) { t.Parallel() pending := []RectPx{ {X: 0, Y: 0, W: 10, H: 1}, // area 10 {X: 0, Y: 1, W: 10, H: 2}, // area 20 {X: 0, Y: 3, W: 10, H: 3}, // area 30 } // Limit 25 => should take first (10) + second (20) would exceed => take only first. sel, rem := takeCatchUpRects(pending, 25) require.Equal(t, []RectPx{{X: 0, Y: 0, W: 10, H: 1}}, sel) require.Equal(t, []RectPx{ {X: 0, Y: 1, W: 10, H: 2}, {X: 0, Y: 3, W: 10, H: 3}, }, rem) // Limit 30 => can take first(10) + second(20) exactly. sel, rem = takeCatchUpRects(pending, 30) require.Equal(t, []RectPx{ {X: 0, Y: 0, W: 10, H: 1}, {X: 0, Y: 1, W: 10, H: 2}, }, sel) require.Equal(t, []RectPx{{X: 0, Y: 3, W: 10, H: 3}}, rem) // No limit => take all. sel, rem = takeCatchUpRects(pending, 0) require.Len(t, sel, 3) require.Empty(t, rem) }