Guest User

Untitled

a guest
Dec 11th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // this is the test
  2. import junit.framework.TestCase;
  3. import org.junit.Test;
  4.  
  5. public class TestGame extends TestCase {
  6. @Test
  7. public void testVisitorWon() {
  8. Game g = new Game(14, 15); //create an instance of Game
  9.  
  10. assertFalse(g.isHomeWinner()); //check that home did not win
  11. assertTrue(g.isVisitorWinner()); //check that visitor did win
  12. assertFalse(g.isTie()); //check that it was not a tie game
  13. }
  14. @Test
  15. public void testHomeWon() {
  16. Game g = new Game(17, 16); //create an instance of Game
  17.  
  18. assertTrue(g.isHomeWinner()); //check that home did win
  19. assertFalse(g.isVisitorWinner());//check that visitor did not win
  20. assertFalse(g.isTie()); //check that it was not a tie game
  21. }
  22. @Test
  23. public void testTie() {
  24. Game g = new Game(15, 15); //create an instance of Game
  25.  
  26. assertFalse(g.isHomeWinner()); //check that home did not win
  27. assertFalse(g.isVisitorWinner());//check that visitor did not win
  28. assertTrue(g.isTie()); //check that it was a tie game
  29. }
  30. }
  31.  
  32. // this is the part with the non-default constructor
  33. public class Game {
  34. int homeScore;
  35. int visitorScore;
  36.  
  37. public Game( int homeScore, int visitorScore) {
  38. homeScore = 0;
  39. visitorScore = 0;
  40.  
  41. }
  42.  
  43. public boolean isHomeWinner() {
  44. return homeScore > visitorScore;
  45. }
  46.  
  47. public boolean isVisitorWinner() {
  48. return homeScore < visitorScore;
  49. }
  50.  
  51. public boolean isTie() {
  52. return homeScore == visitorScore;
  53. }
  54. }
Add Comment
Please, Sign In to add comment