Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
def test_translation_str():
    elem = et.Element("sphere", { "radius" : "5.*mm" })
    vector = et.Element("vector", { "beam" : "10.*mm", "transversal" : "0.*mm", "vertical" : "0.*mm" })
    test = operations.Translation(vector)
    test.body = components.Sphere(elem)
    sol = """translate([10.0, 0.0, 0.0]) {
    sphere(r = 5.0, $fn=100);
}"""
    assert("{0!s}".format(test) == sol)
Example #5
0
def test_translation_vector():
    elem1 = et.Element("sphere", {"radius": "5.*mm"})
    vector = et.Element("vector", {
        "beam": "10.*mm",
        "transversal": "0.*mm",
        "vertical": "0.*mm"
    })
    op = operations.Translation(vector)
    op.body = components.Sphere(elem1)
    assert (op.vector == [10.0, 0.0, 0.0])
Example #6
0
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)
Example #7
0
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)
Example #8
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)
Example #9
0
def test_sphere_str():
    elem1 = et.Element("sphere", { "radius" : "2.5*mm" })
    test = components.Sphere(elem1)
    sol = "sphere(r = 2.5, $fn=100);"
    assert("{0!s}".format(test) == sol)