Skip to content

Commit a83c5e4

Browse files
authored
Merge pull request #7 from CadQuery/nested-cube-test
Added a test for nested cubes
2 parents a47ce50 + 2ec0188 commit a83c5e4

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/sample_assemblies.py

+30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
import cadquery as cq
22

33

4+
def generate_nested_boxes():
5+
"""
6+
Generates a simple assembly of two cubes where one is nested inside the other.
7+
"""
8+
9+
# Cube that is nested completely inside the other one
10+
inside_cube = cq.Workplane().box(5, 5, 5)
11+
12+
# Use the inside cube to make a void inside the outside cube
13+
outside_cube = cq.Workplane().box(10, 10, 10)
14+
outside_cube = outside_cube.cut(inside_cube)
15+
16+
# Create the assembly
17+
assy = cq.Assembly()
18+
assy.add(
19+
outside_cube,
20+
name="outside_cube",
21+
loc=cq.Location(cq.Vector(0, 0, 0)),
22+
color=cq.Color("blue"),
23+
)
24+
assy.add(
25+
inside_cube,
26+
name="inside_cube",
27+
loc=cq.Location(cq.Vector(0, 0, 0)),
28+
color=cq.Color("red"),
29+
)
30+
31+
return assy
32+
33+
434
def generate_simple_nested_boxes():
535
"""
636
Generates the simplest assembly case where two boxes are nested inside each other.

tests/smoke_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
import assembly_mesh_plugin.plugin
22
from tests.sample_assemblies import (
3+
generate_nested_boxes,
34
generate_simple_nested_boxes,
45
generate_test_cross_section,
56
generate_assembly,
67
)
78

89

10+
def test_nested_cubes():
11+
"""
12+
Tests to make sure that the nested cubes do not cause the correct number of surfaces
13+
in the mesh.
14+
"""
15+
16+
# Create the basic assembly
17+
assy = generate_nested_boxes()
18+
19+
# Convert the assembly to a GMSH mesh
20+
gmsh = assy.getTaggedGmsh()
21+
22+
# Make sure we have the correct number of surfaces
23+
surfaces = gmsh.model.getEntities(2)
24+
assert len(surfaces) == 18
25+
26+
927
def test_basic_assembly():
1028
"""
1129
Tests to make sure that the most basic assembly works correctly with tagging.

0 commit comments

Comments
 (0)