diff --git a/.circleci/config.yml b/.circleci/config.yml index 6c76860..5d430f1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,6 +41,15 @@ jobs: cd ./python && . env/bin/activate pytest safe_spaces_test.py + test-java: + docker: + - image: circleci/openjdk:8-jdk-node-browsers + steps: + - checkout + - run: + name: Run Tests + command: cd ./java && ./gradlew test + workflows: version: 2 build_and_test: @@ -48,4 +57,5 @@ workflows: - test-ruby - test-javascript - test-python + - test-java diff --git a/java/.gitignore b/java/.gitignore new file mode 100644 index 0000000..1164ed8 --- /dev/null +++ b/java/.gitignore @@ -0,0 +1,2 @@ +.idea/ +.gradle/ \ No newline at end of file diff --git a/java/README.MD b/java/README.MD new file mode 100644 index 0000000..c5f4627 --- /dev/null +++ b/java/README.MD @@ -0,0 +1,24 @@ +# Find safe places in Java + +## Requirements + +For this exercise we will use Java 8. +You need to have the JDK8 installed and added to your path. + + +## Running the tests + +### Activating the tests +To activate the tests just delete the @Ignore annotation on each test method + +The tests are grouped into 3 levels which each represent a method to be implemented +(see the comments before and after each group of tests) so you can implement and test each method +on its own + +### Windows +To run the tests in a Windows environment navigate into the project directory +and execute ```./gradlew.bat test``` + +### Linux/MacOS +To run test in a Linux or MacOS environment navigate into the project directory +and execute ```./gradlew test``` \ No newline at end of file diff --git a/java/build.gradle b/java/build.gradle new file mode 100644 index 0000000..db4dd62 --- /dev/null +++ b/java/build.gradle @@ -0,0 +1,16 @@ +plugins { + id 'java' +} + +group 'com.thoughtworks' +version '1.0-SNAPSHOT' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/java/gradle/wrapper/gradle-wrapper.jar b/java/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..1948b90 Binary files /dev/null and b/java/gradle/wrapper/gradle-wrapper.jar differ diff --git a/java/gradle/wrapper/gradle-wrapper.properties b/java/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d2c45a4 --- /dev/null +++ b/java/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/java/gradlew b/java/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/java/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/java/gradlew.bat b/java/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/java/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/java/settings.gradle b/java/settings.gradle new file mode 100644 index 0000000..a2681d3 --- /dev/null +++ b/java/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'coding-challenge' + diff --git a/java/src/main/java/SafeSpaces.java b/java/src/main/java/SafeSpaces.java new file mode 100644 index 0000000..755adc9 --- /dev/null +++ b/java/src/main/java/SafeSpaces.java @@ -0,0 +1,321 @@ +import java.util.Arrays; + +/** + * A class to help us find safe locations for Alex + */ +public class SafeSpaces { + + /** + * This method should convert an one dimensional Array with alphanumeric coordinates (e.g. ["A1"]) to a + * two-dimensional, zero-based representation of the coordinates + * + * For example the input of ["A6"] should lead to [[0,5]] + * + * @param alphanumericCoordinates An alphanumeric representation of coordinates e.g. ["A1","D1"] + * @return two-dimensional, zero-based representation of the coordinates (e.g. [[0,0],[3,0]] + */ + + + /** + * This method should take a two-dimensional, zero-based representation of coordinates for the agents locations and + * find the safest places for Alex in a two-dimensional, zero-based representation of coordinates + * + * @param //agentCoordinates a two-dimensional, zero-based representation of coordinates for the agents locations + * @return a two-dimensional, zero-based representation of coordinates for the safest places for alex + * @see SafeSpaces#convertCoordinates(String[]) for the two-dimensional, zero-based representation of coordinates + */ + + public int[][] convertCoordinates(String[] alphanumericCoordinates) { + + int x = 0; + int y = 0; + int xValue = 0; + int yValue = 0; + int agentCounter = 0; + + for (String item : alphanumericCoordinates) { + + switch (item.charAt(0)) { + case 'A': + xValue = 0; + break; + case 'B': + xValue = 1; + break; + case 'C': + xValue = 2; + break; + case 'D': + xValue = 3; + break; + case 'E': + xValue = 4; + break; + case 'F': + xValue = 5; + break; + case 'G': + xValue = 6; + break; + case 'H': + xValue = 7; + break; + case 'I': + xValue = 8; + break; + case 'J': + xValue = 9; + break; + default: + continue; + } + + if (item.length() == 2) { + agentCounter++; + } else if (item.length() == 3) { + if (Character.getNumericValue(item.charAt(1) + item.charAt(2)) < 11) { + agentCounter++; + } + } + } + + + if (agentCounter == 0) { + + int[][] noAgents = new int[0][0]; + return noAgents; + } + + int[][] output = new int[agentCounter][2]; + + for (String item : alphanumericCoordinates) { + y = 0; + switch (item.charAt(0)) { + case 'A': + xValue = 0; + break; + case 'B': + xValue = 1; + break; + case 'C': + xValue = 2; + break; + case 'D': + xValue = 3; + break; + case 'E': + xValue = 4; + break; + case 'F': + xValue = 5; + break; + case 'G': + xValue = 6; + break; + case 'H': + xValue = 7; + break; + case 'I': + xValue = 8; + break; + case 'J': + xValue = 9; + break; + default: + continue; + } + + if (item.length() == 2) { + yValue = Character.getNumericValue(item.charAt(1)) - 1; + } else if (item.length() == 3) { + if (Character.getNumericValue(item.charAt(1) + item.charAt(2)) < 11) { + yValue = Character.getNumericValue(item.charAt(1) + item.charAt(2)) - 1; + } else { + continue; + } + } else { + continue; + } + + output[x][y] = xValue; + y++; + output[x][y] = yValue; + + x++; + + } + return output; + } + + public int[][] findSafeSpaces(int[][] agentCoordinates) { + int x = 0; + int y = 0; + boolean agent; + int highestValue = 0; + int[][] result = new int[10][10]; + for (x = 0; x < 10; x++) { + for (y = 0; y < 10; y++) { + agent = false; + for (int a = 0; a < agentCoordinates.length; a++) { + if ((agentCoordinates[a][0] == x) && (agentCoordinates[a][1] == y)) { + agent = true; + } + } + if (!agent) { + for (int a = 0; a < agentCoordinates.length; a++) { + if (result[x][y] == 0 || Math.abs((agentCoordinates[a][0] - x)) + Math.abs((agentCoordinates[a][1] - y)) < result[x][y]) { + result[x][y] = Math.abs((agentCoordinates[a][0] - x)) + Math.abs((agentCoordinates[a][1] - y)); + } + } + } + } + } + + + for (x = 0; x < 10; x++) { + for (y = 0; y < 10; y++) { + + if (result[x][y] > highestValue) { + highestValue = result[x][y]; + } + } + } + + int count = 0; + if (highestValue != 0 || agentCoordinates.length == 0) { + for (x = 0; x < 10; x++) { + for (y = 0; y < 10; y++) { + + if (result[x][y] == highestValue) { + count++; + } + } + } + + int[][] places = new int[count][2]; + int a = 0; + for (x = 0; x < 10; x++) { + for (y = 0; y < 10; y++) { + + if (result[x][y] == highestValue) { + places[a][0] = x; + places[a][1] = y; + a++; + } + } + } + return places; + } else { + int[][] emptyPlaces = new int[0][0]; + return emptyPlaces; + } + + + } + + /** + * This method should take an array of alphanumeric agent locations and offer advice to Alex for where she + * should hide out in the city, with special advice for edge cases + * + * @param alphanumericCoordinates (e.g. ["A5", "B1"]) + * @return SearchResult with the proper information for Alex + */ + + + public SearchResult adviceForAlex(String[] alphanumericCoordinates) { + + String noSafe = "There are no safelocations for Alex! :-("; + String allSafe = "The whole city is safe for Alex! :-)"; + + + int[][] resultConvert = convertCoordinates(alphanumericCoordinates); + int[][] safeSpaces = findSafeSpaces(resultConvert); + + String xValue = ""; + String yValue = ""; + + if (safeSpaces.length == 0) { + SearchResult searchResult = new SearchResult(noSafe); + return searchResult; + } + if (safeSpaces.length == 100) { + SearchResult searchResult2 = new SearchResult(allSafe); + return searchResult2; + } + + String[] safeLocations = new String[safeSpaces.length]; + + for (int i = 0; i < safeSpaces.length; i++) { + + switch (safeSpaces[i][0]) { + case 0: + xValue = "A"; + break; + case 1: + xValue = "B"; + break; + case 2: + xValue = "C"; + break; + case 3: + xValue = "D"; + break; + case 4: + xValue = "E"; + break; + case 5: + xValue = "F"; + break; + case 6: + xValue = "G"; + break; + case 7: + xValue = "H"; + break; + case 8: + xValue = "I"; + break; + case 9: + xValue = "J"; + break; + default: + continue; + } + + int yPlace = safeSpaces[i][1] + 1; + yValue = Integer.toString(yPlace); + + safeLocations[i] = xValue + yValue; + } + + SearchResult searchResult3 = new SearchResult(safeLocations); + + + return searchResult3; + } + + /** + * Class that contains advice for Alex + * In general the safeLocations array should be filled + * However there edgecases to be taken into account (e.g. no safe locations or only safe locations) which would + * only require a message + */ + public class SearchResult { + private String message; + private String[] safeLocations; + + public SearchResult(String message) { + this.message = message; + } + + public SearchResult(String[] safeLocations) { + Arrays.sort(safeLocations); + this.safeLocations = safeLocations; + } + + @Override + public String toString() { + return message != null ? message : Arrays.toString(safeLocations); + } + } +} diff --git a/java/src/test/java/SafeSpacesTest.java b/java/src/test/java/SafeSpacesTest.java new file mode 100644 index 0000000..3a23fbf --- /dev/null +++ b/java/src/test/java/SafeSpacesTest.java @@ -0,0 +1,208 @@ +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.*; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +public class SafeSpacesTest { + final Comparator arrayComparator = (o1, o2) -> o1[0] == o2[0] ? o1[1] - o2[1] : o1[0] - o2[0]; + + SafeSpaces objectUnderTest; + + @Before + public void setup(){ + objectUnderTest = new SafeSpaces(); + } + + //Level -1 convert coordinates + /** + * Test that the method handles an empty list of coordinates correctly + */ + @Test + @Ignore + public void testEmptyCoordinates(){ + String[] agents = {}; + int[][] coordinates = objectUnderTest.convertCoordinates(agents); + assertArrayEquals("Empty alphanumeric coordinates should lead to empty numeric coordinates", + new int[][]{}, + coordinates); + } + + /** + * Test for correct conversion of a single coordinate + */ + @Test + @Ignore + public void testSingleCoordinate(){ + String[] agents = {"F3"}; + int[][] coordinates = objectUnderTest.convertCoordinates(agents); + int[][] expected = {{5, 2}}; + Arrays.sort(coordinates, arrayComparator); + Arrays.sort(expected, arrayComparator); + assertArrayEquals(expected,coordinates); + } + + /** + * Test for correct conversion from a list of coordinates to multi-dimensional, zero-based array + */ + @Test + @Ignore + public void testMultipleCoordinates(){ + String[] agents = {"B6","C2","J7"}; + int[][] coordinates = objectUnderTest.convertCoordinates(agents); + int[][] expected = {{1, 5}, {2, 1}, {9, 6}}; + Arrays.sort(coordinates, arrayComparator); + Arrays.sort(expected, arrayComparator); + assertArrayEquals(expected,coordinates); + } + + /** + * Test that alphanumeric coordinates with a double digit number are handled correctly + */ + @Test + @Ignore + public void testDoubleDigits(){ + String[] agents = {"J10"}; + int[][] coordinates = objectUnderTest.convertCoordinates(agents); + int[][] expected = {{9, 9}}; + Arrays.sort(coordinates, arrayComparator); + Arrays.sort(expected, arrayComparator); + assertArrayEquals(expected,coordinates); + } + + //End Level-1 convert coordinates + + //Level-2 Find safe spaces in the city based on agent locations + + /** + * Test for six agents at specified locations + */ + @Test + @Ignore + public void testSafeSpacesRound1(){ + int[][] agents = {{1,1},{3,5},{4,8},{7,3},{7,8},{9,1}}; + int[][] safeSpaces = objectUnderTest.findSafeSpaces(agents); + int[][] expected = {{0, 9}, {0, 7}, {5, 0}}; + Arrays.sort(safeSpaces, arrayComparator); + Arrays.sort(expected, arrayComparator); + assertArrayEquals(expected,safeSpaces); + } + + /** + * Test for six agents at different specified locations + */ + @Test + @Ignore + public void testSafeSpacesRound2(){ + int[][] agents = {{0,0},{0,9},{1,5},{5,1},{9,0},{9,9}}; + int[][] safeSpaces = objectUnderTest.findSafeSpaces(agents); + int[][] expected = {{5, 7}, {6, 6}, {7, 5}}; + Arrays.sort(safeSpaces, arrayComparator); + Arrays.sort(expected, arrayComparator); + assertArrayEquals(expected,safeSpaces); + } + + /** + * Test for on agent at a specified location + */ + @Test + @Ignore + public void testSafeSpacesRound3(){ + int[][] agents = {{0,0}}; + int[][] safeSpaces = objectUnderTest.findSafeSpaces(agents); + int[][] expected = {{9, 9}}; + Arrays.sort(safeSpaces, arrayComparator); + Arrays.sort(expected, arrayComparator); + assertArrayEquals(expected,safeSpaces); + } + + //End Level-2 Find safe spaces in the city based on agent locations + + //Level-3 Handle edge cases and offering recommendations + + /** + * Test for agents everywhere in the city + */ + @Test + @Ignore + public void testAgentsEverywhere(){ + String[] agents = { + "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", + "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10", + "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", + "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10", + "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "E10", + "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", + "G1", "G2", "G3", "G4", "G5", "G6", "G7", "G8", "G9", "G10", + "H1", "H2", "H3", "H4", "H5", "H6", "H7", "H8", "H9", "H10", + "I1", "I2", "I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10", + "J1", "J2", "J3", "J4", "J5", "J6", "J7", "J8", "J9", "J10"}; + SafeSpaces.SearchResult searchResult = objectUnderTest.adviceForAlex(agents); + assertEquals("There are no safe locations for Alex! :-(", + searchResult.toString()); + } + + /** + * Test for six agents at specified locations + */ + @Test + @Ignore + public void testAdviceRound1(){ + String[] agents = {"B2", "D6", "E9", "H4", "H9", "J2"}; + SafeSpaces.SearchResult searchResult = objectUnderTest.adviceForAlex(agents); + assertEquals(Arrays.toString(new String[]{"A10", "A8", "F1"}), + searchResult.toString()); + } + + /** + * Test for seven agents at specified locations + */ + @Test + @Ignore + public void testAdviceRound2(){ + String[] agents = {"B4", "C4", "C8", "E2", "F10", "H1", "J6"}; + SafeSpaces.SearchResult searchResult = objectUnderTest.adviceForAlex(agents); + assertEquals(Arrays.toString(new String[]{"A1", "A10", "E6", "F5", "F6", "G4", "G5","G7", "H8", "I9", "J10"}), + searchResult.toString()); + } + + /** + * Test for six agents at different specified locations + */ + @Test + @Ignore + public void testAdviceRound3(){ + String[] agents = {"A1", "A10", "B6", "F2", "J1", "J10"}; + SafeSpaces.SearchResult searchResult = objectUnderTest.adviceForAlex(agents); + assertEquals(Arrays.toString(new String[]{"F8", "G7", "H6"}), + searchResult.toString()); + } + + /** + * Test for only one agent + */ + @Test + @Ignore + public void testAdviceRound4(){ + String[] agents = {"A1"}; + SafeSpaces.SearchResult searchResult = objectUnderTest.adviceForAlex(agents); + assertEquals(Arrays.toString(new String[]{"J10"}), + searchResult.toString()); + } + + /** + * Test for agent outside the map (no agent in the city) + */ + @Test + @Ignore + public void testAgentOutsideMap(){ + String[] agents = {"A12"}; + SafeSpaces.SearchResult searchResult = objectUnderTest.adviceForAlex(agents); + assertEquals("The whole city is safe for Alex! :-)", + searchResult.toString()); + } + +}