def test_intersection_Comp1Radius(): elem1 = et.Element("sphere", { "radius" : "5.*mm" }) elem2 = et.Element("block", { "width" : "5.*mm", "height" : "7.*mm", "thickness": "1.*mm" }) op = operations.Intersection() op.addComp(components.Sphere(elem1)) op.addComp(components.Block(elem2)) assert(op[0].radius == 5)
def test_intersection_Comp2Diag(): elem1 = et.Element("sphere", { "radius" : "5.*mm" }) elem2 = et.Element("block", { "width" : "5.*mm", "height" : "1.*mm", "thickness": "5.*mm" }) op = operations.Intersection() op.addComp(components.Sphere(elem1)) op.addComp(components.Block(elem2)) assert(op[1].x == 5 and op[1].y == 5 and op[1].z == 1)
def test_dilation_str(): elem = et.Element("block", { "width" : "1.*mm", "height" : "1.*mm", "thickness": "1.*mm" }) test = operations.Dilation(5) test.body = components.Block(elem) sol = """scale([5, 5, 5]) { cube([1.0, 1.0, 1.0], center=true); }""" assert("{0!s}".format(test) == sol)
def test_dilation_body(): elem1 = et.Element("block", { "width": "1.*mm", "height": "1.*mm", "thickness": "1.*mm" }) op = operations.Dilation(5) op.body = components.Block(elem1) assert (op.body.x == 1.0 and op.body.y == 1.0 and op.body.z == 1.0)
def test_dilation_scale(): elem1 = et.Element("block", { "width": "1.*mm", "height": "1.*mm", "thickness": "1.*mm" }) op = operations.Dilation(5) op.body = components.Block(elem1) assert (op.scale == 5)
def test_rotation_str(): elem = et.Element("block", { "width" : "5.*mm", "height" : "5.*mm", "thickness": "5.*mm" }) vector = et.Element("axis", { "beam" : "0.0", "transversal" : "0.0", "vertical" : "1.0" }) test = operations.Rotation("45.*deg", vector) test.body = components.Block(elem) sol = """rotate(45.0, [0.0, 0.0, 1.0]) { cube([5.0, 5.0, 5.0], center=true); }""" assert("{0!s}".format(test) == sol)
def test_intersection_str(): elem1 = et.Element("sphere", { "radius" : "5.*mm" }) elem2 = et.Element("block", { "width" : "5.*mm", "height" : "1.*mm", "thickness": "5.*mm" }) test = operations.Intersection() test.addComp(components.Sphere(elem1)) test.addComp(components.Block(elem2)) sol = """intersection() { sphere(r = 5.0, $fn=100); cube([5.0, 5.0, 1.0], center=true); }""" assert("{0!s}".format(test) == sol)
def test_rotation_body(): elem1 = et.Element("block", { "width": "5.*mm", "height": "5.*mm", "thickness": "5.*mm" }) vector = et.Element("axis", { "beam": "0.0", "transversal": "0.0", "vertical": "1.0" }) op = operations.Rotation("45.*deg", vector) op.body = components.Block(elem1) assert (op.body.x == 5.0 and op.body.y == 5.0 and op.body.z == 5.0)
def test_parsercore(): fname = os.path.abspath("./tests/pytest/test_xmls/parser_test.xml") p = Parser(fname) test = p.rootelems[0] sol = operations.Dilation(3.0) vector = et.Element("axis", { "beam": "1.0", "transversal": "0.0", "vertical": "0.0" }) op1 = operations.Rotation("90.*deg", vector) vector = et.Element("vector", { "beam": "0.*mm", "transversal": "0.*mm", "vertical": "5.*cm" }) op2 = operations.Translation(vector) op3 = operations.Reflection("(1, 1, 0)") op4 = operations.Difference() op5 = operations.Intersection() comp1 = et.Element("block", { "width": "20.*mm", "height": "20.*mm", "thickness": "20.*mm" }) comp2 = et.Element("sphere", {"radius": "20.*mm"}) comp3 = et.Element("pyramid", { "thickness": "20.*mm", "width": "20.*mm", "height": "10.*mm" }) op5.addComp(components.Block(comp1)) op5.addComp(components.Sphere(comp2)) op5.addComp(components.Pyramid(comp3)) op6 = operations.Union() comp4 = et.Element("cone", {"height": "20.*mm", "radius": "20.*mm"}) comp5 = et.Element("cylinder", {"height": "10.*mm", "radius": "20.*mm"}) comp6 = et.Element("torus", {"major": "30.*mm", "minor": "20.*mm"}) op6.addComp(components.Cone(comp4)) op6.addComp(components.Cylinder(comp5)) op6.addComp(components.Torus(comp6)) op4.addComp(op5) op4.addComp(op6) op3.body = op4 op2.body = op3 op1.body = op2 sol.body = op1 assert (test == sol)
def test_block_str(): elem1 = et.Element("block", { "width" : "5.*mm", "height" : "7.*mm", "thickness": "1.*mm" }) test = components.Block(elem1) sol = "cube([1.0, 5.0, 7.0], center=true);" assert("{0!s}".format(test) == sol)