Spring 2013, David Matuszek
We will be testing your code with our unit tests. In order for your code to pass the tests, it has to have the correct structure. Since in this assignment you are working from another program, not from a specification, the intended structure may not be perfectly clear.
To avoid a lot of needless test failures, here is the structure that is expected of your program. Use exactly these names for files, classes, and methods (parameter names do not need to be exactly as given).
PuzzlePiece.py
class PuzzlePiece
def __init__(self, top, left, right, bottom)
PuzzlePiecedef getTop(self)def getLeft(self) def getRight(self)def getBottom(self)@classmethod
def lastThreeDigits(cls, number)def __str__(self) # the equivalent of Java's toString@classmethod is the equivalent of Java's static. To use this method, you need to send a message to the class itself, not to an instance. Like this: PuzzlePiece.lastThreeDigits(somePiece).cls instead of self as the name of the first parameter.JigsawPuzzle.py
class JigsawPuzzle
@classmethod
def main(cls, rows, columns)def printPuzzle(self, puzzle)main is a class method, call it like this: JigsawPuzzle.main(3, 4).
printPuzzle from within main, you probably need to say something like JigsawPuzzle().printPuzzle(puzzle). This is because you need to send the message printPuzzle to an instance (=object) of the JigsawPuzzle class, and that's what JigsawPuzzle()--notice the parentheses!--gives you.PuzzleCreator.py
class PuzzleCreator
def create(self, rows, columns)@classmethod
def shuffle(cls, objects)PuzzleSolver.py
class PuzzleSolver
def solve(self, rows, columns, pieces)def findPiece(self, top, left, pieces)File SolutionChecker
def isCorrectlyAssembled(self, puzzle)
SolutionChecker().isCorrectlyAssembled(puzzle).from PuzzlePiece import *
from JigsawPuzzle import *
from PuzzleCreator import *
from PuzzleSolver import *
from SolutionChecker import *
import unittest
class TestStuff(unittest.TestCase):
def test_whether_all_the_methods_are_callable(self):
piece = PuzzlePiece(1, 2, 3, 4)
piece.getTop()
piece.getLeft()
piece.getRight()
piece.getBottom()
PuzzlePiece.lastThreeDigits(123456789)
s = str(piece)
jigsawPuzzle = JigsawPuzzle()
## JigsawPuzzle.main(5, 5)
creator = PuzzleCreator()
pieces = creator.create(5, 8)
PuzzleCreator.shuffle(pieces)
solver = PuzzleSolver()
solver.findPiece(0, 0, pieces)
solvedPuzzle = solver.solve(5, 8, pieces)
checker = SolutionChecker()
checker.isCorrectlyAssembled(solvedPuzzle)
unittest.main()