Skip to content

Instantly share code, notes, and snippets.

@bitmaybewise
Created September 29, 2012 00:14
Show Gist options
  • Save bitmaybewise/3802703 to your computer and use it in GitHub Desktop.
Save bitmaybewise/3802703 to your computer and use it in GitHub Desktop.
Jokenpo: From DojoPuzzles
/**
* @Author: Hercules Lemke Merscher
* Jokenpo
* http://dojopuzzles.com/problemas/exibe/jokenpo/
*/
enum Play {
ROCK, SCISSORS, PAPER
}
enum Result {
PLAYER1, PLAYER2, DRAW
}
public class Jokenpo {
public Result jokenpo(Play playA, Play playB){
if(playA == playB)
return Result.DRAW;
switch(playA){
case ROCK:
if(playB == Play.PAPER) return Result.PLAYER2;
break;
case SCISSORS:
if(playB == Play.ROCK) return Result.PLAYER2;
break;
case PAPER:
if(playB == Play.SCISSORS) return Result.PLAYER2;
break;
}
return Result.PLAYER1;
}
}
/**
* @Author: Hercules Lemke Merscher
* JokenpoTest
* http://dojopuzzles.com/problemas/exibe/jokenpo/
*/
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class JokenpoTest {
Jokenpo jokenpo;
Play play;
Result result;
@Before
public void setup(){
jokenpo= new Jokenpo();
}
@Test
public void jokenpoWinRock(){
assertEquals(Result.PLAYER1, jokenpo.jokenpo(Play.ROCK, Play.SCISSORS));
}
@Test
public void jokenpoWinScissors(){
assertEquals(Result.PLAYER1, jokenpo.jokenpo(Play.SCISSORS, Play.PAPER));
}
@Test
public void jokenpoWinPaper(){
assertEquals(Result.PLAYER1, jokenpo.jokenpo(Play.PAPER, Play.ROCK));
}
@Test
public void jokenpoLostPaper(){
assertEquals(Result.PLAYER2, jokenpo.jokenpo(Play.PAPER, Play.SCISSORS));
}
@Test
public void jokenpoLostScissors(){
assertEquals(Result.PLAYER2, jokenpo.jokenpo(Play.SCISSORS, Play.ROCK));
}
@Test
public void jokenpoLostRock(){
assertEquals(Result.PLAYER2, jokenpo.jokenpo(Play.ROCK, Play.PAPER));
}
@Test
public void jokenpoDrawPaper(){
assertEquals(Result.DRAW, jokenpo.jokenpo(Play.PAPER, Play.PAPER));
}
@Test
public void jokenpoDrawRock(){
assertEquals(Result.DRAW, jokenpo.jokenpo(Play.ROCK, Play.ROCK));
}
@Test
public void jokenpoDrawScissors(){
assertEquals(Result.DRAW, jokenpo.jokenpo(Play.SCISSORS, Play.SCISSORS));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment