Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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) { /**/ }
- }
- }
Add Comment
Please, Sign In to add comment