cadforge / tests /test_geometry.py
eventhorizon28's picture
Upload folder using huggingface_hub
7c72eb2 verified
import pytest
from server.geometry import extract_properties
class TestExtractPropertiesFlatPlate:
@pytest.fixture(autouse=True)
def setup(self, flat_plate_shape):
self.props = extract_properties(flat_plate_shape)
def test_is_valid(self):
assert self.props["is_valid"] is True
def test_volume(self):
assert abs(self.props["volume_mm3"] - 16000.0) < 1.0
def test_surface_area(self):
expected = 2 * (80 * 40 + 80 * 5 + 40 * 5)
assert abs(self.props["surface_area_mm2"] - expected) < 1.0
def test_bbox(self):
assert abs(self.props["bbox_x_mm"] - 80.0) < 0.01
assert abs(self.props["bbox_y_mm"] - 40.0) < 0.01
assert abs(self.props["bbox_z_mm"] - 5.0) < 0.01
def test_face_count(self):
assert self.props["face_count"] == 6
def test_dominant_face_type(self):
assert self.props["dominant_face_type"] == "PLANE"
def test_euler_characteristic(self):
assert self.props["euler_characteristic"] == 2
def test_is_watertight(self):
assert self.props["is_watertight"] is True
def test_shape_class(self):
assert self.props["shape_class"] is not None
assert isinstance(self.props["shape_class"], str)
class TestExtractPropertiesBoxWithHole:
@pytest.fixture(autouse=True)
def setup(self, box_with_hole_shape):
self.props = extract_properties(box_with_hole_shape)
def test_is_valid(self):
assert self.props["is_valid"] is True
def test_volume_less_than_solid_box(self):
solid_vol = 50 * 30 * 20
assert self.props["volume_mm3"] < solid_vol
def test_has_cylinder_faces(self):
assert "CYLINDER" in self.props["face_type_counts"]
def test_face_count_greater_than_box(self):
assert self.props["face_count"] > 6
def test_euler_characteristic_with_hole(self):
assert self.props["euler_characteristic"] == 2
def test_bbox_ratios(self):
assert 0 < self.props["bbox_ratio_yx"] <= 1.0
assert 0 < self.props["bbox_ratio_zx"] <= 1.0
class TestExtractPropertiesSymmetry:
def test_flat_plate_symmetry(self, flat_plate_shape):
props = extract_properties(flat_plate_shape)
assert props["has_xy_symmetry"] == True
assert props["has_xz_symmetry"] == True
assert props["has_yz_symmetry"] == True