Hallo
Wir haben das Problem das einer der Test fehlschlägt. Das Problem ist, dass der Test so vorgegeben ist.
Wir machen folgendes:
Test:
Eigentlich müssten beide die gleiche Referenz haben (siehe toString). Müssen wir jetzt die ganze Klasse wegwerfen?
Wir haben das Problem das einer der Test fehlschlägt. Das Problem ist, dass der Test so vorgegeben ist.
Wir machen folgendes:
Java:
public class Field {
private Point coordinate;
private Config.Land land;
private Integer diceNumber;
/**
* The constructor of the class fields
*
* @param coordinate coordinate of the field
* @param land type of land
* @param diceNumber the dice number on a field
*/
public Field(Point coordinate, Config.Land land, Integer diceNumber) {
this.coordinate = coordinate;
this.land = land;
this.diceNumber = diceNumber;
}
public Config.Land getLand() {
return land;
}
public Integer getDiceNumber() {
return diceNumber;
}
public Point getCoordinate() {
return coordinate;
}
/**
* Get the field corners
*
* @return list of corners
*/
public List<Point> getCorners() {
return List.of(new Point(getCoordinate().x, getCoordinate().y - 2), // N (top)
new Point(getCoordinate().x + 1, getCoordinate().y - 1), // NE (top right)
new Point(getCoordinate().x + 1, getCoordinate().y + 1), // SE (bottom right)
new Point(getCoordinate().x, getCoordinate().y + 2), // S (bottom)
new Point(getCoordinate().x - 1, getCoordinate().y + 1), // SW (bottom left)
new Point(getCoordinate().x - 1, getCoordinate().y - 1) // NW (top left)
);
}
@Override
public String toString()
{
return getLand().toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Field)) {
return false;
}
Field other = (Field) o;
return getCoordinate().equals(other.getCoordinate()) &&
getDiceNumber().equals(other.getDiceNumber()) &&
getLand().equals(other.getLand());
}
@Override
public int hashCode() {
int result = 17;
if (getCoordinate() != null) {
result = 31 * result + getCoordinate().hashCode();
}
if (getLand() != null) {
result = 31 * result + getLand().hashCode();
}
if (getDiceNumber() != null) {
result = 31 * result + getDiceNumber().hashCode();
}
return result;
}
}
Java:
Test:
Java:
public void requirementLandPlacementTest() {
SiedlerGame model = new SiedlerGame(DEFAULT_WINPOINTS, DEFAULT_NUMBER_OF_PLAYERS);
assertTrue(Config.getStandardLandPlacement().size() == model.getBoard().getFields().size(),
"Check if explicit init must be done (violates spec): "
+ "modify initializeSiedlerGame accordingly.");
for (Map.Entry<Point, Config.Land> e : Config.getStandardLandPlacement().entrySet()) {
assertEquals(e.getValue(), model.getBoard().getField(e.getKey()),
"Land placement does not match default placement.");
}
}
Eigentlich müssten beide die gleiche Referenz haben (siehe toString). Müssen wir jetzt die ganze Klasse wegwerfen?