Thoughtworks challenge in Graduate Program Recruitment
In this challenge I used JUnit library in order to make easier all test management. That is why I decided to convert the project to a maven project because it makes more comfortable to manage all dependencies.
I designed an OOP architecture for this project where we can find all de source code in main folder and all tests in test folder:
main
  java
    com
      thoughtworks
        MarsRover
          controller
            PlateauController.java
            PlateauControllerImpl.java
            RobotController.java
            RobotControllerImpl.java
          domain
            Plateau.java
            RoverRobot.java
          factory
            ServiceFactory.java
          service
            MarsRoverService.java
            MarsRoverServiceImpl.java
          Main.java
I created a controller for each domain model in order to control all the actions in relation with these items. I decided to create an interface for each controller because if we want to add a new behaviour in the future of this project, having an interface makes easier this issue.
create an instance of a plateau.create an instance of a robot, check if it can move, make a movement or rotate.I created a class for each model in this project with all parameters that they need.
x upper-right coordinate and a y upper-right coordinate.x coordinate, y coordinate and an orientation.I created a singleton class in order to restrict an only one instance of each service that we need in this project.
getXService() function for each X service that exists in this project.I created a service in order to group all the actions that some controllers have a relationship between them. I decided to create an interface for each service because if we want to add a new behaviour in the future of this project, having an interface makes easier this issue.
PlateauController and RobotController in order to solve the Mars Rover problem.I created a Main class as start point to run this project.
main function that reads from command line, runs solve function of MarsRoverService and print the solution through also command line.test
  java
    com
      thoughtworks
        MarsRover
          controller
            PlateauController.java
            RobotController.java
          domain
            Plateau.java
            RoverRobot.java
          factory
            ServiceFactory.java
          service
            MarsRoverService.java
I created a test class for each class in order to test the correct execution of their behaviour in all the possible situations, including input verification.
All classes and methods are documented in JavaDoc.
Needs: Java 6 & maven
MarsRoverAS.zipcd MarsRoverAS/mvn cleanmvn compilemvn exec:javaMarsRoverAS.zipcd MarsRoverAS/mvn cleanmvn compilemvn testA squad of robotic rovers are to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth.
A rover’s position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.
In order to control a rover, NASA sends a simple string of letters. The possible letters are ‘L’, ‘R’ and ‘M’. ‘L’ and ‘R’ makes the rover spin 90 degrees left or right respectively, without moving from its current spot. ‘M’ means move forward one grid point, and maintain the same heading.
Assume that the square directly North from (x, y) is (x, y+1).
Input:
Output:
Input and Output
Test Input:
5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM
Expected Output:
1 3 N
5 1 E
Copyright 2012 ThoughtWorks, Inc