Skip to content

Instantly share code, notes, and snippets.

@making
Last active August 29, 2015 14:12
Show Gist options
  • Save making/6bf2bd85f6861a1ca170 to your computer and use it in GitHub Desktop.
Save making/6bf2bd85f6861a1ca170 to your computer and use it in GitHub Desktop.
じゃんけんロジック
public class Janken {
public static class Hand {
public static final int GU = 0;
public static final int CHOKI = 1;
public static final int PA = 2;
}
public static class Result {
public static final int DRAW = 0;
public static final int WIN = 1;
public static final int LOSE = 2;
}
public static int judge(int one, int another) {
return (one - another + 3) % 3;
}
}
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class JankenTest {
// tekitou
@Test
public void testCHOKI_CHOKI() throws Exception {
assertThat(Janken.judge(Janken.Hand.CHOKI, Janken.Hand.CHOKI), is(Janken.Result.DRAW));
}
@Test
public void testCHOKI_GU() throws Exception {
assertThat(Janken.judge(Janken.Hand.CHOKI, Janken.Hand.GU), is(Janken.Result.LOSE));
}
@Test
public void testCHOKI_PA() throws Exception {
assertThat(Janken.judge(Janken.Hand.CHOKI, Janken.Hand.PA), is(Janken.Result.WIN));
}
@Test
public void testGU_CHOKI() throws Exception {
assertThat(Janken.judge(Janken.Hand.GU, Janken.Hand.CHOKI), is(Janken.Result.WIN));
}
@Test
public void testGU_GU() throws Exception {
assertThat(Janken.judge(Janken.Hand.GU, Janken.Hand.GU), is(Janken.Result.DRAW));
}
@Test
public void testGU_PA() throws Exception {
assertThat(Janken.judge(Janken.Hand.GU, Janken.Hand.PA), is(Janken.Result.LOSE));
}
@Test
public void testPA_CHOKI() throws Exception {
assertThat(Janken.judge(Janken.Hand.PA, Janken.Hand.CHOKI), is(Janken.Result.LOSE));
}
@Test
public void testPA_GU() throws Exception {
assertThat(Janken.judge(Janken.Hand.PA, Janken.Hand.GU), is(Janken.Result.WIN));
}
@Test
public void testPA_PA() throws Exception {
assertThat(Janken.judge(Janken.Hand.PA, Janken.Hand.PA), is(Janken.Result.DRAW));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment