Beispiel #1
0
    def test_possible_states(self):
        sp = SliderPuzzle(3)
        pm = sp.possible_moves()
        assert len(pm) == 2
        assert pm[0] == [ 1, 0, 2, 3, 4, 5, 6, 7, 8 ]
        assert pm[1] == [ 3, 1, 2, 0, 4, 5, 6, 7, 8 ]
        
        sp.puzzle = sp.swapped_state(0, 4)
        pm = sp.possible_moves()
        assert len(pm) == 4

        sp.puzzle = [4, 1, 2, 3, 0, 5, 6, 7, 8]
        exp_states = [
                        [4, 1, 2, 0, 3, 5, 6, 7, 8],
                        [4, 1, 2, 3, 5, 0, 6, 7, 8],
                        [4, 0, 2, 3, 1, 5, 6, 7, 8],
                        [4, 1, 2, 3, 7, 5, 6, 0, 8]
                        ]

        pm = sp.possible_moves()
        assert len(pm) == len(exp_states)
        for state in pm:
            assert state in exp_states
Beispiel #2
0
 def test_swap_state(self):
     sp = SliderPuzzle(3)
     swapped_sp = sp.swapped_state(0,8)
     assert swapped_sp[0] == 8
     assert swapped_sp[-1] == 0