Skip to content
Snippets Groups Projects
Commit cbd80d54 authored by Alexandre MAINTIER's avatar Alexandre MAINTIER
Browse files

initialisation

parent a9ccfd76
No related branches found
No related tags found
No related merge requests found
package tp06;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.LocalDate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class CompanyTest {
private Employee ts1, ts2, v1, w1, w2;
private Company society;
@BeforeEach
public void initialization() {
ts1 = new TravellingSalesperson("ts-A", LocalDate.now().minusDays(20), 20000);
ts2 = new TravellingSalesperson("ts-B", LocalDate.now().minusDays(5), 2);
v1 = new Vendor("v-A", LocalDate.now().minusDays(20), 20000);
w1 = new Worker("w-A", LocalDate.now().minusDays(20), 2000);
w2 = new Worker("w-B", LocalDate.now().minusDays(5), 2);
society = new Company();
}
@Test
public void hiringSalesPersonTest() {
assertEquals(0, society.getNbEmployee());
society.addEmployee(ts1);
assertEquals(1, society.getNbEmployee());
assertEquals(0, society.getNbWorker());
assertEquals(1, society.getNbSalesPerson());
society.addEmployee(ts2);
assertEquals(2, society.getNbEmployee());
assertEquals(0, society.getNbWorker());
assertEquals(2, society.getNbSalesPerson());
society.addEmployee(v1);
assertEquals(3, society.getNbEmployee());
assertEquals(0, society.getNbWorker());
assertEquals(3, society.getNbSalesPerson());
}
@Test
public void hiringWorkerTest() {
assertEquals(0, society.getNbEmployee());
society.addEmployee(w1);
assertEquals(1, society.getNbEmployee());
assertEquals(1, society.getNbWorker());
assertEquals(0, society.getNbSalesPerson());
society.addEmployee(w2);
assertEquals(2, society.getNbEmployee());
assertEquals(2, society.getNbWorker());
assertEquals(0, society.getNbSalesPerson());
}
private void hiring() {
society.addEmployee(ts1);
society.addEmployee(ts2);
society.addEmployee(v1);
society.addEmployee(w1);
society.addEmployee(w2);
}
private void hiring_alternative() {
society.addEmployee(ts1);
society.addEmployee(v1);
society.addEmployee(w1);
}
@Test
public void firingDate_none() {
hiring();
assertEquals(5, society.getNbEmployee());
assertEquals(3, society.getNbSalesPerson());
assertEquals(2, society.getNbWorker());
society.firing(LocalDate.now());
assertEquals(5, society.getNbEmployee());
assertEquals(3, society.getNbSalesPerson());
assertEquals(2, society.getNbWorker());
}
@Test
public void firingDate_all() {
hiring();
assertEquals(5, society.getNbEmployee());
assertEquals(3, society.getNbSalesPerson());
assertEquals(2, society.getNbWorker());
society.firing(LocalDate.now().minusDays(50));
assertEquals(0, society.getNbEmployee());
assertEquals(0, society.getNbSalesPerson());
assertEquals(0, society.getNbWorker());
}
@Test
public void firingDate_some() {
hiring();
assertEquals(5, society.getNbEmployee());
assertEquals(3, society.getNbSalesPerson());
assertEquals(2, society.getNbWorker());
society.firing(LocalDate.now().minusDays(10));
assertEquals(3, society.getNbEmployee());
assertEquals(2, society.getNbSalesPerson());
assertEquals(1, society.getNbWorker());
}
@Test
public void firingObjective_none() {
hiring_alternative();
assertEquals(3, society.getNbEmployee());
assertEquals(2, society.getNbSalesPerson());
assertEquals(1, society.getNbWorker());
society.firing();
assertEquals(3, society.getNbEmployee());
assertEquals(2, society.getNbSalesPerson());
assertEquals(1, society.getNbWorker());
}
@Test
public void firingObjective_some() {
hiring();
assertEquals(5, society.getNbEmployee());
assertEquals(3, society.getNbSalesPerson());
assertEquals(2, society.getNbWorker());
society.firing();
assertEquals(3, society.getNbEmployee());
assertEquals(2, society.getNbSalesPerson());
assertEquals(1, society.getNbWorker());
}
}
package tp06;
import java.time.LocalDate;
public abstract class Employee{
private String name;
private LocalDate hiringDate;
public Employee(String name, LocalDate hiringDate){
this.name = name;
this.hiringDate = hiringDate;
}
public String getName(){
return this.name;
}
public LocalDate getHiringDate(){
return this.hiringDate;
}
public abstract String getTitle();
public abstract double getWages();
public abstract boolean objectiveFulfilled();
}
\ No newline at end of file
package tp06;
import java.time.LocalDate;
abstract class Salesperson extends Employee{
private double turnover;
public static double objective = 10000;
public Salesperson(double turnover, String name, LocalDate hiringDate){
super(name, hiringDate);
this.turnover = turnover;
}
public double getTurnover(){
return this.turnover;
}
public String toString(){
return this.getName() + ", embauché le " + this.getHiringDate() + "fait un profit de : " + this.getTurnover();
}
public boolean objectiveFulfilled(){
return turnover>=objective;
}
}
\ No newline at end of file
package tp06;
import java.time.LocalDate;
public class TravellingSalesperson extends Salesperson{
private final double PERCENTAGE = 0.2;
private final double BONUS = 800;
public TravellingSalesperson(String nom, LocalDate hiringDate, double turnover){
super(turnover, nom, hiringDate);
}
public String getTitle(){
return "Vendeur";
}
public double getWages(){
return BONUS + PERCENTAGE*this.getTurnover();
}
}
\ No newline at end of file
package tp06;
import java.time.LocalDate;
public class Vendor extends Salesperson{
private final double PERCENTAGE = 0.2;
private final double BONUS = 400;
public Vendor(String nom, LocalDate hiringDate, double turnover){
super(turnover, nom, hiringDate);
}
public String getTitle(){
return "Vendeur";
}
public double getWages(){
return BONUS + PERCENTAGE*this.getTurnover();
}
}
package tp06;
import java.time.LocalDate;
public class Worker extends Employee{
private final double BY_UNIT = 5;
private int units;
private static int objective = 1000;
public Worker(String name, LocalDate hiringDate, int units){
super(name, hiringDate);
this.units=units;
}
public String getTitle(){
return "Travailleur";
}
public double getWages(){
return units*BY_UNIT;
}
public String toString(){
return this.getName() + ", embauché le " + this.getHiringDate() + "est payé : " + this.getWages();
}
public boolean objectiveFulfilled(){
return units>=objective;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment