"""Tests for the cutting-stock nesting (lumber 1D, plywood 2D).""" from woodshop.layout import nest_lumber, nest_plywood, stock_counts from woodshop.scene import Scene def test_lumber_packs_into_sticks(): s = Scene() for _ in range(3): s.place("2x4", 40) # three 40" pieces -> two fit in a 96" stick (80+kerf) sticks = nest_lumber(s)["2x4"] assert len(sticks) == 2 # 2 in the first stick, 1 in the second assert sum(len(st["pieces"]) for st in sticks) == 3 assert all(st["used"] <= 96 + 1e-6 for st in sticks) def test_lumber_offcut_reported(): s = Scene() s.place("2x4", 90) stick = nest_lumber(s)["2x4"][0] assert stick["offcut"] == 6.0 # 96 - 90 def test_plywood_packs_panels_on_sheet(): s = Scene() s.place("ply-3/4", 40, width_in=20) # two panels easily fit on one 48x96 sheet s.place("ply-3/4", 40, width_in=20) sheets = nest_plywood(s)["ply-3/4"] assert len(sheets) == 1 assert len(sheets[0]["placements"]) == 2 def test_oversize_panel_gets_its_own_sheet(): s = Scene() s.place("ply-3/4", 96, width_in=48) # a full sheet s.place("ply-3/4", 96, width_in=48) # another full sheet assert len(nest_plywood(s)["ply-3/4"]) == 2 def test_stock_counts_mixes_lumber_and_plywood(): s = Scene() s.place("2x4", 40) s.place("ply-1/2", 24, width_in=24) counts = stock_counts(s) assert counts["2x4"] == 1 assert counts["ply-1/2"] == 1