I don't know why the tests fail even if the lists are the same [13] [, abc, Abjh45, ch1, 5662, ch2, ch3, ch4, ch5], abc ✘ expected: listes.PureListString@5b94b04d<[, abc, Abjh45, ch1, 5662, ch2, ch3, ch4, ch5, abc]> but was: listes.PureListString@8c3b9d<[, abc, Abjh45, ch1, 5662, ch2, ch3, ch4, ch5, abc]>
Here is my code of addLast() method
public PureListString addLast(String elt) {
PureListString newCell = new PureListString(elt);
PureListString head = new PureListString(this.first);
PureListString tmp = this;
if (tmp == EMPTY_LIST)
{
return newCell;
}
newCell = tmp.tail.addLast(elt);
head.tail = newCell;
head.size = tmp.size + 1;
return head;
}
and this is the constructor
public PureListString(String elt) {
this.first = elt;
this.tail = EMPTY_LIST;
this.size = 1;
}
this is my equals method
@Override
public boolean equals(Object obj) {
if (!(obj instanceof PureListString)) {
return false;
}
PureListString p = (PureListString) obj;
if (size() != p.size()) {
return false;
}
if (!isEmpty() && !p.isEmpty()){
if (getFirst() != p.getFirst())
{
return false;
}
return removeFirst() == p.removeFirst();
}
for (int i = 0; i < size(); i++) {
if (get(i) != p.get(i))
{
return false;
}
}
return true;
}
The test method
public final void testAddLast(PureListString self, String elt) {
assumeTrue(self != null);
// Invariant
assertInvariant(self);
// préconditions
assumeTrue(elt != null);
// Purity
saveState(self);
// Exécution
PureListString result = self.addLast(elt);
// Post conditions
assertNotNull(result);
assertNotSame(result, self);
assertEquals(result.getLast(), elt);
assertTrue(result.size() == (self.size() + 1));
for (int i = 0; i < self.size(); i++) {
assertEquals(self.get(i), result.get(i));
}
if (self.isEmpty()) {
assertEquals(result.getFirst(), elt);
assertTrue(result.removeFirst().isEmpty());
} else {
assertEquals(result.getFirst(), self.getFirst());
assertEquals(result, self.removeFirst().addLast(elt).addFirst(self.getFirst()));
}
// Purity
assertPurity(self);
// Invariant
assertInvariant(self);
}
Please Note that I cannot change the test methods.