Created
May 17, 2013 20:42
-
-
Save pradeepcheers/5601841 to your computer and use it in GitHub Desktop.
First commit PlateauOfRobots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PlateauOfRobots |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="CompilerConfiguration"> | |
<option name="DEFAULT_COMPILER" value="Javac" /> | |
<resourceExtensions /> | |
<wildcardResourcePatterns> | |
<entry name="!?*.java" /> | |
<entry name="!?*.form" /> | |
<entry name="!?*.class" /> | |
<entry name="!?*.groovy" /> | |
<entry name="!?*.scala" /> | |
<entry name="!?*.flex" /> | |
<entry name="!?*.kt" /> | |
<entry name="!?*.clj" /> | |
</wildcardResourcePatterns> | |
<annotationProcessing> | |
<profile default="true" name="Default" enabled="false"> | |
<processorPath useClasspath="true" /> | |
</profile> | |
<profile default="false" name="Maven default annotation processors profile" enabled="true"> | |
<sourceOutputDir name="target/generated-sources/annotations" /> | |
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> | |
<outputRelativeToContentRoot value="true" /> | |
<processorPath useClasspath="true" /> | |
<module name="PlateauOfRobots" /> | |
</profile> | |
</annotationProcessing> | |
<bytecodeTargetLevel> | |
<module name="PlateauOfRobots" target="1.6" /> | |
</bytecodeTargetLevel> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="CopyrightManager"> | |
<settings default=""> | |
<module2copyright /> | |
</settings> | |
</component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" /> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="libraryTable"> | |
<library name="Maven: junit:junit-dep:4.10"> | |
<CLASSES> | |
<root url="jar://$MAVEN_REPOSITORY$/junit/junit-dep/4.10/junit-dep-4.10.jar!/" /> | |
</CLASSES> | |
<JAVADOC> | |
<root url="jar://$MAVEN_REPOSITORY$/junit/junit-dep/4.10/junit-dep-4.10-javadoc.jar!/" /> | |
</JAVADOC> | |
<SOURCES> | |
<root url="jar://$MAVEN_REPOSITORY$/junit/junit-dep/4.10/junit-dep-4.10-sources.jar!/" /> | |
</SOURCES> | |
</library> | |
</component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="libraryTable"> | |
<library name="Maven: org.hamcrest:hamcrest-core:1.2.1"> | |
<CLASSES> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.2.1/hamcrest-core-1.2.1.jar!/" /> | |
</CLASSES> | |
<JAVADOC> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.2.1/hamcrest-core-1.2.1-javadoc.jar!/" /> | |
</JAVADOC> | |
<SOURCES> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.2.1/hamcrest-core-1.2.1-sources.jar!/" /> | |
</SOURCES> | |
</library> | |
</component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="libraryTable"> | |
<library name="Maven: org.hamcrest:hamcrest-library:1.2.1"> | |
<CLASSES> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-library/1.2.1/hamcrest-library-1.2.1.jar!/" /> | |
</CLASSES> | |
<JAVADOC> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-library/1.2.1/hamcrest-library-1.2.1-javadoc.jar!/" /> | |
</JAVADOC> | |
<SOURCES> | |
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-library/1.2.1/hamcrest-library-1.2.1-sources.jar!/" /> | |
</SOURCES> | |
</library> | |
</component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="JavadocGenerationManager"> | |
<option name="OUTPUT_DIRECTORY" value="$PROJECT_DIR$/src/doc" /> | |
<option name="OPTION_SCOPE" value="protected" /> | |
<option name="OPTION_HIERARCHY" value="true" /> | |
<option name="OPTION_NAVIGATOR" value="true" /> | |
<option name="OPTION_INDEX" value="true" /> | |
<option name="OPTION_SEPARATE_INDEX" value="true" /> | |
<option name="OPTION_DOCUMENT_TAG_USE" value="false" /> | |
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" /> | |
<option name="OPTION_DOCUMENT_TAG_VERSION" value="false" /> | |
<option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true" /> | |
<option name="OPTION_DEPRECATED_LIST" value="true" /> | |
<option name="OTHER_OPTIONS" /> | |
<option name="HEAP_SIZE" /> | |
<option name="LOCALE" /> | |
<option name="OPEN_IN_BROWSER" value="true" /> | |
<option name="OPTION_INCLUDE_LIBS" value="false" /> | |
</component> | |
<component name="MavenProjectsManager"> | |
<option name="originalFiles"> | |
<list> | |
<option value="$PROJECT_DIR$/pom.xml" /> | |
</list> | |
</option> | |
</component> | |
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK"> | |
<output url="file://$PROJECT_DIR$/out" /> | |
</component> | |
<component name="masterDetails"> | |
<states> | |
<state key="ProjectJDKs.UI"> | |
<settings> | |
<splitter-proportions> | |
<option name="proportions"> | |
<list> | |
<option value="0.2" /> | |
</list> | |
</option> | |
</splitter-proportions> | |
</settings> | |
</state> | |
</states> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/PlateauOfRobots.iml" filepath="$PROJECT_DIR$/PlateauOfRobots.iml" /> | |
</modules> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="DependencyValidationManager"> | |
<state> | |
<option name="SKIP_IMPORT_STATEMENTS" value="false" /> | |
</state> | |
</component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="Palette2"> | |
<group name="Swing"> | |
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> | |
</item> | |
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> | |
</item> | |
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> | |
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> | |
<initial-values> | |
<property name="text" value="Button" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="RadioButton" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="CheckBox" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="Label" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | |
<preferred-size width="200" height="200" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | |
<preferred-size width="200" height="200" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> | |
</item> | |
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> | |
<preferred-size width="-1" height="20" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> | |
</item> | |
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> | |
</item> | |
</group> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="VcsDirectoryMappings"> | |
<mapping directory="" vcs="" /> | |
</component> | |
</project> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false"> | |
<output url="file://$MODULE_DIR$/target/classes" /> | |
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" /> | |
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | |
<excludeFolder url="file://$MODULE_DIR$/target" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
<orderEntry type="library" name="Maven: junit:junit-dep:4.10" level="project" /> | |
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.2.1" level="project" /> | |
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-library:1.2.1" level="project" /> | |
</component> | |
</module> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.newsinternational.exercise</groupId> | |
<artifactId>PlateauOfRobots</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>2.0.2</version> | |
<configuration> | |
<source>1.6</source> | |
<target>1.6</target> | |
<showDeprecation>true</showDeprecation> | |
</configuration> | |
</plugin> | |
<plugin> | |
<artifactId>maven-assembly-plugin</artifactId> | |
<version>2.2-beta-5</version> | |
<configuration> | |
<descriptorRefs> | |
<descriptorRef>jar-with-dependencies</descriptorRef> | |
</descriptorRefs> | |
<archive> | |
<manifest> | |
<mainClass>com.newsinternational.exercise.client.PlateauOfRobotsMainTest</mainClass> | |
</manifest> | |
</archive> | |
</configuration> | |
<executions> | |
<execution> | |
<id>make-assembly</id> | |
<phase>package</phase> | |
<goals> | |
<goal>single</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit-dep</artifactId> | |
<version>4.10</version> | |
</dependency> | |
<dependency> | |
<groupId>org.hamcrest</groupId> | |
<artifactId>hamcrest-core</artifactId> | |
<version>1.2.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.hamcrest</groupId> | |
<artifactId>hamcrest-library</artifactId> | |
<version>1.2.1</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.client; | |
import com.newsinternational.exercise.Robot; | |
import com.newsinternational.exercise.exception.InvalidInputException; | |
import com.newsinternational.exercise.exception.OutOfPlateauBoundaryException; | |
import com.newsinternational.exercise.implementation.EnvironmentSetUp; | |
import java.util.Scanner; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Class acts like a client to test code in command line | |
*/ | |
public class PlateauOfRobotsMainTest { | |
public static void main(String [] args) throws InvalidInputException { | |
String reTest; | |
Scanner input = new Scanner (System.in); | |
Robot robot; | |
System.out.println("Please enter Plateau co-ordinates Eg - '5 5':"); | |
try { | |
EnvironmentSetUp.loadPlateau(input.nextLine()); | |
} catch (InvalidInputException e) { | |
System.out.println(e.getMessage()); | |
} | |
EnvironmentSetUp environmentSetUp = new EnvironmentSetUp(); | |
do { | |
try { | |
System.out.println("Now enter a Robot position Eg - '5 5 N':"); | |
robot = environmentSetUp.createAndDeployRobot(input.nextLine()); | |
System.out.println("Enter movement instructions Eg - 'LMLMRMM':"); | |
robot.move(input.nextLine()); | |
System.out.println("Current position of Robot is "); | |
System.out.println(environmentSetUp.getRobot().getPosition().toString()); | |
} catch (InvalidInputException e) { | |
System.out.println(e.getMessage()); | |
} catch (OutOfPlateauBoundaryException e) { | |
System.out.println(e.getMessage()); | |
} | |
System.out.println("Add another Robot? (y/n)"); | |
reTest = input.nextLine(); | |
} while(reTest.equalsIgnoreCase("Y") || reTest.equalsIgnoreCase("YES")); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.constant; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Class responsible for holding all the constant values | |
*/ | |
public class Constants { | |
/** | |
* Constant string values | |
*/ | |
public static class StringConstants { | |
public static final String SEPARATOR = " "; | |
public static final String PLATEAU_PATTERN = "^[1-9]\\d*\\s[1-9]\\d*$"; | |
public static final String ROBOT_POSITION_PATTERN = "^[1-9]\\d*\\s[1-9]\\d*\\s[neswNESW]$"; | |
public static final String MOVEMENT_INSTRUCTION_PATTERN = "^[lmrLMR]+$"; | |
public static final String LEFT = "L"; | |
public static final String RIGHT = "R"; | |
public static final String MOVE = "M"; | |
} | |
/** | |
* Constant integer values | |
*/ | |
public static class NumberConstants { | |
public static final int ZERO = 0; | |
public static final int ONE = 1; | |
public static final int TWO = 2; | |
} | |
/** | |
* Error messages | |
*/ | |
public static class ErrorMessages { | |
public static final String EMPTY_INPUT = "Input is null or empty"; | |
public static final String INCORRECT_PLATEAU_INPUT = "Plateau co-ordinates entered are incorrect"; | |
public static final String INCORRECT_ROBOT_POSITION = "Robot position entered is incorrect"; | |
public static final String INCORRECT_MOVEMENT_INSTRUCTIONS = "Movement instructions entered are incorrect"; | |
public static final String OUT_OF_PLATEAU = "Robot positioned out of Plateau"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.exception; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Exception Class | |
*/ | |
public class InvalidInputException extends Exception { | |
/** | |
* Constuctor | |
* @param errorMessage | |
* @see Exception | |
*/ | |
public InvalidInputException(String errorMessage) { | |
super(errorMessage); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.exception; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Exception Class | |
*/ | |
public class OutOfPlateauBoundaryException extends Exception { | |
/** | |
* Constuctor | |
* @param errorMessage | |
* @see Exception | |
*/ | |
public OutOfPlateauBoundaryException(String errorMessage) { | |
super(errorMessage); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.implementation; | |
import com.newsinternational.exercise.Robot; | |
import com.newsinternational.exercise.constant.Constants; | |
import com.newsinternational.exercise.exception.InvalidInputException; | |
import com.newsinternational.exercise.exception.OutOfPlateauBoundaryException; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* To change this template use File | Settings | File Templates. | |
*/ | |
public class EnvironmentSetUp { | |
/** | |
* Perform validation on input | |
* @return validated input | |
*/ | |
//Robot instance | |
private Robot robot; | |
/** | |
* Loads plateau co-ordinates input to Plateau Enum. | |
* @param plateauInput | |
* @throws InvalidInputException | |
* @see com.newsinternational.exercise.implementation.PlateauImplementation | |
*/ | |
public static void loadPlateau(String plateauInput) throws InvalidInputException { | |
plateauInput = validateInput(plateauInput); | |
validateInputPattern(plateauInput, Constants.StringConstants.PLATEAU_PATTERN, Constants.ErrorMessages.INCORRECT_PLATEAU_INPUT); | |
PlateauImplementation.INSTANCE.loadPlateau(plateauInput); | |
} | |
/** | |
* Load Robots starting position | |
* @param robotPosition | |
* @throws InvalidInputException, OutOfPlateauBoundaryException | |
* @see com.newsinternational.exercise.implementation.RobotImplementation | |
*/ | |
public Robot createAndDeployRobot(String robotPosition) throws InvalidInputException, OutOfPlateauBoundaryException { | |
robotPosition = validateInput(robotPosition); | |
if (PlateauImplementation.INSTANCE.isPlateauLoaded()) { | |
validateInputPattern(robotPosition, Constants.StringConstants.ROBOT_POSITION_PATTERN, Constants.ErrorMessages.INCORRECT_ROBOT_POSITION); | |
validateBoundary(robotPosition); | |
robot = new RobotImplementation(robotPosition); | |
PlateauImplementation.INSTANCE.getRobotsOnPlateau().add(robot); | |
} else { | |
throw new InvalidInputException(Constants.ErrorMessages.INCORRECT_ROBOT_POSITION); | |
} | |
return robot; | |
} | |
/** | |
* Input validation | |
* @param input | |
* @return | |
* @throws InvalidInputException | |
*/ | |
static String validateInput(String input) throws InvalidInputException { | |
if(input == null || input.equalsIgnoreCase("")) | |
throw new InvalidInputException(Constants.ErrorMessages.EMPTY_INPUT); | |
return input.toUpperCase(); | |
} | |
/** | |
* Validation for input pattern | |
* @param param | |
* @param regex | |
* @param errorMessage | |
* @throws InvalidInputException | |
*/ | |
static void validateInputPattern(String param, String regex, String errorMessage) throws InvalidInputException { | |
Pattern pattern; | |
Matcher patternMatch; | |
pattern = Pattern.compile(regex); | |
patternMatch = pattern.matcher(param); | |
if(!patternMatch.matches()) | |
throw new InvalidInputException(errorMessage); | |
} | |
/** | |
* Validates the starting position of Robot with the Plateau boundary limit | |
* @param robotPosition | |
* @throws OutOfPlateauBoundaryException | |
*/ | |
static void validateBoundary(String robotPosition) throws OutOfPlateauBoundaryException { | |
String [] coOrdinates = robotPosition.split(Constants.StringConstants.SEPARATOR); | |
if (PlateauImplementation.INSTANCE.getxCoOrdinate() < Integer.parseInt(coOrdinates[Constants.NumberConstants.ZERO])) | |
throw new OutOfPlateauBoundaryException(Constants.ErrorMessages.OUT_OF_PLATEAU); | |
if (PlateauImplementation.INSTANCE.getyCoOrdinate() < Integer.parseInt(coOrdinates[Constants.NumberConstants.ONE])) | |
throw new OutOfPlateauBoundaryException(Constants.ErrorMessages.OUT_OF_PLATEAU); | |
} | |
// Robot getter method | |
public Robot getRobot() { | |
return robot; | |
} | |
/** | |
* Clears environment by undeploying all Robots | |
*/ | |
public static void clearEnvironment() { | |
PlateauImplementation.INSTANCE.setRobotsOnPlateau(null); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.implementation; | |
import com.newsinternational.exercise.Plateau; | |
import com.newsinternational.exercise.Robot; | |
import com.newsinternational.exercise.constant.Constants; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Enum responsible for storing Plateau co-ordinates | |
*/ | |
public enum PlateauImplementation implements Plateau{ | |
//singleton | |
INSTANCE; | |
private int xCoOrdinate; | |
private int yCoOrdinate; | |
private List<Robot> robotsOnPlateau; | |
private static boolean isPlateauLoaded = false; | |
public int getxCoOrdinate() { | |
return xCoOrdinate; | |
} | |
public int getyCoOrdinate() { | |
return yCoOrdinate; | |
} | |
private void setxCoOrdinate(int xCoOrdinate) { | |
this.xCoOrdinate = xCoOrdinate; | |
} | |
private void setyCoOrdinate(int yCoOrdinate) { | |
this.yCoOrdinate = yCoOrdinate; | |
} | |
public List<Robot> getRobotsOnPlateau() { | |
if(robotsOnPlateau == null) | |
robotsOnPlateau = new ArrayList<Robot>(); | |
return robotsOnPlateau; | |
} | |
public void setRobotsOnPlateau(List<Robot> robotsOnPlateau) { | |
this.robotsOnPlateau = robotsOnPlateau; | |
} | |
/** | |
* Loads Plateau co-ordinates from the input | |
* @param plateau | |
*/ | |
public void loadPlateau(String plateau) { | |
String [] input = plateau.split(Constants.StringConstants.SEPARATOR); | |
this.setxCoOrdinate(Integer.parseInt(input[Constants.NumberConstants.ZERO])); | |
this.setyCoOrdinate(Integer.parseInt(input[Constants.NumberConstants.ONE])); | |
isPlateauLoaded = true; | |
} | |
/** | |
* Confirms if Plateau co-ordinates are loaded | |
* @return | |
*/ | |
public boolean isPlateauLoaded() { | |
return isPlateauLoaded; | |
} | |
public int getRobotCount() { | |
return robotsOnPlateau.size(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.implementation; | |
import com.newsinternational.exercise.constant.Constants; | |
import com.newsinternational.exercise.utility.Direction; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Class responsible for Holding the position of the Robot on Plateau | |
*/ | |
public class Position { | |
// x - co-ordinate | |
private int xCoOrdinate; | |
// x - co-ordinate | |
private int yCoOrdinate; | |
// direction | |
private Direction direction; | |
//constructor | |
public Position(int xCoOrdinate, int yCoOrdinate, Direction direction) { | |
this.xCoOrdinate = xCoOrdinate; | |
this.yCoOrdinate = yCoOrdinate; | |
this.direction = direction; | |
} | |
//constructor | |
public Position (String robotPosition) { | |
this.loadRobotPosition(robotPosition); | |
} | |
public int getxCoOrdinate() { | |
return xCoOrdinate; | |
} | |
void setxCoOrdinate(int xCoOrdinate) { | |
this.xCoOrdinate = xCoOrdinate; | |
} | |
public int getyCoOrdinate() { | |
return yCoOrdinate; | |
} | |
void setyCoOrdinate(int yCoOrdinate) { | |
this.yCoOrdinate = yCoOrdinate; | |
} | |
public Direction getDirection() { | |
return direction; | |
} | |
void setDirection(Direction direction) { | |
this.direction = direction; | |
} | |
/** | |
* Method responsible for loading the co-ordinates and the direction of the Robot on Plateau | |
* @param robotPosition | |
* @return | |
*/ | |
public Position loadRobotPosition(String robotPosition) { | |
String [] input = robotPosition.split(Constants.StringConstants.SEPARATOR); | |
this.setxCoOrdinate(Integer.parseInt(input[Constants.NumberConstants.ZERO])); | |
this.setyCoOrdinate(Integer.parseInt(input[Constants.NumberConstants.ONE])); | |
this.setDirection(Direction.valueOf(input[Constants.NumberConstants.TWO].toUpperCase())); | |
return this; | |
} | |
/** | |
* Method responsible for displaying the current position of the Robot | |
* @return | |
*/ | |
public String toString() { | |
return Integer.toString(this.getxCoOrdinate()) + Constants.StringConstants.SEPARATOR + | |
Integer.toString(this.getyCoOrdinate()) + Constants.StringConstants.SEPARATOR + | |
this.getDirection(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.implementation; | |
import com.newsinternational.exercise.Plateau; | |
import com.newsinternational.exercise.Robot; | |
import com.newsinternational.exercise.constant.Constants; | |
import com.newsinternational.exercise.exception.InvalidInputException; | |
import com.newsinternational.exercise.exception.OutOfPlateauBoundaryException; | |
import com.newsinternational.exercise.utility.Direction; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* | |
* This is a Robot implementation class for the Robot interface with methods such as move and getRobotPosition | |
*/ | |
public class RobotImplementation implements Robot { | |
// Holds position of a Robot | |
private Position position; | |
// Holds Robot id | |
private int id; | |
// Robot counter | |
private static int count = 0; | |
/** | |
* Constructor | |
* @param robotPosition | |
* @see com.newsinternational.exercise.implementation.Position | |
*/ | |
public RobotImplementation(String robotPosition) { | |
position = new Position(robotPosition); //Holds starting position | |
id = count++; | |
} | |
/** | |
* Method responsible for robot's movement based on the movement instruction and stores the current position in Position object | |
* @param movementInstruction | |
* @see com.newsinternational.exercise.implementation.Position | |
*/ | |
@Override | |
public void move(String movementInstruction) throws InvalidInputException, OutOfPlateauBoundaryException { | |
movementInstruction = EnvironmentSetUp.validateInput(movementInstruction); | |
if (PlateauImplementation.INSTANCE.isPlateauLoaded()) { | |
EnvironmentSetUp.validateInputPattern(movementInstruction, Constants.StringConstants.MOVEMENT_INSTRUCTION_PATTERN, Constants.ErrorMessages.INCORRECT_MOVEMENT_INSTRUCTIONS); | |
} else { | |
throw new InvalidInputException(Constants.ErrorMessages.INCORRECT_MOVEMENT_INSTRUCTIONS); | |
} | |
for(Character character : movementInstruction.toCharArray()) { | |
if(character.toString().equalsIgnoreCase(Constants.StringConstants.LEFT) || character.toString().equalsIgnoreCase(Constants.StringConstants.RIGHT)) | |
position.setDirection(Direction.getNextDirection(position.getDirection(), character.toString())); | |
if(character.toString().equalsIgnoreCase(Constants.StringConstants.MOVE)) | |
this.moveCoOrdinates(position.getDirection()); | |
} | |
} | |
/** | |
* Based on the movement instruction direction and boundary limit, decides to move robot | |
* @param currentDirection | |
* @throws OutOfPlateauBoundaryException | |
* @see com.newsinternational.exercise.implementation.Position | |
*/ | |
private void moveCoOrdinates(Direction currentDirection) throws OutOfPlateauBoundaryException { | |
int xCoOrdinate = position.getxCoOrdinate(); | |
int yCoOrdinate = position.getyCoOrdinate(); | |
if (currentDirection.equals(Direction.E) && (++xCoOrdinate <= PlateauImplementation.INSTANCE.getxCoOrdinate())) { | |
position.setxCoOrdinate(xCoOrdinate); | |
} else if (currentDirection.equals(Direction.W) && (--xCoOrdinate >= Constants.NumberConstants.ZERO)) { | |
position.setxCoOrdinate(xCoOrdinate); | |
} else if (currentDirection.equals(Direction.N) && (++yCoOrdinate <= PlateauImplementation.INSTANCE.getyCoOrdinate())) { | |
position.setyCoOrdinate(yCoOrdinate); | |
} else if ((currentDirection.equals(Direction.S) && (--yCoOrdinate >= Constants.NumberConstants.ZERO))) { | |
position.setyCoOrdinate(yCoOrdinate); | |
} else { | |
throw new OutOfPlateauBoundaryException(Constants.ErrorMessages.OUT_OF_PLATEAU); | |
} | |
} | |
/** | |
* Retrieves current position of Robot from Position object | |
* @return Current position of Robot | |
*/ | |
@Override | |
public Position getPosition() { | |
return position; | |
} | |
/** | |
* Returns Robot's id | |
* @return | |
*/ | |
public int getId() { | |
return id; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise; | |
import java.util.List; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Interface representing Plateau | |
*/ | |
public interface Plateau { | |
// Method for retrieving x-coordinate | |
public int getxCoOrdinate(); | |
// Method for retrieving y-coordinate | |
public int getyCoOrdinate(); | |
// List represents list of Robots on Plateau | |
public List<Robot> getRobotsOnPlateau(); | |
// Used to check if Plateau is loaded | |
public boolean isPlateauLoaded(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise; | |
import com.newsinternational.exercise.exception.InvalidInputException; | |
import com.newsinternational.exercise.exception.OutOfPlateauBoundaryException; | |
import com.newsinternational.exercise.implementation.Position; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Interface represents Robot | |
*/ | |
public interface Robot { | |
/** | |
* Robot movement is handled based on the movement instructions to explore Plateau | |
* @param path | |
*/ | |
public void move(String path) throws InvalidInputException, OutOfPlateauBoundaryException; | |
/** | |
* Retrieves current position of the Robot | |
*/ | |
public Position getPosition(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.utility; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Enum stores directions, retrieving the direction of the Robot based on movement instruction | |
*/ | |
public enum Direction { | |
// Enum constant Direction(directionToTheLeft, directionToTheRight) | |
N("W", "E"), | |
E("N", "S"), | |
S("E", "W"), | |
W("S", "N"); | |
private final String toTheLeft; | |
private final String toTheRight; | |
public Direction getToTheLeft() { | |
return Direction.valueOf(toTheLeft); | |
} | |
public Direction getToTheRight() { | |
return Direction.valueOf(toTheRight); | |
} | |
// Constructor | |
Direction(String left, String right) { | |
this.toTheLeft = left; | |
this.toTheRight = right; | |
} | |
/** | |
* Retrieves direction for the Robot based on movement instruction | |
* @param currentDirection | |
* @param nextMovement | |
* @return | |
*/ | |
public static Direction getNextDirection(Direction currentDirection, String nextMovement) { | |
return (nextMovement.equalsIgnoreCase("L")) ? | |
currentDirection.getToTheLeft() : | |
currentDirection.getToTheRight(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Manifest-Version: 1.0 | |
Main-Class: com.newsinternational.exercise.RobotGameTest | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.implementation; | |
import com.newsinternational.exercise.exception.InvalidInputException; | |
import com.newsinternational.exercise.exception.OutOfPlateauBoundaryException; | |
import org.junit.Before; | |
import org.junit.Test; | |
import static org.hamcrest.core.Is.is; | |
import static org.junit.Assert.assertThat; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Tests responsible for testing EnvironmentSetUp | |
*/ | |
public class EnvironmentSetUpTest { | |
private EnvironmentSetUp environmentSetUp; | |
@Before | |
public void init(){ | |
environmentSetUp = new EnvironmentSetUp(); | |
} | |
@Test | |
public void testValidateInputForString() throws InvalidInputException{ | |
assertThat(EnvironmentSetUp.validateInput("1 1 N"), is("1 1 N")); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void testValidateInputForNull() throws InvalidInputException{ | |
String nullValue = null; | |
assertThat(environmentSetUp.validateInput(nullValue), is(nullValue)); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void testValidateInputForEmptyString() throws InvalidInputException{ | |
String nullValue = ""; | |
assertThat(environmentSetUp.validateInput(nullValue), is("")); | |
} | |
@Test | |
public void testValidateInputForAnyString() throws InvalidInputException{ | |
assertThat(environmentSetUp.validateInput("XXXX"), is("XXXX")); | |
} | |
@Test | |
public void testCompleteFlow() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("9 9"); | |
environmentSetUp.createAndDeployRobot("1 1 N").move("RMM"); | |
assertThat("3 1 E", is(environmentSetUp.getRobot().getPosition().toString())); | |
} | |
@Test | |
public void testCompleteFlowOne() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 N").move("LMLMLMLMM"); | |
assertThat("1 3 N", is(environmentSetUp.getRobot().getPosition().toString())); | |
} | |
@Test | |
public void checkLeftDirectFromNorth() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 N").move("L"); | |
assertThat("W", is(environmentSetUp.getRobot().getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkLeftDirectFromWest() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 W").move("L"); | |
assertThat("S", is(environmentSetUp.getRobot().getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkLeftDirectFromSouth() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 S").move("L"); | |
assertThat("E", is(environmentSetUp.getRobot().getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkLeftDirectFromEast() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 E").move("L"); | |
assertThat("N", is(environmentSetUp.getRobot().getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkRightDirectFromNorth() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 N").move("R"); | |
assertThat("E", is(environmentSetUp.getRobot().getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkRightDirectFromEast() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 E").move("R"); | |
assertThat("S", is(environmentSetUp.getRobot().getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkRightDirectFromSouth() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 S").move("R"); | |
assertThat("W", is(environmentSetUp.getRobot().getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkRightDirectFromWest() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 W").move("R"); | |
assertThat("N", is(environmentSetUp.getRobot().getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkOneMoveFromNorth() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 N").move("M"); | |
assertThat(3, is(environmentSetUp.getRobot().getPosition().getyCoOrdinate())); | |
} | |
@Test | |
public void checkOneMoveFromSouth() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 S").move("M"); | |
assertThat(1, is(environmentSetUp.getRobot().getPosition().getyCoOrdinate())); | |
} | |
@Test | |
public void checkOneMoveFromEast() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 E").move("M"); | |
assertThat(2, is(environmentSetUp.getRobot().getPosition().getxCoOrdinate())); | |
} | |
@Test | |
public void checkOneMoveFromWest() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 2 W").move("M"); | |
assertThat(0, is(environmentSetUp.getRobot().getPosition().getxCoOrdinate())); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidRobotPositionInput() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 -2 W").move("M"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidRobotPositionInputOne() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("12 W").move("M"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidRobotPositionInputTwo() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("01 -2 W").move("M"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidRobotPositionInputThree() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("3 4.0 S").move("M"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidRobotPositionInputFour() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("1 0 F").move("M"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidRobotPositionInputFive() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("-12 W").move("M"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidPlateauInput() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 05"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidPlateauInputOne() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("05 5"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidPlateauInputTwo() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("-5 5"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidPlateauInputThree() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 -5"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidPlateauInputFour() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("ab ab"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidPlateauInputFive() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("a b"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidMovementInstructionInput() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 5"); | |
environmentSetUp.createAndDeployRobot("5 5 S").move("-M"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidMovementInstructionInputOne() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("05 5"); | |
environmentSetUp.createAndDeployRobot("2 2 S").move("-6"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidMovementInstructionInputTwo() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("-5 5"); | |
environmentSetUp.createAndDeployRobot("2 2 S").move("0"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidMovementInstructionInputThree() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("5 -5"); | |
environmentSetUp.createAndDeployRobot("2 2 S").move("S"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidMovementInstructionInputFour() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("ab ab"); | |
environmentSetUp.createAndDeployRobot("2 2 S").move("LMA"); | |
} | |
@Test (expected = InvalidInputException.class) | |
public void checkInvalidMovementInstructionInputFive() throws InvalidInputException, OutOfPlateauBoundaryException { | |
EnvironmentSetUp.loadPlateau("a b"); | |
environmentSetUp.createAndDeployRobot("2 2 S").move("a"); | |
} | |
@Test | |
public void checkCountOfRobotsOnPlateau() throws InvalidInputException, OutOfPlateauBoundaryException{ | |
EnvironmentSetUp.clearEnvironment(); | |
EnvironmentSetUp.loadPlateau("4 4"); | |
EnvironmentSetUp env1 = new EnvironmentSetUp(); | |
env1.createAndDeployRobot("2 1 N"); | |
env1.createAndDeployRobot("3 2 N"); | |
assertThat(2, is(PlateauImplementation.INSTANCE.getRobotCount())); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.implementation; | |
import org.junit.Test; | |
import static org.hamcrest.core.Is.is; | |
import static org.junit.Assert.assertThat; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Tests for PlateauImplementation class | |
*/ | |
public class PlateauImplementationTest { | |
@Test | |
public void testLoadPlateau() { | |
PlateauImplementation.INSTANCE.loadPlateau("3 8"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("3 8")); | |
} | |
@Test | |
public void testPlateauLoadOne() { | |
PlateauImplementation.INSTANCE.loadPlateau("99 99"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("99 99")); | |
} | |
@Test | |
public void testPlateauLoadTwo() { | |
PlateauImplementation.INSTANCE.loadPlateau("99999 99999"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("99999 99999")); | |
} | |
@Test | |
public void testPlateauLoadThree() { | |
PlateauImplementation.INSTANCE.loadPlateau("0 0"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("0 0")); | |
} | |
@Test | |
public void testPlateauLoadFour() { | |
PlateauImplementation.INSTANCE.loadPlateau("123 345"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("123 345")); | |
} | |
@Test | |
public void testPlateauLoadFive() { | |
PlateauImplementation.INSTANCE.loadPlateau("7654 675678"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("7654 675678")); | |
} | |
@Test | |
public void testPlateauLoadSix() { | |
PlateauImplementation.INSTANCE.loadPlateau("64 64"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("64 64")); | |
} | |
@Test | |
public void testPlateauLoadSeven() { | |
PlateauImplementation.INSTANCE.loadPlateau("3 3"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("3 3")); | |
} | |
@Test | |
public void testPlateauLoadEight() { | |
PlateauImplementation.INSTANCE.loadPlateau("1 1"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("1 1")); | |
} | |
@Test | |
public void testPlateauLoadNine() { | |
PlateauImplementation.INSTANCE.loadPlateau("99 0"); | |
assertThat(PlateauImplementation.INSTANCE.getxCoOrdinate() + " " + | |
PlateauImplementation.INSTANCE.getyCoOrdinate(), is("99 0")); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.implementation; | |
import com.newsinternational.exercise.Robot; | |
import com.newsinternational.exercise.exception.InvalidInputException; | |
import com.newsinternational.exercise.exception.OutOfPlateauBoundaryException; | |
import org.junit.Test; | |
import static org.hamcrest.core.Is.is; | |
import static org.junit.Assert.assertThat; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Tests for RobotImplementation class | |
*/ | |
public class RobotImplementationTest { | |
Robot robot; | |
@Test | |
public void testRobotInitialPosition() { | |
robot = new RobotImplementation("1 1 N"); | |
assertThat("1 1 N", is(robot.getPosition().toString())); | |
} | |
@Test | |
public void testRobotInitialPositionTwo() { | |
robot = new RobotImplementation("99 99 W"); | |
assertThat("99 99 W", is(robot.getPosition().toString())); | |
} | |
@Test | |
public void testRobotInitialPositionThree() { | |
robot = new RobotImplementation("5 5 e"); | |
assertThat("5 5 E", is(robot.getPosition().toString())); | |
} | |
@Test | |
public void testRobotInitialPositionFour() { | |
robot = new RobotImplementation("99 99999 s"); | |
assertThat("99 99999 S", is(robot.getPosition().toString())); | |
} | |
@Test | |
public void testRobotInitialPositionFive() { | |
robot = new RobotImplementation("7 5 S"); | |
assertThat("7 5 S", is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidForOneMoveTestNorth() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
assertThat("5 6 N",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidForOneMoveTestSouth() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 S"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
assertThat("5 4 S",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidL() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("1 1 E"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("LLLL"); | |
assertThat("1 1 E",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidR() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("1 1 E"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("RRRR"); | |
assertThat("1 1 E",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidSN() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("1 1 S"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("RR"); | |
assertThat("1 1 N",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidNS() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("1 3 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("LL"); | |
assertThat("1 3 S",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidThreeMovesSameDirection() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("1 1 E"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("MMM"); | |
assertThat("4 1 E",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidThreeMovesOppositeDirection() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("LLMMM"); | |
assertThat("5 2 S",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidMovesLongTest() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("LMMMMMLMMMMMLMMMMMMMLMMMMMMM"); | |
assertThat("7 7 N",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldMoveBeValidMovesLongTestRight() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("RMMRMMMMMRMMMMMMMRMMMMMRMMMMMR"); | |
assertThat("5 5 S",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void shouldOneMoveFromEast() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 E"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("L"); | |
assertThat("N",is(robot.getPosition().getDirection().toString())); | |
} | |
@Test | |
public void shouldOneMoveFromWest() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 W"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("L"); | |
assertThat("S",is(robot.getPosition().getDirection().toString())); | |
} | |
@Test | |
public void shouldOneMoveFromNorth() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("L"); | |
assertThat("W",is(robot.getPosition().getDirection().toString())); | |
} | |
@Test | |
public void shouldOneMoveFromSouth() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 S"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("L"); | |
assertThat("E",is(robot.getPosition().getDirection().toString())); | |
} | |
@Test | |
public void shouldOneRightMoveFromEast() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 E"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("R"); | |
assertThat("S",is(robot.getPosition().getDirection().toString())); | |
} | |
@Test | |
public void shouldOneRightMoveFromWest() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 W"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("R"); | |
assertThat("N",is(robot.getPosition().getDirection().toString())); | |
} | |
@Test | |
public void shouldOneRightMoveFromNorth() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("R"); | |
assertThat("E",is(robot.getPosition().getDirection().toString())); | |
} | |
@Test | |
public void shouldOneRightMoveFromSouth() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 S"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("R"); | |
assertThat("W",is(robot.getPosition().getDirection().toString())); | |
} | |
@Test | |
public void checkPositonFacingNorthMoveForward() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
assertThat("5 6 N",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void checkPositonFacingSouthMoveForward() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 S"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
assertThat("5 4 S",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void checkPositonFacingEastMoveForward() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 E"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
assertThat("6 5 E",is(robot.getPosition().toString())); | |
} | |
@Test | |
public void checkPositonFacingWestMoveForward() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("5 5 W"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
assertThat("4 5 W",is(robot.getPosition().toString())); | |
} | |
@Test (expected = OutOfPlateauBoundaryException.class) | |
public void checkPositonBottomLeftCornerFacingEast() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("0 0 S"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
} | |
@Test (expected = OutOfPlateauBoundaryException.class) | |
public void checkPositonTopLeftCornerFacingEast() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("0 7 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
} | |
@Test (expected = OutOfPlateauBoundaryException.class) | |
public void checkPositonTopRightCornerFacingEast() throws OutOfPlateauBoundaryException , InvalidInputException { | |
robot = new RobotImplementation("7 7 N"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
} | |
@Test (expected = OutOfPlateauBoundaryException.class) | |
public void checkPositonBottomRightCornerFacingEast() throws OutOfPlateauBoundaryException, InvalidInputException { | |
robot = new RobotImplementation("7 0 S"); | |
PlateauImplementation.INSTANCE.loadPlateau("7 7"); | |
robot.move("M"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise; | |
import com.newsinternational.exercise.exception.InvalidInputException; | |
import com.newsinternational.exercise.exception.OutOfPlateauBoundaryException; | |
import com.newsinternational.exercise.implementation.EnvironmentSetUp; | |
import java.util.Scanner; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Class acts like a client to test code in command line | |
*/ | |
public class RobotGameTest { | |
public static void main(String [] args) throws InvalidInputException { | |
String reTest; | |
Scanner input = new Scanner (System.in); | |
Robot robot; | |
System.out.println("Please enter Plateau co-ordinates Eg - '5 5':"); | |
try { | |
EnvironmentSetUp.loadPlateau(input.nextLine()); | |
} catch (InvalidInputException e) { | |
System.out.println(e.getMessage()); | |
} | |
EnvironmentSetUp environmentSetUp = new EnvironmentSetUp(); | |
do { | |
try { | |
System.out.println("Now enter a Robot position Eg - '5 5 N':"); | |
robot = environmentSetUp.createAndDeployRobot(input.nextLine()); | |
System.out.println("Enter movement instructions Eg - 'LMLMRMM':"); | |
robot.move(input.nextLine()); | |
System.out.println("Current position of Robot is "); | |
System.out.println(environmentSetUp.getRobot().getPosition().toString()); | |
} catch (InvalidInputException e) { | |
System.out.println(e.getMessage()); | |
} catch (OutOfPlateauBoundaryException e) { | |
System.out.println(e.getMessage()); | |
} | |
System.out.println("Add another Robot? (y/n)"); | |
reTest = input.nextLine(); | |
} while(reTest.equalsIgnoreCase("Y") || reTest.equalsIgnoreCase("YES")); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newsinternational.exercise.utility; | |
import org.junit.Test; | |
import static org.hamcrest.core.Is.is; | |
import static org.junit.Assert.assertThat; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: pradeepcheers | |
* Tests for Direction Enum | |
*/ | |
public class DirectionTest { | |
@Test | |
public void testDirectionInitialisationNorthToRight() | |
{ | |
assertThat(Direction.N.getToTheRight(), is(Direction.E)); | |
} | |
@Test | |
public void testDirectionInitialisationEastToRight() | |
{ | |
assertThat(Direction.E.getToTheRight(), is(Direction.S)); | |
} | |
@Test | |
public void testDirectionInitialisationSouthToRight() | |
{ | |
assertThat(Direction.S.getToTheRight(), is(Direction.W)); | |
} | |
@Test | |
public void testDirectionInitialisationWestToRight() | |
{ | |
assertThat(Direction.W.getToTheRight(), is(Direction.N)); | |
} | |
@Test | |
public void testDirectionInitialisationNorthToLeft() | |
{ | |
assertThat(Direction.N.getToTheLeft(), is(Direction.W)); | |
} | |
@Test | |
public void testDirectionInitialisationEastToLeft() | |
{ | |
assertThat(Direction.E.getToTheLeft(), is(Direction.N)); | |
} | |
@Test | |
public void testDirectionInitialisationSouthToLeft() | |
{ | |
assertThat(Direction.S.getToTheLeft(), is(Direction.E)); | |
} | |
@Test | |
public void testDirectionInitialisationWestToLeft() | |
{ | |
assertThat(Direction.W.getToTheLeft(), is(Direction.S)); | |
} | |
@Test | |
public void testGetNextDirectionOne() | |
{ | |
assertThat(Direction.getNextDirection(Direction.N,"L"), is(Direction.W)); | |
} | |
@Test | |
public void testGetNextDirectionTwo() | |
{ | |
assertThat(Direction.getNextDirection(Direction.E,"L"), is(Direction.N)); | |
} | |
@Test | |
public void testGetNextDirectionThree() | |
{ | |
assertThat(Direction.getNextDirection(Direction.W,"L"), is(Direction.S)); | |
} | |
@Test | |
public void testGetNextDirectionFour() | |
{ | |
assertThat(Direction.getNextDirection(Direction.S,"L"), is(Direction.E)); | |
} | |
@Test | |
public void checkDirectionRight(){ | |
assertThat(Direction.getNextDirection(Direction.S,"R"), is(Direction.W)); | |
} | |
@Test | |
public void checkDirectionRightOne(){ | |
assertThat(Direction.getNextDirection(Direction.W,"R"), is(Direction.N)); | |
} | |
@Test | |
public void checkDirectionRightTwo(){ | |
assertThat(Direction.getNextDirection(Direction.S,"R"), is(Direction.W)); | |
} | |
@Test | |
public void checkDirectionRightThree(){ | |
assertThat(Direction.getNextDirection(Direction.W,"R"), is(Direction.N)); | |
} | |
@Test | |
public void checkDirectionRightFour(){ | |
assertThat(Direction.getNextDirection(Direction.N,"R"), is(Direction.E)); | |
} | |
@Test | |
public void checkDirectionRightFive(){ | |
assertThat(Direction.getNextDirection(Direction.E,"R"), is(Direction.S)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
���� 2 w | |