aboutsummaryrefslogtreecommitdiff
path: root/test/ch/epfl/xblast/CellTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/ch/epfl/xblast/CellTest.java')
-rw-r--r--test/ch/epfl/xblast/CellTest.java29
1 files changed, 17 insertions, 12 deletions
diff --git a/test/ch/epfl/xblast/CellTest.java b/test/ch/epfl/xblast/CellTest.java
index ba8becc..c5d93e8 100644
--- a/test/ch/epfl/xblast/CellTest.java
+++ b/test/ch/epfl/xblast/CellTest.java
@@ -1,15 +1,19 @@
1package ch.epfl.xblast; 1package ch.epfl.xblast;
2 2
3import org.junit.Test;
4
3import static org.junit.Assert.assertEquals; 5import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse; 6import static org.junit.Assert.assertFalse;
5 7
6import org.junit.Test; 8/**
7 9 * @author EPFL
10 */
8public class CellTest { 11public class CellTest {
12
9 @Test 13 @Test
10 public void rowMajorIndexCorrespondsToOrder() { 14 public void rowMajorIndexCorrespondsToOrder() {
11 int i = 0; 15 int i = 0;
12 for (Cell c: Cell.ROW_MAJOR_ORDER) 16 for (Cell c : Cell.ROW_MAJOR_ORDER)
13 assertEquals(i++, c.rowMajorIndex()); 17 assertEquals(i++, c.rowMajorIndex());
14 assertEquals(Cell.COUNT, i); 18 assertEquals(Cell.COUNT, i);
15 } 19 }
@@ -19,7 +23,7 @@ public class CellTest {
19 assertEquals(Cell.COUNT, Cell.SPIRAL_ORDER.size()); 23 assertEquals(Cell.COUNT, Cell.SPIRAL_ORDER.size());
20 24
21 boolean[] cellSeen = new boolean[Cell.COUNT]; 25 boolean[] cellSeen = new boolean[Cell.COUNT];
22 for (Cell c: Cell.SPIRAL_ORDER) { 26 for (Cell c : Cell.SPIRAL_ORDER) {
23 assertFalse(cellSeen[c.rowMajorIndex()]); 27 assertFalse(cellSeen[c.rowMajorIndex()]);
24 cellSeen[c.rowMajorIndex()] = true; 28 cellSeen[c.rowMajorIndex()] = true;
25 } 29 }
@@ -28,9 +32,9 @@ public class CellTest {
28 @Test 32 @Test
29 public void spiralOrderNeighborsAreSpatialNeighbors() { 33 public void spiralOrderNeighborsAreSpatialNeighbors() {
30 Cell pred = Cell.SPIRAL_ORDER.get(0); 34 Cell pred = Cell.SPIRAL_ORDER.get(0);
31 for (Cell c: Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) { 35 for (Cell c : Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) {
32 int areNeighborsCount = 0; 36 int areNeighborsCount = 0;
33 for (Direction d: Direction.values()) { 37 for (Direction d : Direction.values()) {
34 if (pred.equals(c.neighbor(d))) 38 if (pred.equals(c.neighbor(d)))
35 areNeighborsCount += 1; 39 areNeighborsCount += 1;
36 } 40 }
@@ -51,18 +55,19 @@ public class CellTest {
51 @Test 55 @Test
52 public void neighborsOfOriginAreCorrect() { 56 public void neighborsOfOriginAreCorrect() {
53 Cell c = new Cell(0, 0); 57 Cell c = new Cell(0, 0);
54 assertEquals(new Cell( 0, 12), c.neighbor(Direction.N)); 58 assertEquals(new Cell(0, 12), c.neighbor(Direction.N));
55 assertEquals(new Cell( 1, 0), c.neighbor(Direction.E)); 59 assertEquals(new Cell(1, 0), c.neighbor(Direction.E));
56 assertEquals(new Cell( 0, 1), c.neighbor(Direction.S)); 60 assertEquals(new Cell(0, 1), c.neighbor(Direction.S));
57 assertEquals(new Cell(14, 0), c.neighbor(Direction.W)); 61 assertEquals(new Cell(14, 0), c.neighbor(Direction.W));
58 } 62 }
59 63
60 @Test 64 @Test
61 public void oppositeNeighborOfNeighborIsThis() { 65 public void oppositeNeighborOfNeighborIsThis() {
62 for (Cell c: Cell.ROW_MAJOR_ORDER) { 66 for (Cell c : Cell.ROW_MAJOR_ORDER) {
63 for (Direction d: Direction.values()) { 67 for (Direction d : Direction.values()) {
64 assertEquals(c, c.neighbor(d).neighbor(d.opposite())); 68 assertEquals(c, c.neighbor(d).neighbor(d.opposite()));
65 } 69 }
66 } 70 }
67 } 71 }
72
68} 73}