Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this is the test
- import junit.framework.TestCase;
- import org.junit.Test;
- public class TestGame extends TestCase {
- @Test
- public void testVisitorWon() {
- Game g = new Game(14, 15); //create an instance of Game
- assertFalse(g.isHomeWinner()); //check that home did not win
- assertTrue(g.isVisitorWinner()); //check that visitor did win
- assertFalse(g.isTie()); //check that it was not a tie game
- }
- @Test
- public void testHomeWon() {
- Game g = new Game(17, 16); //create an instance of Game
- assertTrue(g.isHomeWinner()); //check that home did win
- assertFalse(g.isVisitorWinner());//check that visitor did not win
- assertFalse(g.isTie()); //check that it was not a tie game
- }
- @Test
- public void testTie() {
- Game g = new Game(15, 15); //create an instance of Game
- assertFalse(g.isHomeWinner()); //check that home did not win
- assertFalse(g.isVisitorWinner());//check that visitor did not win
- assertTrue(g.isTie()); //check that it was a tie game
- }
- }
- // this is the part with the non-default constructor
- public class Game {
- int homeScore;
- int visitorScore;
- public Game( int homeScore, int visitorScore) {
- homeScore = 0;
- visitorScore = 0;
- }
- public boolean isHomeWinner() {
- return homeScore > visitorScore;
- }
- public boolean isVisitorWinner() {
- return homeScore < visitorScore;
- }
- public boolean isTie() {
- return homeScore == visitorScore;
- }
- }
Add Comment
Please, Sign In to add comment