"depot M315"
This commit is contained in:
87
tests/openClosedPrinciples/core/CarRentalServiceTest.java
Normal file
87
tests/openClosedPrinciples/core/CarRentalServiceTest.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package openClosedPrinciples.core;
|
||||
|
||||
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 openClosedPrinciples.core.Car;
|
||||
import openClosedPrinciples.core.CarRental;
|
||||
import openClosedPrinciples.core.CarRentalService;
|
||||
import openClosedPrinciples.core.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() throws Exception {
|
||||
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() {
|
||||
ArrayList<Car> possibleCars =
|
||||
(ArrayList<Car>) service.getAvailableCars(LocalDate.of(2018,9,11), 2);
|
||||
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(2017,9,11), 2);
|
||||
assertFalse(carRental==null);
|
||||
carRental = service.book(myCar0,LocalDate.of(2017,9,12), 2);
|
||||
assertTrue(carRental==null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNotAvailableCars() throws NotPossibleCarRentalException {
|
||||
service.book(myCar0,LocalDate.of(2017,9,11), 2);
|
||||
List<Car> possibleCars = service.getAvailableCars(LocalDate.of(2017,9,11), 2);
|
||||
assertEquals(2, possibleCars.size());
|
||||
possibleCars = service.getAvailableCars(LocalDate.of(2017,9,12), 2);
|
||||
assertEquals(2, possibleCars.size());
|
||||
possibleCars = service.getAvailableCars(LocalDate.of(2017,9,13), 2);
|
||||
assertEquals(3, possibleCars.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
61
tests/openClosedPrinciples/core/CarRentalTest.java
Normal file
61
tests/openClosedPrinciples/core/CarRentalTest.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package openClosedPrinciples.core;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import openClosedPrinciples.core.Car;
|
||||
import openClosedPrinciples.core.CarRental;
|
||||
import openClosedPrinciples.core.DateTools;
|
||||
|
||||
|
||||
class CarRentalTest {
|
||||
|
||||
Car myCar = new Car("1111 AB 06",50);
|
||||
CarRental carRental;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
myCar = new Car("1111 AB 06",50);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCarRental() {
|
||||
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*3,carRental.getPrice());
|
||||
}
|
||||
|
||||
}
|
47
tests/openClosedPrinciples/core/FlightServiceTest.java
Normal file
47
tests/openClosedPrinciples/core/FlightServiceTest.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package openClosedPrinciples.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import openClosedPrinciples.core.Flight;
|
||||
import openClosedPrinciples.core.FlightService;
|
||||
|
||||
public class FlightServiceTest {
|
||||
|
||||
FlightService service ;
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ArrayList<Flight> list = new ArrayList<>();
|
||||
list.add(new Flight("Belfort"));
|
||||
list.add(new Flight("Nice"));
|
||||
list.add(new Flight(100, LocalDate.of(2017, 12, 24), LocalTime.of(7, 45),"Nice", "Paris"));
|
||||
list.add(new Flight(150, LocalDate.of(2017, 12, 24), LocalTime.of(9, 30), "Nice", "Paris"));
|
||||
list.add(new Flight(150, LocalDate.of(2017, 12, 24), 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(LocalDate.of(2017, 12, 24));
|
||||
assertEquals(3, flights.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlights() {
|
||||
List<Flight> flights = service.getFlights(LocalDate.now(),"Nice","Paris");
|
||||
assertEquals(1, flights.size());
|
||||
flights = service.getFlights(LocalDate.of(2017, 12, 24),"Nice","Paris");
|
||||
assertEquals(2, flights.size());
|
||||
}
|
||||
|
||||
}
|
30
tests/openClosedPrinciples/core/FlightTest.java
Normal file
30
tests/openClosedPrinciples/core/FlightTest.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package openClosedPrinciples.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import openClosedPrinciples.core.Flight;
|
||||
|
||||
public class FlightTest {
|
||||
|
||||
|
||||
Flight f1 = new Flight(100, LocalDate.of(2017,11,11), LocalTime.of(7, 45),"Nice","Paris");
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetPrice() {
|
||||
assertEquals(100,f1.getPrice(),0);
|
||||
f1.setPrice(-1);
|
||||
assertTrue(f1.getPrice()>=10);
|
||||
assertTrue(f1.getPrice()<=1000);
|
||||
}
|
||||
|
||||
}
|
61
tests/td5/p1/testArmes.java
Normal file
61
tests/td5/p1/testArmes.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package td5.p1;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import td5.p1.arme.Arme;
|
||||
import td5.p1.personnage.Orc;
|
||||
import td5.p1.personnage.Personnage;
|
||||
import td5.p1.personnage.Tauren;
|
||||
|
||||
public class testArmes {
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
Tauren diablon = new Tauren("Diablon", 15);
|
||||
Orc azag = new Orc("Azag", 5);
|
||||
|
||||
diablon.attack(azag);
|
||||
azag.attack(diablon);
|
||||
assertEquals(100, azag.getHp());
|
||||
assertEquals(95, diablon.getHp());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
WeaponFactory wf = new WeaponFactory();
|
||||
Arme w = wf.createWeapon("SWORD", "excalibur");
|
||||
Arme w1 = wf.getWeapon("excalibur");
|
||||
assertEquals(w, w1);
|
||||
Personnage azag = new Orc("Azag", 5);
|
||||
try {
|
||||
assertEquals(Class.forName("td5.p1.arme.Epée"), azag.getArme().getClass());
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
WeaponFactory wp = new WeaponFactory();
|
||||
WeaponFactory wp2 = new ModernWeaponFactory();
|
||||
String nom = "Ref";
|
||||
int i = 0;
|
||||
Arme a1 = wp.createWeapon("SWORD", nom + i);
|
||||
i++;
|
||||
Arme a2 = wp2.createWeapon("Dague", nom + i);
|
||||
i++;
|
||||
Arme a3 = wp2.createWeapon("Fusil", nom + i);
|
||||
i++;
|
||||
Arme a4 = wp2.createWeapon("Missil", nom + i); // Type non reconnu
|
||||
assertTrue(a1 != null);
|
||||
assertTrue(a2 != null);
|
||||
assertTrue(a3 != null);
|
||||
assertTrue(a4 == null);
|
||||
assertEquals(a1, wp.getWeapon(nom + 0)); // On retrouve une arme créée par un autre
|
||||
assertEquals(a3, wp.getWeapon(nom + 2));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user