Skip to content

Commit

Permalink
test: fix test_random_slots
Browse files Browse the repository at this point in the history
  • Loading branch information
erooke committed Nov 17, 2024
1 parent 7e6c8d4 commit 7bc27fe
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions tests/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
desc: Unit tests for the build123d pack module
"""

import operator
import random
import unittest
from functools import reduce

from build123d import *

Expand Down Expand Up @@ -48,20 +46,20 @@ def test_random_boxes(self):
str((Part() + packed).bounding_box()),
)

def test_random_slots(self):
"""Test pack for 2D objects."""
random.seed(123456)
# 50 is an arbitrary number that is large enough to exercise
# different aspects of the packer while still completing quickly.
inputs = [
SlotOverall(random.randint(1, 20), random.randint(1, 20)) for _ in range(50)
]
# Not raising in this call shows successfull non-overlap.
packed = pack(inputs, 1)
self.assertEqual(
"bbox: 0.0 <= x <= 124.0, 0.0 <= y <= 105.0, 0.0 <= z <= 0.0",
str((Sketch() + packed).bounding_box()),
)

def test_random_slots():
"""Test pack for 2D objects."""
random.seed(123456)
# 50 is an arbitrary number that is large enough to exercise
# different aspects of the packer while still completing quickly.
widths = [random.randint(2, 20) for _ in range(50)]
heights = [random.randint(1, width - 1) for width in widths]
inputs = [SlotOverall(width, height) for width, height in zip(widths, heights)]
# Not raising in this call shows successfull non-overlap.
packed = pack(inputs, 1)
bb = (Sketch() + packed).bounding_box()
assert bb.min == Vector(0, 0, 0)
assert bb.max == Vector(70, 63, 0)


if __name__ == "__main__":
Expand Down

0 comments on commit 7bc27fe

Please sign in to comment.