Commit 7aa9a727 authored by mathieugautron's avatar mathieugautron

Fix the bug of equals methodes in Travel, Calendar and Correspondence,...

Fix the bug of equals methodes in Travel, Calendar and Correspondence, implement their test methodes
parent b5808800
......@@ -55,19 +55,11 @@ public class Calendar {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Calendar calendar = (Calendar) o;
boolean res;
if (owner.isSet() && calendar.getAgentAssociation().isSet()) {
res = owner.get().equals(calendar.getAgentAssociation().get());
} else {
res = true;
}
if (travels.size() != calendar.getTravelAssociation().size()) {
System.out.println("Je passe ici");
return false;
}
for (int i = 0; i < travels.size(); i++) {
boolean res = true;
int i=0;
while (travels.size() > i && calendar.getTravelAssociation().size() > i) {
res = res && calendar.getTravelAssociation().get(i).equals(travels.get(i));
i++;
}
return res;
}
......
......@@ -107,8 +107,8 @@ public class Correspondence {
Correspondence that = (Correspondence) o;
return getStartCity().equals(that.getStartCity()) &&
getDestinationCity().equals(that.getDestinationCity()) &&
getStartTime() == that.getStartTime() &&
getArrivalTime() == that.getArrivalTime();
getStartTime().equals(that.getStartTime()) &&
getArrivalTime().equals(that.getArrivalTime());
}
/**
......
......@@ -60,4 +60,17 @@ public class Travel {
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Travel travel = (Travel) o;
boolean res = true;
int i=0;
while (steps.size() > i && travel.getCorrespondenceAssociation().size() > i) {
res = res && travel.getCorrespondenceAssociation().get(i).equals(steps.get(i));
i++;
}
return res;
}
}
......@@ -78,11 +78,12 @@ public class CalendarTest {
@Test
public void equalsIfTheyHaveTheSameValuesTest() {
Calendar lememe = new Calendar();
for (Travel t: listoftravel) {
toTest.addTravel(t);
lememe.addTravel(t);
for (int i=0; i<listoftravel.size(); i++) {
toTest.addTravel(listoftravel.get(i));
lememe.addTravel(listoftravel.get(i));
}
assertTrue(toTest.equals(lememe));
}
@AfterEach
......
......@@ -160,6 +160,18 @@ class CorrespondenceTest {
assertFalse(correspondenceParisToNewYork_2.collapseWithCorrespondence(correspondenceParisToNewYork));
}
@Test
public void equalsIfItsTheSameObjectTest() {
Correspondence lememe = this.correspondenceParisToNewYork;
assertTrue(correspondenceParisToNewYork.equals(lememe));
}
@Test
public void equalsIfTheyHaveTheSameValuesTest() {
Correspondence lememe = new Correspondence(startCity1, destinationCity1, startTime1, arrivalTime1);
assertTrue(correspondenceParisToNewYork.equals(lememe));
}
@AfterEach
......
......@@ -125,16 +125,27 @@ public class TravelTest {
}
@Test
public void testIfAddTravelReturnTrueIfTravelAdded(){
assertTrue(toTest.addCorrespondence(listOfCorrespondences.get(0)));
public void equalsIfItsTheSameObjectTest() {
Travel lememe = this.toTest;
assertTrue(toTest.equals(lememe));
}
@Test
public void testIfAddTravelReturnFalseIfTheTravelAddIsAlreadyInTravel(){
toTest.addCorrespondence(listOfCorrespondences.get(0));
assertFalse(toTest.addCorrespondence(listOfCorrespondences.get(0)));
public void equalsIfTheyHaveTheSameValuesTest() {
Travel lememe = new Travel(firstCorrespondence);
for (int i=0; i<listOfCorrespondences.size(); i++) {
try {
toTest.getCorrespondenceAssociation().add(listOfCorrespondences.get(i));
} catch (MultipleReference.NumberOfElementException e) {
e.printStackTrace();
}
try {
lememe.getCorrespondenceAssociation().add(listOfCorrespondences.get(i));
} catch (MultipleReference.NumberOfElementException e) {
e.printStackTrace();
}
}
assertTrue(toTest.equals(lememe));
}
}
\ No newline at end of file
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