Created
December 31, 2010 00:34
-
-
Save ericanderson/760546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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