Spaces:
Running on Zero
Running on Zero
| from buddy_fusion.boxes import repair_boxes | |
| def test_repair_drops_non_finite_and_oversized(): | |
| raw = [ | |
| {"x": 0, "y": 0, "z": 0, "w": 2, "h": 2, "d": 2, "color": "#abc"}, | |
| {"x": "bad", "y": 0, "z": 0, "w": 1, "h": 1, "d": 1}, # non-numeric -> dropped | |
| {"x": 0, "y": 0, "z": 0, "w": 999, "h": 1, "d": 1}, # oversized -> clamped | |
| {"x": 0, "y": 0, "z": 0, "w": 0, "h": 1, "d": 1}, # zero size -> bumped to 1 | |
| ] | |
| out = repair_boxes(raw) | |
| assert all(set(("x", "y", "z", "w", "h", "d", "color")) <= set(b) for b in out) | |
| assert all(1 <= b["w"] <= 8 and 1 <= b["h"] <= 8 and 1 <= b["d"] <= 8 for b in out) | |
| assert len(out) == 3 # the non-numeric one is dropped | |
| def test_repair_returns_empty_for_garbage(): | |
| assert repair_boxes(None) == [] | |
| assert repair_boxes([{"nope": 1}]) == [] | |