|
@ -4,6 +4,8 @@ import org.junit.jupiter.api.AfterEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
|
class ChessFigureTest { |
|
|
class ChessFigureTest { |
|
@ -43,4 +45,67 @@ class ChessFigureTest { |
|
|
assertNotEquals(kw2, kb1); |
|
|
assertNotEquals(kw2, kb1); |
|
|
assertNotEquals(pw1, kb1); |
|
|
assertNotEquals(pw1, kb1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void isRelativeMoveValid() { |
|
|
|
|
|
ArrayList<ChessFigure> array = new ArrayList<>(); |
|
|
|
|
|
for (ChessFigure.Type type : ChessFigure.Type.values()) |
|
|
|
|
|
for (ChessFigure.Team team : ChessFigure.Team.values()) |
|
|
|
|
|
array.add(new ChessFigure(type, team)); |
|
|
|
|
|
|
|
|
|
|
|
for (ChessFigure figure : array) { |
|
|
|
|
|
for (int x = -4; x <= 4; x++) { |
|
|
|
|
|
for (int y = -4; y <= 4; y++) { |
|
|
|
|
|
if (x == 0 && y == 0) { |
|
|
|
|
|
assertFalse(figure.isRelativeMoveValid(x, y)); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
switch (figure.getType()) { |
|
|
|
|
|
case KING: |
|
|
|
|
|
if (x * x == 1 && y * y == 1) { |
|
|
|
|
|
assertTrue(figure.isRelativeMoveValid(x, y)); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case QUEEN: |
|
|
|
|
|
if ((x == y) || (x == 0 ^ y == 0)) { |
|
|
|
|
|
assertTrue(figure.isRelativeMoveValid(x, y)); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case CASTLE: |
|
|
|
|
|
if (x == 0 ^ y == 0) { |
|
|
|
|
|
assertTrue(figure.isRelativeMoveValid(x, y)); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case BISHOP: |
|
|
|
|
|
if (x == y) { |
|
|
|
|
|
assertTrue(figure.isRelativeMoveValid(x, y)); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case KNIGHT: |
|
|
|
|
|
if ((y == 2 && (x == -1 || x == 1)) || (y == -2 && (x == -1 || x == 1)) || (x == 2 && (y == -1 || y == 1)) || (x == -2 && (y == -1 || y == 1))) { |
|
|
|
|
|
assertTrue(figure.isRelativeMoveValid(x, y)); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case PAWN: |
|
|
|
|
|
if (figure.getTeam() == ChessFigure.Team.WHITE && (y == 1) && x != 0) { |
|
|
|
|
|
assertTrue(figure.isRelativeMoveValid(x, y)); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (figure.getTeam() == ChessFigure.Team.BLACK && (y == -1) && x != 0) { |
|
|
|
|
|
assertTrue(figure.isRelativeMoveValid(x, y)); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
} |
|
|
|
|
|
assertFalse(figure.isRelativeMoveValid(x, y), "Type: " + figure.getType() + " X: " + x + " Y: " + y + " should be false"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |