Skip to content

Commit

Permalink
Changed Attempt to be an enum. This reduced the number of tests to wr…
Browse files Browse the repository at this point in the history
…ite. This also will push input-to-Attempt creation logic into the factory.
  • Loading branch information
hborders committed Dec 23, 2009
1 parent 2a1cc16 commit 3086795
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
@@ -1,11 +1,7 @@
package com.github.hborders.rockpaperscissors;

public class Attempt {
private final String attempt;

public Attempt(String attempt) {
this.attempt = attempt;
}
public enum Attempt {
ROCK, PAPER, SCISSORS, ;

public boolean beats(Attempt otherAttempt) {
return false;
Expand Down
Expand Up @@ -8,57 +8,46 @@ public class AttemptTest {

@Test
public void rock_does_not_beat_rock() {
assertFalse(new Attempt("R").beats(new Attempt("R")));
assertFalse(Attempt.ROCK.beats(Attempt.ROCK));
}

@Test
public void rock_does_not_beat_paper() {
assertFalse(new Attempt("R").beats(new Attempt("P")));
assertFalse(Attempt.ROCK.beats(Attempt.PAPER));
}

@Test
public void rock_beats_scissors() {
assertTrue(new Attempt("R").beats(new Attempt("S")));
assertTrue(Attempt.ROCK.beats(Attempt.SCISSORS));
}

@Test
public void scissors_does_not_beat_rock() {
assertFalse(new Attempt("S").beats(new Attempt("R")));
}

@Test
public void scissors_beats_paper() {
assertTrue(new Attempt("S").beats(new Attempt("P")));
public void paper_beats_rock() {
assertTrue(Attempt.PAPER.beats(Attempt.ROCK));
}

@Test
public void scissors_does_not_beat_scissors() {
assertFalse(new Attempt("S").beats(new Attempt("S")));
public void paper_does_not_beat_scissors() {
assertTrue(Attempt.PAPER.beats(Attempt.SCISSORS));
}

@Test
public void paper_beats_rock() {
assertTrue(new Attempt("P").beats(new Attempt("R")));
public void paper_does_not_beat_paper() {
assertTrue(Attempt.PAPER.beats(Attempt.PAPER));
}

@Test
public void paper_does_not_beat_scissors() {
assertTrue(new Attempt("P").beats(new Attempt("S")));
public void scissors_does_not_beat_rock() {
assertFalse(Attempt.SCISSORS.beats(Attempt.ROCK));
}

@Test
public void paper_does_not_beat_paper() {
assertTrue(new Attempt("P").beats(new Attempt("P")));
public void scissors_beats_paper() {
assertTrue(Attempt.SCISSORS.beats(Attempt.PAPER));
}

@Test
public void equality_is_case_insensitive() {
assertEquals(new Attempt("R"), new Attempt("r"));
assertEquals(new Attempt("P"), new Attempt("p"));
assertEquals(new Attempt("S"), new Attempt("s"));

assertEquals(new Attempt("R").hashCode(), new Attempt("r").hashCode());
assertEquals(new Attempt("P").hashCode(), new Attempt("p").hashCode());
assertEquals(new Attempt("S").hashCode(), new Attempt("s").hashCode());
public void scissors_does_not_beat_scissors() {
assertFalse(Attempt.SCISSORS.beats(Attempt.SCISSORS));
}
}

0 comments on commit 3086795

Please sign in to comment.