Browse Source

refactoring: removed magic numbers

feat-figureMovement
JD 4 years ago
parent
commit
e77ffb6f8a
  1. 2
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java
  2. 8
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureBishopTest.java

2
fh.fd.ci.client/src/main/java/de/fd/fh/FigureBishop.java

@ -5,7 +5,7 @@ public class FigureBishop extends Figure
@Override @Override
public boolean moveAllowed(int src, int dst, Figure[] field) 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; return false;
} }

8
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 class FigureBishopTest
{ {
@Test @Test
void checkInvalidMovesBishop()
void checkInvalidMovesBishopUpward()
{ {
Figure f = new FigureBishop(); 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]));
} }
} }
Loading…
Cancel
Save