import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; public class SimpleTest { private static TicketBuyer ticketBuyer; @BeforeClass public static void init() { ticketBuyer = new OnlineTicketBuyer(); } @Test public void test1() { int seasonPrice = 5; boolean[] days = {true, true, false, true, false, true}; int optimalPrice = 4; test(seasonPrice, days, optimalPrice); } @Test public void test2() { int seasonPrice = 3; boolean[] days = {false, true, false, true, false, true, true}; int optimalPrice = 3; test(seasonPrice, days, optimalPrice); } @Test public void test3() { int seasonPrice = 2; boolean[] days = {true, true, true, true, true}; int optimalPrice = 2; test(seasonPrice, days, optimalPrice); } private void test(int seasonPrice, boolean[] days, int optimalPrice) { int cost = 0; boolean boughtSeason = false; ticketBuyer.startSeason(days.length, seasonPrice); for (boolean travel : days) { switch (ticketBuyer.newDay(travel)) { case SINGLE: cost++; break; case SEASON: boughtSeason = true; cost += seasonPrice; break; case NONE: Assert.assertTrue("Je hebt geen ticket op een reisdag.", !travel || boughtSeason); } } Assert.assertTrue(cost < 2 * optimalPrice); } }