def test_error_message(self): rover4 = Rover("Rover-004", "E", 2, 4) grid2 = Grid([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, "rock", 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0], [0]]) result = Rover.moveForward(rover4, grid2) self.assertEqual(result, "There is a rock on y = 2 , x = 5") grid2.noPrivadoGrid[rover4.y][rover4.x] = 0
def test_not_detect_boundaries_move(self): rover = Rover() rover.move() self.assertEqual(rover.position_x, 1) self.assertEqual(rover.position_y, 0) self.assertEqual(False, self.plateau.detect_boundaries(rover))
def test_moveBackward(self): rover1 = Rover("Rover-001", "N", 5, 0) grid1 = Grid([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0], [0]]) Rover.moveBackward(rover1, grid1) self.assertEqual(rover1.y, 6) grid1.noPrivadoGrid[rover1.y][rover1.x] = 0
def test_grid_left(self): rover1 = Rover("Rover-001", "N", 0, 0) grid1 = Grid([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0], [0]]) Rover.commands(rover1, grid1, "lfff") self.assertEqual(rover1.y, 0) self.assertEqual(rover1.x, 0) grid1.noPrivadoGrid[rover1.y][rover1.x] = 0
def test_obstacle(self): rover1 = Rover("Rover-001", "N", 0, 0) grid1 = Grid([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, "rock", 0, 0, 0, 0, 0], [0, 0], [0]]) Rover.commands(rover1, grid1, "bbbbrf") self.assertEqual(rover1.y, 4) self.assertEqual(rover1.x, 0) grid1.noPrivadoGrid[rover1.y][rover1.x] = 0
def test_second_input(self): coordinate = Coordinate(3, 3) plateau = Plateau(5, 5) rover = Rover(coordinate, East()) RoverManager(plateau, rover).perform("MMRMMRMRRM") self.assertEqual(rover.coordinate, Coordinate(5, 1)) self.assertEqual(rover.direction, East())
def test_first_input(self): coordinate = Coordinate(1, 2) plateau = Plateau(5, 5) rover = Rover(coordinate, North()) RoverManager(plateau, rover).perform("LMLMLMLMM") self.assertEqual(rover.coordinate, Coordinate(1, 3)) self.assertEqual(rover.direction, North())
def test_grid(self): rover1 = Rover("Rover-001", "N", 0, 0) grid1 = Grid([[0, 0], [0, 0], ["Rover2", 0]]) grid2 = Grid([[0, "Rock"], [0, 0], ["Rover2", 0]]) # TODO ejecucion por Grid2 -> No se mueve a [0, 1] Rover.commands(rover1, grid2, "rf") self.assertEqual(rover1.y, 0) self.assertEqual(rover1.x, 0) # TODO Ejecucion por Grid 1 -> Si se mueve a [0, 1] Rover.commands(rover1, grid1, "rf") self.assertEqual(rover1.y, 1) self.assertEqual(rover1.x, 0)
def test_advanced_move(self): rover = Rover() rover.position_x = 5 rover.position_y = 5 rover.direction = 3 rover.move() self.assertEqual(rover.position_x, 5) self.assertEqual(rover.position_y, 6)
def test_start_initial_point(self): axe_x = 0 axe_y = 0 facing = 'N' pattern = '.*{}.*{}.*{}'.format(axe_x,axe_y,facing) end_point = Point() point = Point() rover = Rover(Point(),facing) result = re.match(str(pattern),str(rover)) self.assertTrue(result)
def test_detect_bondaries_move(self): rover = Rover() rover.position_x = 5 rover.position_y = 5 rover.direction = 3 rover.move() self.assertEqual(rover.position_x, 5) self.assertEqual(rover.position_y, 6) self.assertRaises(Exception, lambda: self.plateau.detect_boundaries(rover))
def test_turn_changes_direction_for_R_instruction(self): rover = Rover(self.coordinate, East()) rover.turn("R") self.assertEqual(rover.direction, South())
def test_move_when_pointed_east_in_x_direction_forward(self): rover = Rover(self.coordinate, East()) rover.move(self.plateau.is_coordinate_with_bounds) self.assertEqual(rover.coordinate, Coordinate(2, 2))
def test_move_when_pointed_west_in_x_direction_backwards(self): rover = Rover(self.coordinate, West()) rover.move(self.plateau.is_coordinate_with_bounds) self.assertEqual(rover.coordinate, Coordinate(0, 2))
def test_move_when_pointed_south_in_y_direction_downwards(self): rover = Rover(self.coordinate, South()) rover.move(self.plateau.is_coordinate_with_bounds) self.assertEqual(rover.coordinate, Coordinate(1, 1))
def test_turn_raised_exception_for_incorrect_instruction(self): rover = Rover(self.coordinate, East()) self.assertRaises(InstructionException, rover.turn("W"))
def test_basic_move(self): rover = Rover() rover.move() self.assertEqual(rover.position_x, 1) self.assertEqual(rover.position_y, 0)
def test_basic_methods(): # for future rover = Rover() rover.rotate_left() rover.rotate_right() rover.move() rover.parse_commands("LLMM") rover.get_location() rover.get_direction()
import io from flask import Flask, render_template, request, make_response, send_file import time try: from src.rover import Rover import picamera.array import picamera except ImportError as e: print(e) raise e app = Flask(__name__) rover = Rover() try: # Picamera setup cam_resolution = (200, 200) camera = picamera.PiCamera(resolution=cam_resolution) time.sleep(2) # Flip picture # camera.hflip = True # camera.vflip = True camera.rotation = 90 except ModuleNotFoundError as e: print(e) @app.route("/") def index(): return render_template("index.html")
def test_turnLeft(self): rover1 = Rover("Rover-001", "N", 0, 0) Rover.turnLeft(rover1) self.assertEqual(rover1.direction, "W")