From 25d399e1a60f1eccc0562a120d7e80378bf08779 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Thu, 13 Jan 2022 12:16:32 +0100 Subject: [PATCH] Refactoring testEverySecondField (override Equals of Coordinate) --- .../java/de/tims/fleetstorm/matchfield/Coordinate.java | 8 ++++++++ src/test/java/de/tims/fleetstorm/ai/LogicTest.java | 5 +---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java index 3e16694..705c77c 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java @@ -32,4 +32,12 @@ public class Coordinate { this.state = state; } + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Coordinate)) { + return false; + } + return this.x == ((Coordinate) obj).getX() && this.y == ((Coordinate) obj).getY(); + } + } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index 96d8eae..5eb55c0 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -64,9 +64,6 @@ class LogicTest { expectedResult.add(new Coordinate(3, 1)); expectedResult.add(new Coordinate(3, 3)); - for (int i = 0; i < expectedResult.size(); i++) { - assertEquals(everySecondField.get(i).getX(), expectedResult.get(i).getX()); - assertEquals(everySecondField.get(i).getY(), expectedResult.get(i).getY()); - } + assertEquals(everySecondField, expectedResult); } }