From ef18ef4f9801598699240d12cd298a9b936b828e Mon Sep 17 00:00:00 2001 From: Julius Dewender Date: Thu, 14 Jan 2021 21:22:22 +0100 Subject: [PATCH] figure movement: invalid step --- fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java | 5 +++++ fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java b/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java index 0b5b4d5..f4e9625 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java @@ -6,6 +6,11 @@ public class Figure public boolean moveAllowed(int src, int dst, int[] field) { + if (src == dst) + { + return false; + } + if (field.length == fieldSize) { return true; diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java index 22902f1..56d8ae9 100644 --- a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java @@ -26,4 +26,11 @@ class FigureTest Figure f = new Figure(); assertTrue(f.moveAllowed(48,40, new int[Figure.fieldSize])); } + + @Test + void checkMoveWithoutNewDestination() + { + Figure f = new Figure(); + assertFalse(f.moveAllowed(48,48, new int[Figure.fieldSize])); + } } \ No newline at end of file