From e77ffb6f8a798c7917ff54e238e3027ab8a21878 Mon Sep 17 00:00:00 2001 From: Julius Dewender Date: Fri, 5 Feb 2021 13:11:19 +0100 Subject: [PATCH] refactoring: removed magic numbers --- fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java | 2 +- .../src/test/java/de/fd/fh/FigureBishopTest.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java index 80ea718..b9e6e6f 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java @@ -5,7 +5,7 @@ public class FigureBishop extends Figure @Override public boolean moveAllowed(int src, int dst, Figure[] field) { - if ((dst-src) % 8 == 0) // nach oben/unten nicht erlaubt + if ((dst-src) % Figure.fieldLength == 0) // nach oben/unten nicht erlaubt { return false; } diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureBishopTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureBishopTest.java index 3dc528a..acbf798 100644 --- a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureBishopTest.java +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureBishopTest.java @@ -7,10 +7,14 @@ import static org.junit.jupiter.api.Assertions.*; class FigureBishopTest { @Test - void checkInvalidMovesBishop() + void checkInvalidMovesBishopUpward() { Figure f = new FigureBishop(); - assertFalse(f.moveAllowed(45, 37, new Figure[64])); + int src = Figure.fieldLength * 5 + 5; + int dst = src - Figure.fieldLength; + + assertFalse(f.moveAllowed(src, dst, + new Figure[Figure.fieldLength * Figure.fieldLength])); } } \ No newline at end of file