Commit 7756abab authored by Yotlan LE CROM's avatar Yotlan LE CROM
Browse files

TP is finish

parent 57206405
......@@ -88,6 +88,8 @@ public class TicketReservationSystemImpl implements TicketReservationSystem {
public Trip createTrip(City origin, City destination, Train train, Instant departure, Instant arrival) throws TripException {
List<Trip> trainTrips = this.findOrderedTripsOfTrain(train);
if(origin == destination)
throw new TripException();
if (!trainTrips.isEmpty()) {
......@@ -95,17 +97,15 @@ public class TicketReservationSystemImpl implements TicketReservationSystem {
boolean comesAfter = lastTrainTrip.findRealArrivalTime().isBefore(departure);
boolean c1 = lastTrainTrip.getDestination() == origin;
boolean c1 = lastTrainTrip.getTrain() != train || lastTrainTrip.getTrain() == train && lastTrainTrip.getDestination() == origin; //change lastTrainTrip.getDestination() == origin to lastTrainTrip.getTrain() != train || lastTrainTrip.getTrain() == train && lastTrainTrip.getDestination() == origin
boolean c2 = Duration.between(lastTrainTrip.findRealArrivalTime(), departure)
.compareTo(Duration.ofMinutes(10)) == 1;
.compareTo(Duration.ofMinutes(10)) > 0; //change ==1 to >0
boolean c3 = arrival.isAfter(departure);
boolean c4 = origin != destination;
System.out.println("c1" + c1 + "|c2" + c2 + "|c3" + c3 + "|c4" + c4);
if (!(comesAfter && c1 && c2 && c3 && c4))
throw new TripException();
}
......
......@@ -4,7 +4,9 @@ import fr.univnantes.trainreservation.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
......@@ -13,20 +15,26 @@ public class TicketReservationSystemImplTest {
City city1;
City city2;
City city3;
Train train1;
Train train2;
Trip trip1;
Trip trip2;
Instant t1;
Instant t2;
Instant t3;
Instant t4;
ZoneId zoneId1;
Ticket ticket1;
LocalDate date1;
LocalDate date2;
Duration delay1;
@BeforeEach
public void setUp(){
city1 = new CityImpl("Nantes");
city2 = new CityImpl("Rennes");
city3 = new CityImpl("Angers");
train1 = new TrainImpl("TER orange", 20);
train2 = new TrainImpl("TER bleu", 100);
t1 = Instant.parse("2021-12-10T15:30:45.123Z");
......@@ -34,16 +42,26 @@ public class TicketReservationSystemImplTest {
t3 = Instant.parse("2021-12-10T16:30:45.123Z");
t4 = Instant.parse("2021-12-10T16:32:45.123Z");
zoneId1 = ZoneId.of("Europe/Paris");
date1 = LocalDate.parse("2021-12-09");
date2 = LocalDate.parse("2021-12-10");
delay1 = Duration.ofDays(2);
}
//getAllBookedTickets's Tests
@Test
public void getAllBookedTicketsTest() throws TripException, ReservationException{
public void testIsTheListIsEmpty1() throws TripException, ReservationException{
//Test is the list is empty
TicketReservationSystemImpl res = new TicketReservationSystemImpl(zoneId1);
assertTrue(res.getAllBookedTickets().isEmpty());
//Test is the tickets we add into the list is really here
}
@Test
public void testIsTheListContainsOurTickets1() throws TripException, ReservationException{
TicketReservationSystemImpl res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
ticket1 = res.createTrip(city1, city2, train1, t1, t2).bookTicket("Bernard");
......@@ -51,14 +69,21 @@ public class TicketReservationSystemImplTest {
}
//getAllCancelledTickets's Tests
@Test
public void getAllCancelledTicketsTest() throws TripException, ReservationException{
public void testIsTheListIsEmpty2() throws TripException, ReservationException{
//Test is the list is empty
TicketReservationSystemImpl res = new TicketReservationSystemImpl(zoneId1);
assertTrue(res.getAllCancelledTickets().isEmpty());
//Test is the tickets we cancel into the list is here
}
@Test
public void testIsTheListContainsOurTickets2() throws TripException, ReservationException{
TicketReservationSystemImpl res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
trip1 = res.createTrip(city1, city2, train1, t1, t2);
......@@ -68,21 +93,189 @@ public class TicketReservationSystemImplTest {
}
//findPossibleExchange's Tests
@Test
public void findPossibleExchangeTest() throws TripException, ReservationException{
public void testIsTheListIsEmpty3() throws TripException, ReservationException{
//Test is the list is empty
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
ticket1 = res.createTrip(city1, city2, train1, t1, t2).bookTicket("Jean");
assertTrue(res.findPossibleExchanges(ticket1).isEmpty());
//Test is another trip is sent if is fill the requirements
res.createTrip(city2, city1, train2, t1, t2);
}
@Test
public void testIsTheListContainsOurTrips1() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
ticket1 = res.createTrip(city1, city2, train1, t1, t2).bookTicket("Jean");
trip1 = res.createTrip(city1, city2, train2, t3, t4);
assertTrue(res.findPossibleExchanges(ticket1).contains(trip1));
}
//findAvailableTrip's Tests
@Test
public void testIsTheListIsEmptyAtThisDate() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
res.createTrip(city1, city2, train1, t1, t2);
assertTrue(res.findAvailableTrips(city1, date1).isEmpty());
}
@Test
public void testIsTheListIsEmptyAtThisCity() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
res.addCity(city3);
res.createTrip(city1, city2, train1, t1, t2);
assertTrue(res.findAvailableTrips(city3, date2).isEmpty());
}
@Test
public void testIsTheListContainsOurTrips2() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
trip1 = res.createTrip(city1, city2, train1, t1, t2);
assertTrue(res.findAvailableTrips(city1, date2).contains(trip1));
}
//cancelTrip's Tests
@Test
public void testIsOurListContainsOurTrips3() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
trip1 = res.createTrip(city1, city2, train1, t1, t2);
res.cancelTrip(trip1);
assertTrue(res.getAllCancelledTrips().contains(trip1) && trip1.isCancelled());
}
@Test
public void testIsCancelTripWhoWasAlreadyCancelDoNothing() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
trip1 = res.createTrip(city1, city2, train1, t1, t2);
res.cancelTrip(trip1);
assertAll(
() -> res.cancelTrip(trip1)
);
}
//createTrip's Tests
@Test
public void testIsTripWasCreateInCorrectOrder() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
res.createTrip(city1, city2, train1, t2, t3);
assertThrows(TripException.class,
() -> res.createTrip(city2, city1, train1, t1, t4)
);
}
@Test
public void testIsOriginAndDestinationAreEquals() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city3);
assertThrows(TripException.class,
() -> res.createTrip(city3, city3, train1, t1, t2)
);
}
@Test
public void testIsDestinationAndOriginAreTheSame() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
res.addCity(city3);
res.createTrip(city1, city2, train1, t1, t2);
assertThrows(TripException.class,
() -> res.createTrip(city3, city1, train1, t3, t4)
);
}
@Test
public void testIsCreationOfTripWork() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
assertAll(
() -> trip1 = res.createTrip(city1, city2, train1, t1, t2),
() -> assertTrue(res.getAllTrips().contains(trip1))
);
}
//delayTripDeparture's Tests
@Test
public void testIsDelayTripDepartureWork() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
trip1 = res.createTrip(city1, city2, train1, t1, t2);
res.delayTripDeparture(trip1, delay1);
assertTrue(trip1.isDelayed());
}
//delayTripArrival's Tests
@Test
public void testIsDelayTripArrivalWork() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
trip1 = res.createTrip(city1, city2, train1, t1, t2);
res.delayTripArrival(trip1, delay1);
assertTrue(trip1.findRealArrivalTime() != t2);
}
@Test
public void testIsDelayTripArrivalHaveAnImpactOnSecondTrain() throws TripException, ReservationException{
TicketReservationSystem res = new TicketReservationSystemImpl(zoneId1);
res.addCity(city1);
res.addCity(city2);
res.addCity(city3);
trip1 = res.createTrip(city1, city2, train1, t1, t2);
trip2 = res.createTrip(city2, city3, train1, t3, t4);
res.delayTripArrival(trip1, delay1);
assertTrue(trip2.isDelayed());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment