diff options
Diffstat (limited to 'tests/TestArrange.py')
-rwxr-xr-x | tests/TestArrange.py | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/tests/TestArrange.py b/tests/TestArrange.py index a00b544936..85299a314d 100755 --- a/tests/TestArrange.py +++ b/tests/TestArrange.py @@ -2,40 +2,50 @@ # Cura is released under the terms of the LGPLv3 or higher. import numpy +import pytest from cura.Arranging.Arrange import Arrange from cura.Arranging.ShapeArray import ShapeArray -## Triangle of area 12 +pytestmark = pytest.mark.skip() + def gimmeTriangle(): + """Triangle of area 12""" + return numpy.array([[-3, 1], [3, 1], [0, -3]], dtype=numpy.int32) -## Boring square def gimmeSquare(): + """Boring square""" + return numpy.array([[-2, -2], [2, -2], [2, 2], [-2, 2]], dtype=numpy.int32) -## Triangle of area 12 def gimmeShapeArray(scale = 1.0): + """Triangle of area 12""" + vertices = gimmeTriangle() shape_arr = ShapeArray.fromPolygon(vertices, scale = scale) return shape_arr -## Boring square def gimmeShapeArraySquare(scale = 1.0): + """Boring square""" + vertices = gimmeSquare() shape_arr = ShapeArray.fromPolygon(vertices, scale = scale) return shape_arr -## Smoke test for Arrange def test_smoke_arrange(): + """Smoke test for Arrange""" + Arrange.create(fixed_nodes = []) -## Smoke test for ShapeArray def test_smoke_ShapeArray(): + """Smoke test for ShapeArray""" + gimmeShapeArray() -## Test ShapeArray def test_ShapeArray(): + """Test ShapeArray""" + scale = 1 ar = Arrange(16, 16, 8, 8, scale = scale) ar.centerFirst() @@ -44,8 +54,9 @@ def test_ShapeArray(): count = len(numpy.where(shape_arr.arr == 1)[0]) assert count >= 10 # should approach 12 -## Test ShapeArray with scaling def test_ShapeArray_scaling(): + """Test ShapeArray with scaling""" + scale = 2 ar = Arrange(16, 16, 8, 8, scale = scale) ar.centerFirst() @@ -54,8 +65,9 @@ def test_ShapeArray_scaling(): count = len(numpy.where(shape_arr.arr == 1)[0]) assert count >= 40 # should approach 2*2*12 = 48 -## Test ShapeArray with scaling def test_ShapeArray_scaling2(): + """Test ShapeArray with scaling""" + scale = 0.5 ar = Arrange(16, 16, 8, 8, scale = scale) ar.centerFirst() @@ -64,8 +76,9 @@ def test_ShapeArray_scaling2(): count = len(numpy.where(shape_arr.arr == 1)[0]) assert count >= 1 # should approach 3, but it can be inaccurate due to pixel rounding -## Test centerFirst def test_centerFirst(): + """Test centerFirst""" + ar = Arrange(300, 300, 150, 150, scale = 1) ar.centerFirst() assert ar._priority[150][150] < ar._priority[170][150] @@ -75,8 +88,9 @@ def test_centerFirst(): assert ar._priority[150][150] < ar._priority[150][130] assert ar._priority[150][150] < ar._priority[130][130] -## Test centerFirst def test_centerFirst_rectangular(): + """Test centerFirst""" + ar = Arrange(400, 300, 200, 150, scale = 1) ar.centerFirst() assert ar._priority[150][200] < ar._priority[150][220] @@ -86,15 +100,17 @@ def test_centerFirst_rectangular(): assert ar._priority[150][200] < ar._priority[130][200] assert ar._priority[150][200] < ar._priority[130][180] -## Test centerFirst def test_centerFirst_rectangular2(): + """Test centerFirst""" + ar = Arrange(10, 20, 5, 10, scale = 1) ar.centerFirst() assert ar._priority[10][5] < ar._priority[10][7] -## Test backFirst def test_backFirst(): + """Test backFirst""" + ar = Arrange(300, 300, 150, 150, scale = 1) ar.backFirst() assert ar._priority[150][150] < ar._priority[170][150] @@ -102,8 +118,9 @@ def test_backFirst(): assert ar._priority[150][150] > ar._priority[130][150] assert ar._priority[150][150] > ar._priority[130][130] -## See if the result of bestSpot has the correct form def test_smoke_bestSpot(): + """See if the result of bestSpot has the correct form""" + ar = Arrange(30, 30, 15, 15, scale = 1) ar.centerFirst() @@ -114,8 +131,9 @@ def test_smoke_bestSpot(): assert hasattr(best_spot, "penalty_points") assert hasattr(best_spot, "priority") -## Real life test def test_bestSpot(): + """Real life test""" + ar = Arrange(16, 16, 8, 8, scale = 1) ar.centerFirst() @@ -131,8 +149,9 @@ def test_bestSpot(): assert best_spot.x != 0 or best_spot.y != 0 # it can't be on the same location ar.place(best_spot.x, best_spot.y, shape_arr) -## Real life test rectangular build plate def test_bestSpot_rectangular_build_plate(): + """Real life test rectangular build plate""" + ar = Arrange(16, 40, 8, 20, scale = 1) ar.centerFirst() @@ -164,8 +183,9 @@ def test_bestSpot_rectangular_build_plate(): best_spot_x = ar.bestSpot(shape_arr) ar.place(best_spot_x.x, best_spot_x.y, shape_arr) -## Real life test def test_bestSpot_scale(): + """Real life test""" + scale = 0.5 ar = Arrange(16, 16, 8, 8, scale = scale) ar.centerFirst() @@ -182,8 +202,9 @@ def test_bestSpot_scale(): assert best_spot.x != 0 or best_spot.y != 0 # it can't be on the same location ar.place(best_spot.x, best_spot.y, shape_arr) -## Real life test def test_bestSpot_scale_rectangular(): + """Real life test""" + scale = 0.5 ar = Arrange(16, 40, 8, 20, scale = scale) ar.centerFirst() @@ -205,8 +226,9 @@ def test_bestSpot_scale_rectangular(): best_spot = ar.bestSpot(shape_arr_square) ar.place(best_spot.x, best_spot.y, shape_arr_square) -## Try to place an object and see if something explodes def test_smoke_place(): + """Try to place an object and see if something explodes""" + ar = Arrange(30, 30, 15, 15) ar.centerFirst() @@ -216,8 +238,9 @@ def test_smoke_place(): ar.place(0, 0, shape_arr) assert numpy.any(ar._occupied) -## See of our center has less penalty points than out of the center def test_checkShape(): + """See of our center has less penalty points than out of the center""" + ar = Arrange(30, 30, 15, 15) ar.centerFirst() @@ -228,8 +251,9 @@ def test_checkShape(): assert points2 > points assert points3 > points -## See of our center has less penalty points than out of the center def test_checkShape_rectangular(): + """See of our center has less penalty points than out of the center""" + ar = Arrange(20, 30, 10, 15) ar.centerFirst() @@ -240,8 +264,9 @@ def test_checkShape_rectangular(): assert points2 > points assert points3 > points -## Check that placing an object on occupied place returns None. def test_checkShape_place(): + """Check that placing an object on occupied place returns None.""" + ar = Arrange(30, 30, 15, 15) ar.centerFirst() @@ -252,8 +277,9 @@ def test_checkShape_place(): assert points2 is None -## Test the whole sequence def test_smoke_place_objects(): + """Test the whole sequence""" + ar = Arrange(20, 20, 10, 10, scale = 1) ar.centerFirst() shape_arr = gimmeShapeArray() @@ -268,26 +294,30 @@ def test_compare_occupied_and_priority_tables(): ar.centerFirst() assert ar._priority.shape == ar._occupied.shape -## Polygon -> array def test_arrayFromPolygon(): + """Polygon -> array""" + vertices = numpy.array([[-3, 1], [3, 1], [0, -3]]) array = ShapeArray.arrayFromPolygon([5, 5], vertices) assert numpy.any(array) -## Polygon -> array def test_arrayFromPolygon2(): + """Polygon -> array""" + vertices = numpy.array([[-3, 1], [3, 1], [2, -3]]) array = ShapeArray.arrayFromPolygon([5, 5], vertices) assert numpy.any(array) -## Polygon -> array def test_fromPolygon(): + """Polygon -> array""" + vertices = numpy.array([[0, 0.5], [0, 0], [0.5, 0]]) array = ShapeArray.fromPolygon(vertices, scale=0.5) assert numpy.any(array.arr) -## Line definition -> array with true/false def test_check(): + """Line definition -> array with true/false""" + base_array = numpy.zeros([5, 5], dtype=float) p1 = numpy.array([0, 0]) p2 = numpy.array([4, 4]) @@ -296,8 +326,9 @@ def test_check(): assert check_array[3][0] assert not check_array[0][3] -## Line definition -> array with true/false def test_check2(): + """Line definition -> array with true/false""" + base_array = numpy.zeros([5, 5], dtype=float) p1 = numpy.array([0, 3]) p2 = numpy.array([4, 3]) @@ -306,8 +337,9 @@ def test_check2(): assert not check_array[3][0] assert check_array[3][4] -## Just adding some stuff to ensure fromNode works as expected. Some parts should actually be in UM def test_parts_of_fromNode(): + """Just adding some stuff to ensure fromNode works as expected. Some parts should actually be in UM""" + from UM.Math.Polygon import Polygon p = Polygon(numpy.array([[-2, -2], [2, -2], [2, 2], [-2, 2]], dtype=numpy.int32)) offset = 1 |