def test_union_Comp2Radius(): elem1 = et.Element("sphere", { "radius" : "2.5*mm" }) elem2 = et.Element("cylinder", { "height" : "5.*mm", "radius" : "1.*mm" }) op = operations.Union() op.addComp(components.Sphere(elem1)) op.addComp(components.Cylinder(elem2)) assert(op[1].radius == 1)
def test_makeComp(): elem = et.Element("cylinder", {"radius": "1.5*mm", "height": "10.*mm"}) fname = os.path.abspath("./tests/pytest/test_xmls/empty.xml") p = Parser(fname) test = p.makeComp(elem) sol = components.Cylinder(elem) assert (test == sol)
def test_difference_Comp2Top(): elem1 = et.Element("cylinder", { "height" : "5.*mm", "radius" : "2.5*mm" }) elem2 = et.Element("cone", { "height" : "5.*mm", "radius" : "2.5*mm" }) op = operations.Difference() op.addComp(components.Cylinder(elem1)) op.addComp(components.Cone(elem2)) assert(op[1].radius == 2.5)
def test_reflection_str(): elem = et.Element("cylinder", { "height" : "5.*mm", "radius" : "2.5*mm" }) test = operations.Reflection("(1, 1, 1)") test.body = components.Cylinder(elem) sol = """mirror([1.0, 1.0, 1.0]) { cylinder(h = 5.0, r = 2.5, $fn=100, center=true); }""" assert("{0!s}".format(test) == sol)
def test_union_str(): elem1 = et.Element("sphere", { "radius" : "2.5*mm" }) elem2 = et.Element("cylinder", { "height" : "5.*mm", "radius" : "1.*mm" }) test = operations.Union() test.addComp(components.Sphere(elem1)) test.addComp(components.Cylinder(elem2)) sol = """union() { sphere(r = 2.5, $fn=100); cylinder(h = 5.0, r = 1.0, $fn=100, center=true); }""" assert("{0!s}".format(test) == sol)
def test_difference_str(): elem1 = et.Element("cylinder", { "radius" : "2.5*mm", "height" : "5.*mm" }) elem2 = et.Element("cone", { "radius" : "2.5*mm", "height" : "5.*mm" }) comp1 = components.Cylinder(elem1) comp2 = components.Cone(elem2) test = operations.Difference() test.addComp(comp1) test.addComp(comp2) sol = """difference() { cylinder(h = 5.0, r = 2.5, $fn=100, center=true); translate([0.0, 0.0, -2.5]) {cylinder(h = 5.0, r1 = 2.5, r2=0, $fn=100, center=true);} }""" assert("{0!s}".format(test) == sol)
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_reflection_body(): elem1 = et.Element("cylinder", {"height": "5.*mm", "radius": "2.5*mm"}) op = operations.Reflection("(1, 1, 1)") op.body = components.Cylinder(elem1) assert (op.body.height == 5.0 and op.body.radius == 2.5)
def test_reflection_vector(): elem1 = et.Element("cylinder", {"height": "5.*mm", "radius": "2.5*mm"}) op = operations.Reflection("(1, 1, 1)") op.body = components.Cylinder(elem1) assert (op.vector == [1, 1, 1])
def test_cylinder_str(): elem1 = et.Element("cylinder", { "height" : "5.*mm", "radius" : "2.5*mm" }) test = components.Cylinder(elem1) sol = "cylinder(h = 5.0, r = 2.5, $fn=100, center=true);" assert("{0!s}".format(test) == sol)