Convert matrix index to gcode
#39 Save GCode in file Convert a list of index to gcode string in an array
This commit is contained in:
@@ -5,31 +5,50 @@ from pcbdevice.models.Coordinates import Coordinate
|
||||
|
||||
|
||||
class TestListToGCode(TestCase):
|
||||
|
||||
oneTrace = [Coordinate(1, 2),
|
||||
Coordinate(1, 5),
|
||||
Coordinate(2, 5),
|
||||
Coordinate(2, 8)]
|
||||
|
||||
twoTrace = [Coordinate(1, 2),
|
||||
Coordinate(1, 5),
|
||||
Coordinate(5, 5),
|
||||
Coordinate(5, 2),
|
||||
Coordinate(1, 2),
|
||||
Coordinate(-1, -1),
|
||||
Coordinate(5, 4),
|
||||
Coordinate(8, 4)]
|
||||
|
||||
threeTrace = [Coordinate(1, 2),
|
||||
Coordinate(1, 5),
|
||||
Coordinate(5, 5),
|
||||
Coordinate(5, 2),
|
||||
Coordinate(1, 2),
|
||||
Coordinate(-1, -1),
|
||||
Coordinate(5, 4),
|
||||
Coordinate(8, 4),
|
||||
Coordinate(2, 9),
|
||||
Coordinate(9, 45),
|
||||
Coordinate(12, 12),
|
||||
Coordinate(1, 10)]
|
||||
|
||||
def test_listToGCodeMultipleTrace(self):
|
||||
xSize, ySize = 2, 3
|
||||
|
||||
coords = whenSingleTrace()
|
||||
self.assertEqual(listToGCode(coords, ySize, xSize), getExpected(coords, ySize, xSize))
|
||||
|
||||
coords = whenTwoTrace()
|
||||
self.assertEqual(listToGCode(coords, ySize, xSize), getExpected(coords, ySize, xSize))
|
||||
|
||||
coords = whenThreeTrace()
|
||||
self.assertEqual(listToGCode(coords, ySize, xSize), getExpected(coords, ySize, xSize))
|
||||
self.assertEqual(listToGCode(self.oneTrace, ySize, xSize), getExpected(self.oneTrace, ySize, xSize))
|
||||
self.assertEqual(listToGCode(self.twoTrace, ySize, xSize), getExpected(self.twoTrace, ySize, xSize))
|
||||
self.assertEqual(listToGCode(self.threeTrace, ySize, xSize), getExpected(self.threeTrace, ySize, xSize))
|
||||
|
||||
def test_listToGCodePixelSize(self):
|
||||
xSize, ySize = 1, 4
|
||||
coords = whenSingleTrace()
|
||||
self.assertEqual(listToGCode(coords, ySize, xSize), getExpected(coords, ySize, xSize))
|
||||
self.assertEqual(listToGCode(self.oneTrace, ySize, xSize), getExpected(self.oneTrace, ySize, xSize))
|
||||
|
||||
xSize, ySize = 4, 2
|
||||
coords = whenSingleTrace()
|
||||
self.assertEqual(listToGCode(coords, ySize, xSize), getExpected(coords, ySize, xSize))
|
||||
self.assertEqual(listToGCode(self.oneTrace, ySize, xSize), getExpected(self.oneTrace, ySize, xSize))
|
||||
|
||||
xSize, ySize = 8, -1
|
||||
coords = whenSingleTrace()
|
||||
self.assertRaises(RuntimeError, lambda: listToGCode(coords, ySize, xSize))
|
||||
|
||||
self.assertRaises(RuntimeError, lambda: listToGCode(self.oneTrace, ySize, xSize))
|
||||
|
||||
def getExpected(coords, ySize, xSize):
|
||||
header = ['G28', 'G90\n']
|
||||
@@ -48,37 +67,4 @@ def getExpected(coords, ySize, xSize):
|
||||
else:
|
||||
content.append('G0 Z0')
|
||||
|
||||
return header + content + footer
|
||||
|
||||
|
||||
def whenSingleTrace():
|
||||
return [Coordinate(1, 2),
|
||||
Coordinate(1, 5),
|
||||
Coordinate(2, 5),
|
||||
Coordinate(2, 8)]
|
||||
|
||||
|
||||
def whenTwoTrace():
|
||||
return [Coordinate(1, 2),
|
||||
Coordinate(1, 5),
|
||||
Coordinate(5, 5),
|
||||
Coordinate(5, 2),
|
||||
Coordinate(1, 2),
|
||||
Coordinate(-1, -1),
|
||||
Coordinate(5, 4),
|
||||
Coordinate(8, 4)]
|
||||
|
||||
|
||||
def whenThreeTrace():
|
||||
return [Coordinate(1, 2),
|
||||
Coordinate(1, 5),
|
||||
Coordinate(5, 5),
|
||||
Coordinate(5, 2),
|
||||
Coordinate(1, 2),
|
||||
Coordinate(-1, -1),
|
||||
Coordinate(5, 4),
|
||||
Coordinate(8, 4),
|
||||
Coordinate(2, 9),
|
||||
Coordinate(9, 45),
|
||||
Coordinate(12, 12),
|
||||
Coordinate(1, 10)]
|
||||
return header + content + footer
|
||||
Reference in New Issue
Block a user