Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import junit.framework.TestCase;
public class StrategyTest extends TestCase {
public void testSequentialStrategy() {
GuessTheNumber guesser = new GuessTheNumber(5, 100);
SequentialStrategy strategy = new SequentialStrategy(guesser);
for (int i=0; i<3; i++) {
try {
guesser.getValue();
fail("An exception should have been thrown");
}
catch (IllegalStateException ex) { /**/ }
int value = strategy.solve();
assertEquals(guesser.getValue(), value);
try {
guesser.guess(guesser.getMax() + 1);
fail("Shouldn't reach this point");
}
catch (IllegalStateException ex) {/**/}
guesser.resetCount();
}
}
public void testBadGuessGame() {
GuessTheNumber guesser = new GuessTheNumber(1, 10, 3000);
SequentialStrategy strategy = new SequentialStrategy(guesser);
try {
strategy.solve();
fail("Should not reach this point");
}
catch (IllegalStateException ex) { /**/ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment