TD4
This commit is contained in:
104
2020-2021/tests/TD4/cars/CarRentalServiceTest.java
Normal file
104
2020-2021/tests/TD4/cars/CarRentalServiceTest.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package TD4.cars;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import TD4.util.NotPossibleCarRentalException;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class CarRentalServiceTest {
|
||||
|
||||
CarRentalService service ;
|
||||
Car myCar0 = new Car("1111 AB 06",50);
|
||||
Car myCar1 = new Car("1111 AB 75",100);
|
||||
Car myCar2 = new Car("1111 AB 83",75);
|
||||
LocalDate currentDate;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
myCar0 = new Car("1111 AB 06",50);
|
||||
myCar1 = new Car("1111 AB 75",100);
|
||||
myCar2 = new Car("1111 AB 83",75);
|
||||
service = new CarRentalService( new ArrayList<>(Arrays.asList(myCar0, myCar1, myCar2) ) ) ;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvailableCars() throws NotPossibleCarRentalException {
|
||||
LocalDate current = LocalDate.of(2020,9,11);
|
||||
List<Car> possibleCars =
|
||||
service.getAvailableCars(current, 2);
|
||||
assertEquals(3, possibleCars.size());
|
||||
|
||||
CarRental carRental = service.book(myCar0,current,2);
|
||||
assertTrue(carRental != null);
|
||||
possibleCars =
|
||||
service.getAvailableCars(current, 1);
|
||||
assertEquals(2, possibleCars.size());
|
||||
possibleCars =
|
||||
service.getAvailableCars(current, 2);
|
||||
assertEquals(2, possibleCars.size());
|
||||
possibleCars =
|
||||
service.getAvailableCars(LocalDate.of(2020,9,12), 1);
|
||||
assertEquals(2, possibleCars.size());
|
||||
possibleCars =
|
||||
service.getAvailableCars(LocalDate.of(2020,9,13), 1);
|
||||
assertEquals(3, possibleCars.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBookAnAvalaibleCar() throws NotPossibleCarRentalException {
|
||||
CarRental carRental = service.book(myCar0,LocalDate.of(2018,9,11), 2);
|
||||
assertFalse(carRental==null);
|
||||
List<Car> possibleCars = service.getAvailableCars(LocalDate.of(2018,9,11), 1);
|
||||
assertEquals(2, possibleCars.size());
|
||||
|
||||
possibleCars = service.getAvailableCars(LocalDate.of(2018,9,12), 3);
|
||||
assertEquals(2, possibleCars.size());
|
||||
|
||||
possibleCars = service.getAvailableCars(LocalDate.of(2018,9,13), 3);
|
||||
assertEquals(3, possibleCars.size());
|
||||
|
||||
possibleCars = service.getAvailableCars(LocalDate.of(2018,9,9), 4);
|
||||
assertEquals(2, possibleCars.size());
|
||||
|
||||
possibleCars = service.getAvailableCars(LocalDate.of(2018,9,19), 7);
|
||||
assertEquals(3, possibleCars.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBookANonAvalaibleCar() throws NotPossibleCarRentalException {
|
||||
CarRental carRental = service.book(myCar0,LocalDate.of(2020,9,11), 2);
|
||||
assertFalse(carRental==null);
|
||||
carRental = service.book(myCar0,LocalDate.of(2020,9,12), 2);
|
||||
assertTrue(carRental==null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNotAvailableCars() throws NotPossibleCarRentalException {
|
||||
service.book(myCar0,LocalDate.of(2020,9,11), 2);
|
||||
List<Car> possibleCars = service.getAvailableCars(LocalDate.of(2020,9,11), 2);
|
||||
assertEquals(2, possibleCars.size());
|
||||
possibleCars = service.getAvailableCars(LocalDate.of(2020,9,12), 2);
|
||||
assertEquals(2, possibleCars.size());
|
||||
possibleCars = service.getAvailableCars(LocalDate.of(2020,9,13), 2);
|
||||
assertEquals(3, possibleCars.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
61
2020-2021/tests/TD4/cars/CarRentalTest.java
Normal file
61
2020-2021/tests/TD4/cars/CarRentalTest.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package TD4.cars;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import TD4.util.DateTools;
|
||||
|
||||
|
||||
|
||||
|
||||
class CarRentalTest {
|
||||
|
||||
Car myCar ;
|
||||
CarRental carRental;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
myCar = new Car("1111 AB 06",50);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCarRentalCreation() {
|
||||
carRental = new CarRental(myCar, LocalDate.of(2018, 8, 30), 3);
|
||||
assertEquals( myCar.getDayPrice()*3, carRental.getPrice());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCarRentalAvailability() {
|
||||
carRental = new CarRental(myCar, LocalDate.of(2018, 8, 30), 3);
|
||||
LocalDate[] dates = DateTools.getDays(LocalDate.of(2018, 8, 30), 3);
|
||||
assertEquals(3, dates.length );
|
||||
dates = DateTools.getDays(LocalDate.of(2018, 8, 30), 1);
|
||||
assertTrue(carRental.includeADate(dates),"date de début OK");
|
||||
|
||||
dates = DateTools.getDays(LocalDate.of(2018, 8, 29), 1);
|
||||
assertFalse(carRental.includeADate(dates),"date à un jour avant");
|
||||
|
||||
dates = DateTools.getDays(LocalDate.of(2018, 9, 2), 1);
|
||||
assertFalse(carRental.includeADate(dates),"date à un jour après");
|
||||
|
||||
dates = DateTools.getDays(LocalDate.of(2018, 8, 25), 10);
|
||||
assertTrue(carRental.includeADate(dates),"date incluse après");
|
||||
|
||||
dates = DateTools.getDays(LocalDate.of(2018, 9, 1), 1);
|
||||
assertTrue(carRental.includeADate(dates),"date incluse sur la fin");
|
||||
dates = DateTools.getDays(LocalDate.of(2018, 8, 31), 10);
|
||||
assertTrue(carRental.includeADate(dates),"date incluse sur la fin");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPrice() {
|
||||
carRental = new CarRental(myCar, LocalDate.of(2017, 8, 31), 3);
|
||||
assertEquals(50,myCar.getDayPrice());
|
||||
assertEquals(50.0*3,carRental.getPrice());
|
||||
}
|
||||
|
||||
}
|
75
2020-2021/tests/TD4/flights/FlightServiceTest.java
Normal file
75
2020-2021/tests/TD4/flights/FlightServiceTest.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package TD4.flights;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
||||
public class FlightServiceTest {
|
||||
|
||||
private static final String PARIS = "Paris";
|
||||
private static final String NICE = "Nice";
|
||||
private static final LocalDate dateToTest = LocalDate.of(2017, 12, 24);
|
||||
|
||||
FlightService service ;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ArrayList<Flight> list = new ArrayList<>();
|
||||
list.add(new Flight("Belfort"));
|
||||
list.add(new Flight(NICE));
|
||||
list.add(new Flight(100, dateToTest, LocalTime.of(7, 45),NICE, PARIS));
|
||||
list.add(new Flight(20, dateToTest, LocalTime.of(9, 30), NICE, PARIS));
|
||||
list.add(new Flight(150, dateToTest, LocalTime.of(18, 30), PARIS, NICE));
|
||||
service = new FlightService(list);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetFlightsOnADivenDate() {
|
||||
List<Flight> flights = service.getFlights(LocalDate.now());
|
||||
assertEquals(2, flights.size());
|
||||
flights = service.getFlights(dateToTest);
|
||||
assertEquals(3, flights.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlights() {
|
||||
List<Flight> flights = service.getFlights(LocalDate.now(),NICE,PARIS);
|
||||
assertEquals(1, flights.size());
|
||||
flights = service.getFlights(dateToTest,NICE,PARIS);
|
||||
assertEquals(2, flights.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedByPrice() {
|
||||
ArrayList<Flight> list = new ArrayList<>();
|
||||
list.add(new Flight(100, dateToTest, LocalTime.of(7, 45),NICE, PARIS));
|
||||
list.add(new Flight(20, dateToTest, LocalTime.of(9, 30), NICE, PARIS));
|
||||
list.add(new Flight(150, dateToTest, LocalTime.of(18, 30), PARIS, NICE));
|
||||
service = new FlightService(list);
|
||||
List<Flight> flights = service.sortedByPrice();
|
||||
assertEquals(20,flights.get(0).getPrice(),0.01);
|
||||
assertEquals(100,flights.get(1).getPrice(),0.01);
|
||||
assertEquals(150,flights.get(2).getPrice(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBestPrice() {
|
||||
ArrayList<Flight> list = new ArrayList<>();
|
||||
list.add(new Flight(100, dateToTest, LocalTime.of(7, 45),NICE, PARIS));
|
||||
list.add(new Flight(20, dateToTest, LocalTime.of(9, 30), NICE, PARIS));
|
||||
list.add(new Flight(150, dateToTest, LocalTime.of(18, 30), PARIS, NICE));
|
||||
service = new FlightService(list);
|
||||
assertEquals(20, service.getFlyWithBestPrice().getPrice());
|
||||
}
|
||||
|
||||
}
|
29
2020-2021/tests/TD4/flights/FlightTest.java
Normal file
29
2020-2021/tests/TD4/flights/FlightTest.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package TD4.flights;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FlightTest {
|
||||
|
||||
|
||||
Flight f1 ;
|
||||
@Before
|
||||
public void setUp() {
|
||||
f1 = new Flight(100, LocalDate.of(2017,11,11), LocalTime.of(7, 45),"Nice","Paris");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetPrice() {
|
||||
assertEquals(100,f1.getPrice(),0);
|
||||
f1.setPrice(-1);
|
||||
assertTrue(f1.getPrice()>=10);
|
||||
assertTrue(f1.getPrice()<=1000);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user