From 7c784337031f6de133fca2add9f4b4864b9ff34e Mon Sep 17 00:00:00 2001 From: Julius Dewender Date: Sun, 31 Jan 2021 17:44:35 +0100 Subject: [PATCH] added test for valid movement of black farmer --- .../src/main/java/de/fd/fh/FigureFarmer.java | 9 ++++++-- .../test/java/de/fd/fh/FigureFarmerTest.java | 23 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java index af1aaad..8f6548e 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java @@ -15,12 +15,17 @@ public class FigureFarmer extends Figure { int rowDiff = src / fieldLength - dst / fieldLength; // hoch/runter - if (rowDiff > 1) // weißer Bauer nicht mehr als 1 Schritt nach "oben" + if (mColor == Color.Black) + { + rowDiff *= -1; + } + + if (rowDiff > 1) // Bauer nicht mehr als 1 Schritt { return false; } - if (rowDiff <= 0) // weißer Bauer kein Schritt "runter" + if (rowDiff <= 0) // Bauer nur Schritte in erlaubte Richtung (weiß -> hoch, schwarz -> runter) { return false; } diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java index 1a680ab..f4c2df3 100644 --- a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java @@ -10,19 +10,30 @@ class FigureFarmerTest { Figure[] field = new Figure[Figure.fieldLength * Figure.fieldLength]; - // weißer Bauer @ParameterizedTest - // row (src), col (src), row (dst), col (dst) + // color (0 white/1 black), row (src), col (src), row (dst), col (dst) @CsvSource({ - "6, 0, 5, 0", // a2 -> a3 - "4, 4, 3, 4" // e4 -> e5 + "0, 6, 0, 5, 0", // white: a2 -> a3 + "0, 4, 4, 3, 4", // white: e4 -> e5 + + "1, 1, 0, 2, 0" // black: a1 -> a2 }) - void whiteFarmerValidDestination(int srcRow, int srcCol, int dstRow, int dstCol) + void whiteFarmerValidDestination(int color, int srcRow, int srcCol, int dstRow, int dstCol) { int src = Figure.fieldLength * srcRow + srcCol; int dst = Figure.fieldLength * dstRow + dstCol; - Figure f = new FigureFarmer(FigureFarmer.Color.White); + Figure f = null; + + if (color == 0) + { + f = new FigureFarmer(FigureFarmer.Color.White); + } + else if (color == 1) + { + f = new FigureFarmer(FigureFarmer.Color.Black); + } + assertTrue(f.moveAllowed(src, dst, field)); }