-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChickenAttackerPosTest.java
42 lines (37 loc) · 1.34 KB
/
ChickenAttackerPosTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ch.epfl.chacun;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class ChickenAttackerPosTest {
@Test
void posOriginIsCorrectlyDefined() {
assertEquals(0, Pos.ORIGIN.x());
assertEquals(0, Pos.ORIGIN.y());
}
@Test
void posTranslatedWorksForRandomAmounts() {
for (int x = -10; x <= 10; x += 1) {
for (int y = -10; y <= 10; y += 1) {
var pos = new Pos(x, y);
for (int dX = -5; dX <= 5; dX += 1) {
for (int dY = -5; dY <= 5; dY += 1) {
var pos1 = pos.translated(dX, dY);
assertEquals(x + dX, pos1.x());
assertEquals(y + dY, pos1.y());
}
}
}
}
}
@Test
void posNeighborWorksForRandomPositions() {
for (int x = -10; x <= 10; x += 1) {
for (int y = -10; y <= 10; y += 1) {
var pos = new Pos(x, y);
assertEquals(new Pos(x, y - 1), pos.neighbor(Direction.N));
assertEquals(new Pos(x + 1, y), pos.neighbor(Direction.E));
assertEquals(new Pos(x, y + 1), pos.neighbor(Direction.S));
assertEquals(new Pos(x - 1, y), pos.neighbor(Direction.W));
}
}
}
}