Rename modules
Rename modules with better name and move the arduino code to its own folder
This commit is contained in:
0
gcodeextractor/tests/gcode/__init__.py
Normal file
0
gcodeextractor/tests/gcode/__init__.py
Normal file
93
gcodeextractor/tests/gcode/test_gcodeCreator.py
Normal file
93
gcodeextractor/tests/gcode/test_gcodeCreator.py
Normal file
@@ -0,0 +1,93 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from gcodeextractor.gcode.GcodeCreator import createSequence, findDirection, findEndOfLine
|
||||
from gcodeextractor.models.Coordinates import Coordinate
|
||||
|
||||
|
||||
class TestGcodeCreator(TestCase):
|
||||
|
||||
|
||||
def imageTest(self):
|
||||
return [[0, 2, 0, 0, 0, 0, 0],
|
||||
[0, 2, 0, 0, 0, 0, 0],
|
||||
[0, 2, 0, 0, 2, 2, 0],
|
||||
[0, 2, 2, 0, 0, 2, 0],
|
||||
[0, 0, 2, 0, 0, 2, 0],
|
||||
[0, 0, 2, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0]]
|
||||
|
||||
expectedSequence = [Coordinate(-1, -1),
|
||||
Coordinate(1, 0),
|
||||
Coordinate(1, 3),
|
||||
Coordinate(2, 3),
|
||||
Coordinate(2, 5),
|
||||
Coordinate(-1, -1),
|
||||
Coordinate(4, 2),
|
||||
Coordinate(5, 2),
|
||||
Coordinate(5, 4)]
|
||||
|
||||
def imageTestDots(self):
|
||||
return [[0, 0, 0, 2],
|
||||
[0, 2, 0, 0],
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 2, 0]]
|
||||
|
||||
expectedSequenceDots = [Coordinate(-1, -1),
|
||||
Coordinate(3, 0),
|
||||
Coordinate(-1, -1),
|
||||
Coordinate(1, 1),
|
||||
Coordinate(-1, -1),
|
||||
Coordinate(2, 3)]
|
||||
|
||||
def imageTestEmpty(self):
|
||||
return [[0, 0, 0, 0],
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0],
|
||||
[0, 0, 0, 0]]
|
||||
|
||||
expectedSequenceEmpty = []
|
||||
|
||||
def imageTestFull(self):
|
||||
return [[2, 2, 2, 2],
|
||||
[2, 2, 2, 2],
|
||||
[2, 2, 2, 2],
|
||||
[2, 2, 2, 2]]
|
||||
|
||||
expectedSequenceFull = [Coordinate(-1, -1),
|
||||
Coordinate(0, 0),
|
||||
Coordinate(3, 0),
|
||||
Coordinate(3, 3),
|
||||
Coordinate(0, 3),
|
||||
Coordinate(0, 1),
|
||||
Coordinate(2, 1),
|
||||
Coordinate(2, 2),
|
||||
Coordinate(1, 2)]
|
||||
|
||||
|
||||
def test_createSequence(self):
|
||||
|
||||
self.assertEqual(createSequence(self.imageTest()), self.expectedSequence)
|
||||
self.assertEqual(createSequence(self.imageTestDots()), self.expectedSequenceDots)
|
||||
self.assertEqual(createSequence(self.imageTestEmpty()), self.expectedSequenceEmpty)
|
||||
self.assertEqual(createSequence(self.imageTestFull()), self.expectedSequenceFull)
|
||||
|
||||
def test_findDirection(self):
|
||||
|
||||
self.assertEqual(findDirection(self.imageTest(), 1, 1), 0)
|
||||
self.assertEqual(findDirection(self.imageTest(), 2, 4), 1)
|
||||
self.assertEqual(findDirection(self.imageTest(), 1, 4), 2)
|
||||
self.assertEqual(findDirection(self.imageTest(), 3, 3), 3)
|
||||
self.assertEqual(findDirection(self.imageTest(), 5, 4), -1)
|
||||
|
||||
def test_findEndOfLine(self):
|
||||
|
||||
sequenceTest = []
|
||||
|
||||
self.assertEqual(findEndOfLine(self.imageTest(), 2, 0, 1, sequenceTest), 4)
|
||||
self.assertEqual(findEndOfLine(self.imageTest(), 1, 3, 1, sequenceTest), 2)
|
||||
self.assertEqual(findEndOfLine(self.imageTest(), 0, 5, 2, sequenceTest), 3)
|
||||
self.assertEqual(findEndOfLine(self.imageTest(), 3, 0, 1, sequenceTest), 1)
|
||||
self.assertEqual(findEndOfLine(self.imageTestFull(), 1, 1, 1, sequenceTest), 3)
|
||||
self.assertEqual(findEndOfLine(self.imageTestFull(), 0, 1, 1, sequenceTest), 2)
|
||||
|
||||
|
||||
70
gcodeextractor/tests/gcode/test_listToGcode.py
Normal file
70
gcodeextractor/tests/gcode/test_listToGcode.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from gcodeextractor.gcode.GcodeBuilder import listToGCode
|
||||
from gcodeextractor.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.0, 3.0
|
||||
|
||||
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.0, 4.0
|
||||
self.assertEqual(listToGCode(self.oneTrace, ySize, xSize), getExpected(self.oneTrace, ySize, xSize))
|
||||
|
||||
xSize, ySize = 4.0, 2.0
|
||||
self.assertEqual(listToGCode(self.oneTrace, ySize, xSize), getExpected(self.oneTrace, ySize, xSize))
|
||||
|
||||
xSize, ySize = 8.0, -1.0
|
||||
self.assertRaises(RuntimeError, lambda: listToGCode(self.oneTrace, ySize, xSize))
|
||||
|
||||
def getExpected(coords, ySize, xSize):
|
||||
header = ['G28', 'G90\n']
|
||||
footer = ['\nG0 Z0', 'G28', 'M18']
|
||||
|
||||
content = ['G0 X' + str(round(xSize * coords[0].getX(), 2)) + ' Y' + str(round(ySize * coords[0].getY(), 2)),
|
||||
'G0 Z3',
|
||||
]
|
||||
|
||||
for index, coord in enumerate(coords):
|
||||
if index > 0:
|
||||
if coord.getX() != -1 and coord.getY() != -1:
|
||||
content.append('G0 X' + str(xSize * coord.getX()) + ' Y' + str(ySize * coord.getY()))
|
||||
if coords[index - 1].getX() == -1 and coords[index - 1].getX() == -1:
|
||||
content.append('G0 Z3')
|
||||
else:
|
||||
content.append('G0 Z0')
|
||||
|
||||
return header + content + footer
|
||||
174
gcodeextractor/tests/gcode/test_path.py
Normal file
174
gcodeextractor/tests/gcode/test_path.py
Normal file
@@ -0,0 +1,174 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from gcodeextractor.gcode.path import scanHorizontal, scanVertical, twoRemoving
|
||||
|
||||
|
||||
class TestPath(TestCase):
|
||||
|
||||
#inputs
|
||||
def imageTest(self):
|
||||
return [[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 1, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0]]
|
||||
|
||||
def imageTestMulti(self):
|
||||
return [[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 1, 0, 0, 1, 0, 0],
|
||||
[0, 0, 0, 1, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 1, 0, 0]]
|
||||
|
||||
def imageTestHOut(self):
|
||||
return [[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 1, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0]]
|
||||
|
||||
def imageTestVOut(self):
|
||||
return [[0, 0, 0],
|
||||
[0, 0, 0],
|
||||
[0, 0, 0],
|
||||
[0, 1, 0],
|
||||
[0, 0, 0],
|
||||
[0, 0, 0],
|
||||
[0, 0, 0]]
|
||||
|
||||
def imageTest2(self):
|
||||
return [[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 2, 2, 1, 2, 2, 0],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0]]
|
||||
|
||||
def imageTestMulti2(self):
|
||||
return [[2, 2, 2, 2, 2, 2, 2],
|
||||
[2, 2, 2, 2, 2, 2, 2],
|
||||
[2, 1, 2, 2, 1, 2, 2],
|
||||
[2, 2, 2, 1, 2, 2, 2],
|
||||
[2, 2, 2, 2, 2, 2, 2],
|
||||
[2, 2, 2, 2, 2, 2, 2],
|
||||
[2, 2, 2, 2, 1, 2, 2]]
|
||||
|
||||
|
||||
#horizontal results
|
||||
def imageResultHr2(self):
|
||||
return [[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 2, 0, 0, 0, 2, 0],
|
||||
[0, 2, 0, 0, 0, 2, 0],
|
||||
[0, 2, 0, 1, 0, 2, 0],
|
||||
[0, 2, 0, 0, 0, 2, 0],
|
||||
[0, 2, 0, 0, 0, 2, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0]]
|
||||
|
||||
def imageResultHr3(self):
|
||||
return [[2, 0, 0, 0, 0, 0, 2],
|
||||
[2, 0, 0, 0, 0, 0, 2],
|
||||
[2, 0, 0, 0, 0, 0, 2],
|
||||
[2, 0, 0, 1, 0, 0, 2],
|
||||
[2, 0, 0, 0, 0, 0, 2],
|
||||
[2, 0, 0, 0, 0, 0, 2],
|
||||
[2, 0, 0, 0, 0, 0, 2]]
|
||||
|
||||
def imageResultHOut(self):
|
||||
return [[0, 2, 0, 0, 0, 2, 0],
|
||||
[0, 2, 0, 1, 0, 2, 0],
|
||||
[0, 2, 0, 0, 0, 2, 0]]
|
||||
|
||||
def imageResultMultiH(self):
|
||||
return [[0, 0, 2, 2, 0, 0, 2],
|
||||
[0, 2, 2, 2, 0, 2, 2],
|
||||
[0, 1, 2, 2, 1, 2, 2],
|
||||
[0, 2, 2, 1, 0, 2, 2],
|
||||
[0, 2, 2, 2, 0, 2, 2],
|
||||
[0, 2, 2, 0, 0, 2, 2],
|
||||
[0, 0, 2, 0, 1, 0, 2]]
|
||||
|
||||
|
||||
#vertical results
|
||||
def imageResultVr2(self):
|
||||
return [[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 1, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0]]
|
||||
|
||||
def imageResultVr3(self):
|
||||
return [[2, 2, 2, 2, 2, 2, 2],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 1, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[2, 2, 2, 2, 2, 2, 2]]
|
||||
|
||||
def imageResultVOut(self):
|
||||
return [[0, 0, 0],
|
||||
[2, 2, 2],
|
||||
[0, 0, 0],
|
||||
[0, 1, 0],
|
||||
[0, 0, 0],
|
||||
[2, 2, 2],
|
||||
[0, 0, 0]]
|
||||
|
||||
def imageResultMultiV(self):
|
||||
return [[2, 2, 2, 2, 2, 2, 2],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 1, 0, 0, 1, 0, 0],
|
||||
[0, 0, 0, 1, 0, 0, 0],
|
||||
[2, 2, 2, 2, 2, 2, 2],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 0, 0, 0, 1, 0, 0]]
|
||||
|
||||
#two results
|
||||
|
||||
def imageResult2(self):
|
||||
return [[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 2, 0, 0, 0, 2, 0],
|
||||
[0, 2, 0, 1, 0, 2, 0],
|
||||
[0, 2, 0, 0, 0, 2, 0],
|
||||
[0, 2, 2, 2, 2, 2, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0]]
|
||||
|
||||
def imageResultMulti2(self):
|
||||
return [[2, 2, 2, 2, 2, 2, 2],
|
||||
[0, 0, 0, 0, 0, 0, 2],
|
||||
[0, 1, 0, 0, 1, 0, 2],
|
||||
[0, 0, 0, 1, 0, 0, 2],
|
||||
[2, 2, 0, 0, 0, 2, 2],
|
||||
[2, 2, 2, 0, 0, 0, 2],
|
||||
[2, 2, 2, 0, 1, 0, 2]]
|
||||
|
||||
|
||||
|
||||
def test_hori(self):
|
||||
|
||||
self.assertEqual(scanHorizontal(self.imageTest(), 2), self.imageResultHr2())
|
||||
self.assertEqual(scanHorizontal(self.imageTest(), 3), self.imageResultHr3())
|
||||
self.assertEqual(scanHorizontal(self.imageTestHOut(), 2), self.imageResultHOut())
|
||||
self.assertEqual(scanHorizontal(self.imageTest(), 4), self.imageTest())
|
||||
self.assertEqual(scanHorizontal(self.imageTestMulti(), 2), self.imageResultMultiH())
|
||||
|
||||
def test_vert(self):
|
||||
|
||||
self.assertEqual(scanVertical(self.imageTest(), 2), self.imageResultVr2())
|
||||
self.assertEqual(scanVertical(self.imageTest(), 3), self.imageResultVr3())
|
||||
self.assertEqual(scanVertical(self.imageTestVOut(), 2), self.imageResultVOut())
|
||||
self.assertEqual(scanVertical(self.imageTest(), 4), self.imageTest())
|
||||
self.assertEqual(scanVertical(self.imageTestMulti(), 2), self.imageResultMultiV())
|
||||
|
||||
def test_two(self):
|
||||
|
||||
self.assertEqual(twoRemoving(self.imageTest2(), 2), self.imageResult2())
|
||||
self.assertEqual(twoRemoving(self.imageTest2(), 3), self.imageTest())
|
||||
self.assertEqual(twoRemoving(self.imageTest2(), 7), self.imageTest())
|
||||
self.assertEqual(twoRemoving(self.imageTestMulti2(), 2), self.imageResultMulti2())
|
||||
Reference in New Issue
Block a user