Guest User

Untitled

a guest
Jul 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import junit.framework.TestCase;
  2.  
  3. public class StrategyTest extends TestCase {
  4.  
  5. public void testSequentialStrategy() {
  6. GuessTheNumber guesser = new GuessTheNumber(5, 100);
  7. SequentialStrategy strategy = new SequentialStrategy(guesser);
  8.  
  9. for (int i=0; i<3; i++) {
  10. try {
  11. guesser.getValue();
  12. fail("An exception should have been thrown");
  13. }
  14. catch (IllegalStateException ex) { /**/ }
  15.  
  16. int value = strategy.solve();
  17. assertEquals(guesser.getValue(), value);
  18.  
  19. try {
  20. guesser.guess(guesser.getMax() + 1);
  21. fail("Shouldn't reach this point");
  22. }
  23. catch (IllegalStateException ex) {/**/}
  24.  
  25. guesser.resetCount();
  26. }
  27. }
  28.  
  29. public void testBadGuessGame() {
  30. GuessTheNumber guesser = new GuessTheNumber(1, 10, 3000);
  31. SequentialStrategy strategy = new SequentialStrategy(guesser);
  32.  
  33. try {
  34. strategy.solve();
  35. fail("Should not reach this point");
  36. }
  37. catch (IllegalStateException ex) { /**/ }
  38. }
  39. }
Add Comment
Please, Sign In to add comment