correction couverture de test Date
This commit is contained in:
@@ -35,14 +35,13 @@ class Date implements Comparable<Date> {
|
||||
int max_day = max_day(m, y);
|
||||
if (d < max_day) {
|
||||
return new Date(d + 1, m, y);
|
||||
} else if (d == max_day) {
|
||||
} else {
|
||||
if (m == 12) {
|
||||
return new Date(1, 1, y + 1);
|
||||
} else {
|
||||
return new Date(1, m + 1, y);
|
||||
}
|
||||
}
|
||||
return null; // This line should never be reached
|
||||
}
|
||||
|
||||
public Date previousDate() {
|
||||
@@ -64,18 +63,16 @@ class Date implements Comparable<Date> {
|
||||
if (other == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (isValidDate(other.getDay(), other.getMonth(), other.getYear())) {
|
||||
int cmpYear = Integer.compare(this.getYear(), other.getYear());
|
||||
if (cmpYear != 0)
|
||||
return cmpYear;
|
||||
int cmpYear = Integer.compare(this.getYear(), other.getYear());
|
||||
if (cmpYear != 0)
|
||||
return cmpYear;
|
||||
|
||||
int cmpMonth = Integer.compare(this.getMonth(), other.getMonth());
|
||||
if (cmpMonth != 0)
|
||||
return cmpMonth;
|
||||
int cmpMonth = Integer.compare(this.getMonth(), other.getMonth());
|
||||
if (cmpMonth != 0)
|
||||
return cmpMonth;
|
||||
|
||||
return Integer.compare(this.getDay(), other.getDay());
|
||||
|
||||
return Integer.compare(this.getDay(), other.getDay());
|
||||
}
|
||||
throw new IllegalArgumentException("The date to compare is not valid");
|
||||
}
|
||||
|
||||
public int getDay() {
|
||||
|
||||
@@ -204,4 +204,6 @@ class DateTest {
|
||||
Date d2 = new Date(5, 5, 2025);
|
||||
assertEquals(0, d1.compareTo(d2));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user