Browse Source

refactored field length

feat-figureMovement
JD 4 years ago
parent
commit
0af2521e3a
  1. 6
      fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java
  2. 12
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java

6
fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java

@ -2,7 +2,7 @@ package de.fd.fh;
public class Figure public class Figure
{ {
public static final int fieldSize = 64;
public static final int fieldLength = 8;
public boolean moveAllowed(int src, int dst, int[] field) public boolean moveAllowed(int src, int dst, int[] field)
{ {
@ -11,12 +11,12 @@ public class Figure
return false; return false;
} }
if (field.length != fieldSize)
if (field.length != Figure.fieldLength * Figure.fieldLength)
{ {
return false; return false;
} }
if (dst >= 56)
if (dst >= Figure.fieldLength * 7 + 0)
{ {
return false; return false;
} }

12
fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java

@ -10,41 +10,41 @@ class FigureTest
void checkMoveWithInvalidFieldSmall() // Feldgröße sollte 8*8 betragen void checkMoveWithInvalidFieldSmall() // Feldgröße sollte 8*8 betragen
{ {
Figure f = new Figure(); Figure f = new Figure();
assertFalse(f.moveAllowed(0,0, new int[0]));
assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 5 + 0, new int[0]));
} }
@Test @Test
void checkMoveWithInvalidFieldBigger() // Feldgröße sollte 8*8 betragen void checkMoveWithInvalidFieldBigger() // Feldgröße sollte 8*8 betragen
{ {
Figure f = new Figure(); Figure f = new Figure();
assertFalse(f.moveAllowed(48,40, new int[8*9]));
assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 5 + 0, new int[8*9]));
} }
@Test @Test
void checkMoveWithInvalidFieldCorrect() // Feldgröße sollte 8*8 betragen void checkMoveWithInvalidFieldCorrect() // Feldgröße sollte 8*8 betragen
{ {
Figure f = new Figure(); Figure f = new Figure();
assertTrue(f.moveAllowed(48,40, new int[Figure.fieldSize]));
assertTrue(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 5 + 0, new int[Figure.fieldLength * Figure.fieldLength]));
} }
@Test @Test
void checkMoveWithoutNewDestination() void checkMoveWithoutNewDestination()
{ {
Figure f = new Figure(); Figure f = new Figure();
assertFalse(f.moveAllowed(48,48, new int[Figure.fieldSize]));
assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 6 + 0, new int[Figure.fieldLength * Figure.fieldLength]));
} }
@Test @Test
void checkMoveWithValidDestination() void checkMoveWithValidDestination()
{ {
Figure f = new Figure(); Figure f = new Figure();
assertTrue(f.moveAllowed(48,40, new int[Figure.fieldSize]));
assertTrue(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 5 + 0, new int[Figure.fieldLength * Figure.fieldLength]));
} }
@Test @Test
void whiteFarmerInvalidDestinationDown() // statt nach "oben" wird nach "unten" gegangen void whiteFarmerInvalidDestinationDown() // statt nach "oben" wird nach "unten" gegangen
{ {
Figure f = new Figure(); Figure f = new Figure();
assertFalse(f.moveAllowed(48,56, new int[Figure.fieldSize]));
assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 7 + 0, new int[Figure.fieldLength * Figure.fieldLength]));
} }
} }
Loading…
Cancel
Save