From 39759cf01d501a43bdd10bd4c0d12fef83aa1cdb Mon Sep 17 00:00:00 2001 From: Julius Dewender Date: Fri, 5 Feb 2021 11:55:54 +0100 Subject: [PATCH] test: king movement -> valid moves (based on checkInvalidKingMoves()) --- .../src/main/java/de/fd/fh/FigureKing.java | 14 +++++----- .../test/java/de/fd/fh/FigureKingTest.java | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java index 4c2c230..e4bc10e 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java @@ -7,15 +7,15 @@ public class FigureKing extends Figure { // TODO: Positionierung in einer Ecke beachten if (dst != src-1 - || dst != src +1 + && dst != src +1 - || dst != src -8 - || dst != src -8 -1 - || dst != src -8 +1 + && dst != src -8 + && dst != src -8 -1 + && dst != src -8 +1 - || dst != src +8 - || dst != src +8 -1 - || dst != src +8 +1) + && dst != src +8 + && dst != src +8 -1 + && dst != src +8 +1) { return false; } diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java index adffd96..7e7db53 100644 --- a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java @@ -43,4 +43,30 @@ class FigureKingTest assertFalse(f.moveAllowed(pos, i, new Figure[64])); } } + + @Test + void checkValidKingMoves() + { + Figure f = new FigureKing(); + + int pos = 45; + + ArrayList possibleMoves = new ArrayList<>(); + + possibleMoves.add(pos - Figure.fieldLength - 1); + possibleMoves.add(pos - Figure.fieldLength); + possibleMoves.add(pos - Figure.fieldLength + 1); + + possibleMoves.add(pos - 1); + possibleMoves.add(pos + 1); + + possibleMoves.add(pos + Figure.fieldLength - 1); + possibleMoves.add(pos + Figure.fieldLength); + possibleMoves.add(pos + Figure.fieldLength + 1); + + for (int i = 0; i < possibleMoves.size(); i++) + { + assertTrue(f.moveAllowed(pos, possibleMoves.get(i), new Figure[64])); + } + } } \ No newline at end of file