Example #1
0
 def test_immutable_width(self):
     """
     Board width properties are immutable.
     """
     board = Board(width=4, height=4)
     with self.assertRaises(ValueError) as exc:
         board.width = 0
         self.assertEqual("Board width cannot be changed after creation.",
                          str(exc))
Example #2
0
 def test_immutable_height(self):
     """
     Board height properties are immutable.
     """
     board = Board(width=1, height=22)
     with self.assertRaises(ValueError) as exc:
         board.height = 8
         self.assertEqual("Board height cannot be changed after creation.",
                          str(exc))
Example #3
0
 def test_board_properties(self):
     """
     Confirm that a board has a height and width available as properties.
     """
     board = Board(height=45, width=16)
     self.assertEqual(45, board.height)
     self.assertEqual(16, board.width)
Example #4
0
    def test_multiple_placing(self):
        """
        Move the robot around a 5x5 board, requesting progress along the way.
        """
        robot = Robot(Board(5, 5))

        robot.place(13, 13, Aim.SOUTH)
        assert None == robot.report()

        robot.place(2, 2, Aim.WEST)
        robot.place(13, 13, Aim.SOUTH)
        assert '2,2,WEST' == robot.report()

        robot.place(1, 1, Aim.NORTH)
        robot.move()
        robot.move()
        robot.turn_right()
        robot.move()
        assert '2,3,EAST' == robot.report()

        robot.place(0, 5, Aim.NORTH)
        assert '2,3,EAST' == robot.report()

        robot.place(3, 4, Aim.SOUTH)
        assert '3,4,SOUTH' == robot.report()

        robot.move()
        robot.move()
        robot.move()
        robot.move()
        robot.turn_left()  # Turn to the East
        robot.move()
        robot.move()       # Try to walk off the table.
        assert '4,0,EAST' == robot.report()
Example #5
0
 def open_grid(self) :
     """ affiche un dialogue pour l'ouverture d'un fichier """
     filename, filter = QFileDialog.getOpenFileName(self , 'selectionner un fichier contenant une grille','./grids','*.json')
     print(filename)
     board, = Board.load_from_json(filename) 
     canvas = self.draw_Board ( board)
     
     self.label.setPixmap(canvas)
     self.setCentralWidget(self.label)
Example #6
0
def main(config):
    """
    Run the program using file as input.

    Output is to written standard out.

    :param config: Configuration dict. Must contain a key of 'file' that points to an open file handle.
    """
    runner = FileToFileRunner(config.file, sys.stdout, Parser(Robot(Board(5, 5))))
    runner.run()
    config.file.close()
Example #7
0
    def test_invalid_does_not_override(self):
        """
        Robot will not be replaced after place command.
        """
        expected = '2,3,EAST'

        robot = Robot(Board(16, 4))
        robot.place(2, 3, Aim.EAST)
        robot.place(16, 7, Aim.NORTH)
        actual = robot.report()

        assert expected == actual
Example #8
0
def get_place_and_move_scenarios():
    """
    List of valid commands.

    Calling report after all the commands should match the 'report' key.

    :return: List contain scenarios, consisting of commands and a final 'report' location/
    """
    return [
        ("Robot can report it's location after being placed on a single square board.",
         Board(1, 1), [('place', {
             'x': 0,
             'y': 0,
             'direction': Aim.NORTH
         })], '0,0,NORTH'),
        ('Robot moves North after given valid movement command.', Board(8, 8),
         [('place', {
             'x': 2,
             'y': 2,
             'direction': Aim.NORTH
         }), ('move', {})], '2,3,NORTH'),
        ('Robot moves South after given valid movement command.', Board(8, 8),
         [('place', {
             'x': 2,
             'y': 2,
             'direction': Aim.SOUTH
         }), ('move', {})], '2,1,SOUTH'),
        ('Robot moves East after given valid movement command.', Board(8, 8),
         [('place', {
             'x': 2,
             'y': 4,
             'direction': Aim.EAST
         }), ('move', {})], '3,4,EAST'),
        ('Robot moves West after given valid movement command.', Board(8, 8),
         [('place', {
             'x': 7,
             'y': 0,
             'direction': Aim.WEST
         }), ('move', {})], '6,0,WEST'),
        (
            'Robot turns right from North to East',
            Board(5, 5),
            [('place', {
                'x': 2,
                'y': 2,
                'direction': Aim.NORTH
            }), ('turn_right', {})],
            '2,2,EAST',
        ),
        (
            'Robot turns left from North to West',
            Board(5, 5),
            [('place', {
                'x': 2,
                'y': 2,
                'direction': Aim.NORTH
            }), ('turn_left', {})],
            '2,2,WEST',
        ),
        (
            'Robot turns left three times from North to East',
            Board(5, 5),
            [('place', {
                'x': 2,
                'y': 2,
                'direction': Aim.NORTH
            }), ('turn_left', {}), ('turn_left', {}), ('turn_left', {})],
            '2,2,EAST',
        ),
        (
            'Robot turns left three times from North to West',
            Board(5, 5),
            [('place', {
                'x': 2,
                'y': 2,
                'direction': Aim.NORTH
            }), ('turn_left', {}), ('turn_left', {}), ('turn_left', {})],
            '2,2,EAST',
        ),
        (
            'Robot turns left three times and then right to go from North to South',
            Board(5, 5),
            [('place', {
                'x': 2,
                'y': 2,
                'direction': Aim.NORTH
            }), ('turn_left', {}), ('turn_left', {}), ('turn_left', {}),
             ('turn_right', {})],
            '2,2,SOUTH',
        ),
        (
            '3x3 board. Robot starts in centre, turns to south, circuits the board, returns to top.',
            Board(3, 3),
            [
                ('place', {
                    'x': 1,
                    'y': 1,
                    'direction': Aim.EAST
                }),
                ('turn_right', {}),
                ('move', {}),  # After command, will be at bottom of board.
                ('turn_left', {}),  # Turn east.
                ('move', {}),  # Bottom right corner.
                ('turn_left', {}),
                ('move', {}),
                ('move', {}),  # Now at top right
                ('turn_left', {}),
                ('move', {}),
                ('move', {}),  # Now at top left.
                ('turn_left', {}),
                ('move', {}),
                ('move', {}),  # Now at bottom left.
                ('turn_left', {}),
                ('move', {}),
                ('turn_right', {}),
                ('turn_right', {}),
                ('turn_right', {}),
                ('move', {}),
                ('move', {}),
            ],
            '1,2,NORTH',
        ),
        (
            '1x1 board. Robot tries to walk off the edge in all directions.',
            Board(1, 1),
            [
                ('place', {
                    'x': 0,
                    'y': 0,
                    'direction': Aim.SOUTH
                }),
                ('move', {}),
                ('turn_right', {}),  # Turn to the West.
                ('move', {}),
                ('move', {}),
                ('turn_right', {}),  # North
                ('move', {}),
                ('move', {}),
                ('turn_right', {}),  # East
                ('move', {}),
                ('turn_left', {}),  # Back to North
                ('move', {}),
                ('move', {}),
                ('move', {}),
            ],
            '0,0,NORTH',
        ),
        (
            "Robot never gets placed. Make sure commands don't crash the program.",
            Board(1, 1),
            [
                ('place', {
                    'x': 3,
                    'y': 3,
                    'direction': Aim.SOUTH
                }),
                ('move', {}),
                ('turn_left', {}),  # Back to North
                ('turn_right', {}),  # Turn to the West.
            ],
            None),
        (
            '1x4 board. Robot tries to walk off the corners. Moves from South to North',
            Board(1, 4),
            [
                ('place', {
                    'x': 0,
                    'y': 3,
                    'direction': Aim.EAST
                }),
                ('move', {}),
                ('turn_right', {}),  # Turn South
                ('move', {}),
                ('move', {}),
                ('move', {}),
                ('turn_left', {}),  # Turn East
                ('move', {}),  # Edge of board
                ('turn_left', {}),  # Turn North
            ],
            '0,0,NORTH')
    ]
Example #9
0
def get_bad_place_scenarios():
    """
    List of placement values that should not produce a valid placement.

    Calling report after all these tests should produce "Not on the board yet!" error.

    :return: List contain scenarios, consisting of commands that do not make a valid placement.
    """
    return [('No placement yet.', Board(5, 5), []),
            ('No placement yet.', Board(1, 1), [('place', {
                'x': 5,
                'y': 5,
                'direction': Aim.SOUTH
            })]),
            ('Single placement, X too high.', Board(1, 1), [('place', {
                'x':
                0,
                'y':
                1,
                'direction':
                Aim.NORTH
            })]),
            ('Single placement, Y too high.', Board(1, 1), [('place', {
                'x':
                1,
                'y':
                0,
                'direction':
                Aim.NORTH
            })]),
            ('Single placement, X too low.', Board(3, 3), [('place', {
                'x':
                -4,
                'y':
                0,
                'direction':
                Aim.EAST
            })]),
            ('Single placement, Y too low.', Board(3, 3), [('place', {
                'x':
                1,
                'y':
                -2,
                'direction':
                Aim.WEST
            })]),
            ('Place multiple times invalid location. Do not place.',
             Board(16, 16), [('place', {
                 'x': -1,
                 'y': 4,
                 'direction': Aim.NORTH
             }), ('place', {
                 'x': 3,
                 'y': 17,
                 'direction': Aim.EAST
             }), ('place', {
                 'x': 7,
                 'y': 999999,
                 'direction': Aim.WEST
             }), ('place', {
                 'x': 20,
                 'y': 17,
                 'direction': Aim.SOUTH
             })])]