test(tests): assert D25 property coverage, leader endpoints, no button off screen
This commit is contained in:
1 parent
ec2a595d56
commit
760a4bf7e1
1 file changed
+12
-1
@@ -84,6 +84,7 @@ describe('placeAccessLabels', () => {
|
||||
const out = run(one({ x: 500, y: 100, w: 60, h: 40 }, 50))
|
||||
expect(out.placed).toEqual([])
|
||||
expect(out.overflow).toEqual([])
|
||||
expect(out.button).toBeNull()
|
||||
})
|
||||
|
||||
it('caps a long name at the maximum width', () => {
|
||||
@@ -175,6 +176,8 @@ const cross = (s: Segment, t: Segment) => {
|
||||
return turn(p, q, a) * turn(p, q, b) < 0 && turn(a, b, p) * turn(a, b, q) < 0
|
||||
}
|
||||
function leaderHitsBox(s: Segment, b: Box): boolean {
|
||||
const within = (x: number, y: number) => x > b.x && x < b.x + b.w && y > b.y && y < b.y + b.h
|
||||
if (within(s.x1, s.y1) || within(s.x2, s.y2)) return true
|
||||
const c = [[b.x, b.y], [b.x + b.w, b.y], [b.x + b.w, b.y + b.h], [b.x, b.y + b.h]]
|
||||
const edges = c.map((v, i) => ({ x1: v[0], y1: v[1], x2: c[(i + 1) % 4][0], y2: c[(i + 1) % 4][1] }))
|
||||
return edges.some((e) => cross(s, e))
|
||||
@@ -206,9 +209,17 @@ function checkInvariants(input: ReturnType<typeof randomInput>, out: LabelLayout
|
||||
describe('placeAccessLabels invariants', () => {
|
||||
it('holds on 2000 seeded random layouts', () => {
|
||||
const r = rng(20261122)
|
||||
const seen = { leader: 0, overflow: 0, button: 0 }
|
||||
for (let i = 0; i < 2000; i++) {
|
||||
const input = randomInput(r)
|
||||
checkInvariants(input, placeAccessLabels({ ...input, button: BUTTON }))
|
||||
const out = placeAccessLabels({ ...input, button: BUTTON })
|
||||
checkInvariants(input, out)
|
||||
if (out.placed.some((p) => p.leader !== null)) seen.leader++
|
||||
if (out.overflow.length > 0) seen.overflow++
|
||||
if (out.button !== null) seen.button++
|
||||
}
|
||||
expect(seen.leader).toBeGreaterThan(0)
|
||||
expect(seen.overflow).toBeGreaterThan(0)
|
||||
expect(seen.button).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user