示例#1
0
 def test_move_to_left_to_fail(self):
     matrix = [
         [1, 2, 3],
         [0, 8, 4],
         [7, 6, 5]]
     new = Puzzle(matrix)
     self.assertFalse(new.left())
示例#2
0
class PuzzleTest(unittest.TestCase):
    matrix = [
        [1, 2, 3],
        [8, 0, 4],
        [7, 6, 5]]
    p = None

    def setUp(self):
        self.p = Puzzle(self.matrix)

    def test_get_blank(self):
        p = Puzzle(self.matrix)
        self.assertEquals(p.get_blank, (1, 1))

    def test_move_to_up(self):
        matrix = [
            [1, 0, 3],
            [8, 2, 4],
            [7, 6, 5]]
        self.assertEquals(self.p.up(), matrix)

    def test_move_to_up_to_fail(self):
        matrix = [
            [1, 2, 0],
            [8, 4, 3],
            [7, 6, 5]]
        new = Puzzle(matrix)
        self.assertFalse(new.up())

    def test_move_to_down(self):
        matrix = [
            [1, 2, 3],
            [8, 6, 4],
            [7, 0, 5]]
        self.assertEquals(self.p.down(), matrix)

    def test_move_to_down_to_fail(self):
        matrix = [
            [1, 2, 3],
            [8, 4, 5],
            [7, 6, 0]]
        new = Puzzle(matrix)
        self.assertFalse(new.down())

    def test_move_to_left(self):
        matrix = [
            [1, 2, 3],
            [0, 8, 4],
            [7, 6, 5]]
        self.assertEquals(self.p.left(), matrix)

    def test_move_to_left_to_fail(self):
        matrix = [
            [1, 2, 3],
            [0, 8, 4],
            [7, 6, 5]]
        new = Puzzle(matrix)
        self.assertFalse(new.left())

    def test_move_to_right(self):
        matrix = [
            [1, 2, 3],
            [8, 4, 0],
            [7, 6, 5]]
        self.assertEquals(self.p.right(), matrix)

    def test_move_to_right_to_fail(self):
        matrix = [
            [1, 2, 3],
            [8, 4, 0],
            [7, 6, 5]]
        new = Puzzle(matrix)
        self.assertFalse(new.right())

    def test_copy_data(self):
        new_data = self.p.copy_data()
        self.assertEquals(self.p.matrix, new_data)