Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions classes/test/coding/111111111.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

| | | | | | | | |
| | | | | | | | |
3 changes: 3 additions & 0 deletions classes/test/coding/123456789.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|
3 changes: 3 additions & 0 deletions classes/test/coding/222222222.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ _ _ _ _ _ _ _ _
_| _| _| _| _| _| _| _| _|
|_ |_ |_ |_ |_ |_ |_ |_ |_
3 changes: 3 additions & 0 deletions classes/test/coding/caso1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ _ _ _ _ _ _ _
|_||_ ||_ | ||_|| || || |
| _| | _||_||_||_||_||_|
3 changes: 3 additions & 0 deletions classes/test/coding/caso2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ _ _ _ _ _ _ _
|_||_ | _ | ||_|| || || |
| _| ||_||_||_| _||_||_|
3 changes: 3 additions & 0 deletions classes/test/coding/caso3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_ _ _ _ _ _
|_ |_ |_| _| | ||_||_||_
|_||_| | _| | | | _| _|
1 change: 1 addition & 0 deletions classes/test/coding/prueba.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234567890
74 changes: 74 additions & 0 deletions src/main/java/org/fundacionjala/coding/abel/StreetFighter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.fundacionjala.coding.abel;

import java.util.ArrayList;
import java.util.List;

/**
* You'll have to simulate the video game's character selection screen behaviour, more specifically the selection grid.
* Such screen looks like this:
* Selection Grid Layout in text:
* | Ryu | E.Honda | Blanka | Guile | Balrog | Vega |
* | Ken | Chun Li | Zangief | Dhalsim | Sagat | M.Bison |
* Input
* the list of game characters in a 2x6 grid;
* the initial position of the selection cursor (top-left is (0,0));
* a list of moves of the selection cursor (which are up, down, left, right);
* Output
* the list of characters who have been hovered by the selection cursor after all the moves
* (ordered and with repetition, all the ones after a move, wether successful or not, see tests);
*/
public final class StreetFighter {

/**
* Private Constructor.
*/
private StreetFighter() {

}

/**
* Returns the Fighter after pushing buttons.
*
* @param fighters String[][].
* @param position int[].
* @param moves String[].
* @return String[].
*/
public static String[] streetFighterSelection(String[][] fighters, int[] position, String[] moves) {
String[] solution = new String[]{};
List<String> listSolution = new ArrayList<String>();
int[] currentPosition = position;
for (String move : moves) {
if (move.equals("up")) {
if (position[0] != 0) {
currentPosition[0] = position[0] - 1;
}
listSolution.add(fighters[currentPosition[0]][currentPosition[1]]);
}
if (move.equals("down")) {
if (position[0] != 1) {
currentPosition[0] = position[0] + 1;
}
listSolution.add(fighters[currentPosition[0]][currentPosition[1]]);
}
if (move.equals("left")) {
if (position[1] == 0) {
currentPosition[1] = fighters[0].length - 1;
} else {
currentPosition[1] = position[1] - 1;
}
listSolution.add(fighters[currentPosition[0]][currentPosition[1]]);
}
if (move.equals("right")) {
if (position[1] == fighters[0].length - 1) {
currentPosition[1] = 0;
} else {
currentPosition[1] = position[1] + 1;
}
listSolution.add(fighters[currentPosition[0]][currentPosition[1]]);
}
position = currentPosition;
}
return listSolution.toArray(solution);
}
}
108 changes: 108 additions & 0 deletions src/test/java/org/fundacionjala/coding/abel/StreetFighterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.fundacionjala.coding.abel;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;

/**
* Class to run Test for Street Fighter.
*/
public class StreetFighterTest {

private static final String[][] FIGHTERS = new String[][]{
new String[]{"Ryu", "E.Honda", "Blanka", "Guile", "Balrog", "Vega"},
new String[]{"Ken", "Chun Li", "Zangief", "Dhalsim", "Sagat", "M.Bison"},
};

/**
* Test for Private Constructors.
*
* @throws NoSuchMethodException Thrown when a particular method cannot be found.
* @throws IllegalAccessException Thrown when an application tries to reflectively create an instance.
* @throws InvocationTargetException thrown by an invoked method or constructor.
* @throws InstantiationException Thrown when an application tries to create an instance of a class
* using the {@code newInstance} method in class.
*/
@Test
public void privateConstructorTest() throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException, InstantiationException {
Constructor<StreetFighter> constructor = StreetFighter.class.getDeclaredConstructor();
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
constructor.setAccessible(true);
constructor.newInstance();
}

/**
* First Test.
*/
@Test
public void shouldWorkWithNoMoves() {
String[] solution = new String[]{};
assertArrayEquals(solution, StreetFighter.streetFighterSelection(FIGHTERS, new int[]{0, 0}, new String[]{}));
}

/**
* First Test.
*/
@Test
public void shouldWorkWithFewMoves() {
String[] moves = new String[]{"up", "left", "right", "left", "left"};
String[] solution = new String[]{"Ryu", "Vega", "Ryu", "Vega", "Balrog"};
assertArrayEquals(solution, StreetFighter.streetFighterSelection(FIGHTERS, new int[]{0, 0}, moves));
}

/**
* First Test.
*/
@Test
public void shouldWorkWhenAlwaysMovingLeft() {
String[] moves = new String[]{"left", "left", "left", "left", "left", "left", "left", "left"};
String[] solution = new String[]{"Vega", "Balrog", "Guile", "Blanka", "E.Honda", "Ryu", "Vega", "Balrog"};
assertArrayEquals(solution, StreetFighter.streetFighterSelection(FIGHTERS, new int[]{0, 0}, moves));
}

/**
* First Test.
*/
@Test
public void shouldWorkWhenAlwaysMovingRight() {
String[] moves = new String[]{"right", "right", "right", "right", "right", "right", "right", "right"};
String[] solution = new String[]{"E.Honda", "Blanka", "Guile", "Balrog", "Vega", "Ryu", "E.Honda", "Blanka"};
assertArrayEquals(solution, StreetFighter.streetFighterSelection(FIGHTERS, new int[]{0, 0}, moves));
}

/**
* First Test.
*/
@Test
public void shouldUseAll4DirectionsClockwiseTwice() {
String[] moves = new String[]{"up", "left", "down", "right", "up", "left", "down", "right"};
String[] solution = new String[]{"Ryu", "Vega", "M.Bison", "Ken", "Ryu", "Vega", "M.Bison", "Ken"};
assertArrayEquals(solution, StreetFighter.streetFighterSelection(FIGHTERS, new int[]{0, 0}, moves));
}

/**
* First Test.
*/
@Test
public void shouldWorkWhenAlwaysMovingDown() {
String[] moves = new String[]{"down", "down", "down", "down"};
String[] solution = new String[]{"Ken", "Ken", "Ken", "Ken"};
assertArrayEquals(solution, StreetFighter.streetFighterSelection(FIGHTERS, new int[]{0, 0}, moves));
}

/**
* First Test.
*/
@Test
public void shouldWorkWhenAlwaysMovingUp() {
String[] moves = new String[]{"up", "up", "up", "up"};
String[] solution = new String[]{"Ryu", "Ryu", "Ryu", "Ryu"};
assertArrayEquals(solution, StreetFighter.streetFighterSelection(FIGHTERS, new int[]{0, 0}, moves));
}
}