Skip to content

Instantly share code, notes, and snippets.

@dndx
Created September 17, 2012 03:49
Show Gist options
  • Save dndx/3735445 to your computer and use it in GitHub Desktop.
Save dndx/3735445 to your computer and use it in GitHub Desktop.
Test Case for Assignment1
/* Copyright (c) <2012> <Datong Sun>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package hw1;
/**
* Test class for preassignment1
* Total 58 tests included
* @author Datong Sun
*
*/
public class TestClass {
public static void main(String[] args) {
Ticket ticket = new Ticket(1000, false); //A new ticket with $1 in it, no discount
System.out.printf("This ticket should have 1000 cents in it, it have %d now.\n", ticket.getBalance());
System.out.printf("This ticket should NOT be a discounted ticket, the discount status is %s now.\n", ticket.isDiscounted())
;
System.out.printf("This ticket should NOT be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("This ticket should return TicketUtil.INVALID_ZONE as start zone, does the return value equal to TicketUtil.INVALID_ZONE? %s.\n", ticket.getStartZone() == TicketUtil.INVALID_ZONE);
;
System.out.printf("Let's begin a trip from zone 5.\n");
ticket.beginTrip(5);
System.out.printf("Now the start zone should be 5, the actual value is %d.\n", ticket.getStartZone());
System.out.printf("This ticket should be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("Now the trip ends at zone 2, let's reduce the amount by 725 cents.\n");
ticket.charge(TicketUtil.calculateRideCost(5, 2, false));
System.out.printf("Now this ticket should have 275 cents left in it, it have %d now.\n", ticket.getBalance());
System.out.printf("If the above number is not correct, you may have some problem with your TicketUtil.calculateRideCost or Ticket.charge.\n");
System.out.printf("This ticket should NOT be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("This is the end of Non-discount Ticket test case.\n\n");
//Non-discount Ticket case ends
ticket = new Ticket(1000, true); //A new ticket with $1 in it, with discount
System.out.printf("This ticket should have 1000 cents in it, it have %d now.\n", ticket.getBalance());
System.out.printf("This ticket should be a discounted ticket, the discount status is %s now.\n", ticket.isDiscounted())
;
System.out.printf("This ticket should NOT be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("This ticket should return TicketUtil.INVALID_ZONE as start zone, does the return value equal to TicketUtil.INVALID_ZONE? %s.\n", ticket.getStartZone() == TicketUtil.INVALID_ZONE);
;
System.out.printf("Let's begin a trip from zone 2.\n");
ticket.beginTrip(2);
System.out.printf("Now the start zone should be 2, the actual value is %d.\n", ticket.getStartZone());
System.out.printf("This ticket should be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("Now the trip ends at zone 3, let's reduce the amount by 725 cents.\n");
ticket.charge(TicketUtil.calculateRideCost(2, 3, true));
System.out.printf("Now this ticket should have 730 cents left in it, it have %d now.\n", ticket.getBalance());
System.out.printf("If the above number is not correct, you may have some problem with your TicketUtil.calculateRideCost or Ticket.charge.\n");
System.out.printf("This ticket should NOT be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("Let's begin another trip from zone 10.\n");
ticket.beginTrip(10);
System.out.printf("Now the start zone should be 10, the actual value is %d.\n", ticket.getStartZone());
System.out.printf("This ticket should be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("Now the trip ends at zone 3, let's reduce the amount by 990 cents.\n");
System.out.printf("The charge should fail, does it failed? %s.\n", ticket.charge(TicketUtil.calculateRideCost(10, 3, true)) ? "NO" : "YES");
System.out.printf("Now this ticket should still have 730 cents left in it, it have %d now.\n", ticket.getBalance());
System.out.printf("This ticket should still in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("This is the end of discount Ticket test case.\n\n");
//discount Ticket test case ends
TicketMachine tm = new TicketMachine();
System.out.printf("This ticket machine should have no sold now, the actual value is %d.\n", tm.totalTickets());
System.out.printf("This ticket machine should have no money in box now, the actual value is %d.\n", tm.totalCost());
System.out.printf("Now we are selling a single trip ticket from zone 3 to zone 7, NO discount.\n");
ticket = tm.purchaseTicket(3, 7, false);
System.out.printf("This ticket should have 900 cents in it, it have %d now.\n", ticket.getBalance());
System.out.printf("This ticket should NOT be a discounted ticket, the discount status is %s now.\n", ticket.isDiscounted())
;
System.out.printf("Now we are selling a single trip ticket from zone 7 to zone 3, WITH discount.\n");
ticket = tm.purchaseTicket(7, 3, true);
System.out.printf("This ticket should have 630 cents in it, it have %d now.\n", ticket.getBalance());
System.out.printf("This ticket should be a discounted ticket, the discount status is %s now.\n", ticket.isDiscounted())
;
System.out.printf("Now we are selling a 3 times ticket from zone 3 to zone 20, NO discount.\n");
ticket = tm.purchaseTicket(3, 3, 20, false);
System.out.printf("This ticket should have 9525 cents in it, it have %d now.\n", ticket.getBalance());
System.out.printf("This ticket should NOT be a discounted ticket, the discount status is %s now.\n", ticket.isDiscounted());
System.out.printf("Now we are selling a 10 times ticket from zone 3 to zone 3, WITH discount.\n");
ticket = tm.purchaseTicket(10, 3, 3, true);
System.out.printf("This ticket should have 1500 cents in it, it have %d now.\n", ticket.getBalance());
System.out.printf("This ticket should be a discounted ticket, the discount status is %s now.\n", ticket.isDiscounted());
System.out.printf("Now we are selling a ticket contains 1234 cents in it, WITH discount.\n");
ticket = tm.purchaseTicket(1234, true);
System.out.printf("This ticket should have 1234 cents in it, it have %d now.\n", ticket.getBalance());
System.out.printf("This ticket should be a discounted ticket, the discount status is %s now.\n", ticket.isDiscounted());
System.out.printf("This ticket machine should have 5 sold now, the actual value is %d.\n", tm.totalTickets());
System.out.printf("This ticket machine should have 13789 cents in box now, the actual value is %d.\n", tm.totalCost());
System.out.printf("This is the end of TicketMachine test case.\n\n");
//TicketMachine test ends
Turnstile ts3 = new Turnstile(3); //New turnstile at zone 3
Turnstile ts7 = new Turnstile(7); //New turnstile at zone 7
System.out.printf("This turnstile should have NO get in now, the actual value is %d.\n", ts3.getEntranceCount());
System.out.printf("This turnstile should have NO get in now, the actual value is %d.\n", ts7.getEntranceCount());
System.out.printf("This turnstile should have NO get out now, the actual value is %d.\n", ts3.getExitCount());
System.out.printf("This turnstile should have NO get out now, the actual value is %d.\n", ts7.getExitCount());
ticket = new Ticket(1000, false);
System.out.printf("Let's get in from zone 7.\n");
System.out.printf("Did we get in? %s.\n", ts7.swipeIn(ticket));
System.out.printf("Let's get out from zone 3.\n");
System.out.printf("Did we get out? %s.\n", ts3.swipeOut(ticket));
System.out.printf("The card should have 100 cents left now, the actual value is %d.\n", ticket.getBalance());
System.out.printf("Now let's get in from zone 3 again.\n");
System.out.printf("We should NOT be able to get in, did we get in? %s.\n", ts3.swipeIn(ticket));
System.out.printf("Let's get out from zone 7.\n");
System.out.printf("We should not able to get out, did we get out? %s.\n", ts7.swipeOut(ticket));
ticket = new Ticket(3000, true);
ticket.beginTrip(5);
System.out.printf("We got a ticket that has the start zone of %d and %d cents in it, also it's discount status is %s.\n", ticket.getStartZone(), ticket.getBalance(), ticket.isDiscounted());
System.out.printf("Now let's get in from zone3.\n");
System.out.printf("Did we get in? %s.\n", ts3.swipeIn(ticket));
System.out.printf("But we should have only 2610 cents left, the actual value is %d.\n", ticket.getBalance());
System.out.printf("This ticket should be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("This ticket should have a start zone of 3, the start zone is %s now.\n", ticket.getStartZone());
ticket = new Ticket(1000, false);
ticket.beginTrip(15);
System.out.printf("We got a ticket that has the start zone of %d and %d cents in it, also it's discount status is %s.\n", ticket.getStartZone(), ticket.getBalance(), ticket.isDiscounted());
System.out.printf("Now let's get in from zone7.\n");
System.out.printf("We should not be able to get in, did we get in? %s.\n", ts7.swipeIn(ticket));
System.out.printf("We should still have 1000 cents left, the actual value is %d.\n", ticket.getBalance());
System.out.printf("This ticket should still be in a transit, the transit status is %s now.\n", ticket.isInTransit());
System.out.printf("This turnstile should have 1 get in now, the actual value is %d.\n", ts3.getEntranceCount());
System.out.printf("This turnstile should have 1 get in now, the actual value is %d.\n", ts7.getEntranceCount());
System.out.printf("This turnstile should have 2 get out now, the actual value is %d.\n", ts3.getExitCount());
System.out.printf("This turnstile should have 0 get out now, the actual value is %d.\n", ts7.getExitCount());
System.out.printf("This is the end of Turnstile test case.\n\n");
//Turnstile test ends
System.out.printf("Now don't forget to check you write a private dummy constructor for TicketUtil class.\n\n");
//I don't know how to check the visibility of method by code, using try and catch will not work because calling
//a private method will cause compile error
System.out.printf("This is the end of all the test case, if you got all the result correct, that means all your class should works fine.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment