aboutsummaryrefslogtreecommitdiff
path: root/test/ch
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-02-20 19:41:47 +0100
committerPacien TRAN-GIRARD2016-02-20 19:41:47 +0100
commitdf1880840db7bd8229d46118fb6d8508ecda61a1 (patch)
tree2dd2d307fde93c860d2645d62e42ecf90c94ceea /test/ch
parentb5644de85dda89829f20ca0106bf623f16c69090 (diff)
downloadxblast-df1880840db7bd8229d46118fb6d8508ecda61a1.tar.gz
Import first part unit tests
Diffstat (limited to 'test/ch')
-rw-r--r--test/ch/epfl/xblast/CellTest.java68
-rw-r--r--test/ch/epfl/xblast/DirectionTest.java41
-rw-r--r--test/ch/epfl/xblast/SubCellTest.java60
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck01.java49
4 files changed, 218 insertions, 0 deletions
diff --git a/test/ch/epfl/xblast/CellTest.java b/test/ch/epfl/xblast/CellTest.java
new file mode 100644
index 0000000..ba8becc
--- /dev/null
+++ b/test/ch/epfl/xblast/CellTest.java
@@ -0,0 +1,68 @@
1package ch.epfl.xblast;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5
6import org.junit.Test;
7
8public class CellTest {
9 @Test
10 public void rowMajorIndexCorrespondsToOrder() {
11 int i = 0;
12 for (Cell c: Cell.ROW_MAJOR_ORDER)
13 assertEquals(i++, c.rowMajorIndex());
14 assertEquals(Cell.COUNT, i);
15 }
16
17 @Test
18 public void spiralOrderContainsAllCells() {
19 assertEquals(Cell.COUNT, Cell.SPIRAL_ORDER.size());
20
21 boolean[] cellSeen = new boolean[Cell.COUNT];
22 for (Cell c: Cell.SPIRAL_ORDER) {
23 assertFalse(cellSeen[c.rowMajorIndex()]);
24 cellSeen[c.rowMajorIndex()] = true;
25 }
26 }
27
28 @Test
29 public void spiralOrderNeighborsAreSpatialNeighbors() {
30 Cell pred = Cell.SPIRAL_ORDER.get(0);
31 for (Cell c: Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) {
32 int areNeighborsCount = 0;
33 for (Direction d: Direction.values()) {
34 if (pred.equals(c.neighbor(d)))
35 areNeighborsCount += 1;
36 }
37 assertEquals(1, areNeighborsCount);
38 pred = c;
39 }
40 }
41
42 @Test
43 public void constructorCorrectlyNormalizesCoordinates() {
44 for (int i = -2; i <= 2; ++i) {
45 Cell c = new Cell(14 + 15 * i, 12 + 13 * i);
46 assertEquals(14, c.x());
47 assertEquals(12, c.y());
48 }
49 }
50
51 @Test
52 public void neighborsOfOriginAreCorrect() {
53 Cell c = new Cell(0, 0);
54 assertEquals(new Cell( 0, 12), c.neighbor(Direction.N));
55 assertEquals(new Cell( 1, 0), c.neighbor(Direction.E));
56 assertEquals(new Cell( 0, 1), c.neighbor(Direction.S));
57 assertEquals(new Cell(14, 0), c.neighbor(Direction.W));
58 }
59
60 @Test
61 public void oppositeNeighborOfNeighborIsThis() {
62 for (Cell c: Cell.ROW_MAJOR_ORDER) {
63 for (Direction d: Direction.values()) {
64 assertEquals(c, c.neighbor(d).neighbor(d.opposite()));
65 }
66 }
67 }
68}
diff --git a/test/ch/epfl/xblast/DirectionTest.java b/test/ch/epfl/xblast/DirectionTest.java
new file mode 100644
index 0000000..a2ac9cd
--- /dev/null
+++ b/test/ch/epfl/xblast/DirectionTest.java
@@ -0,0 +1,41 @@
1package ch.epfl.xblast;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import org.junit.Test;
8
9public class DirectionTest {
10 @Test
11 public void oppositeOfOppositeIsIdentity() {
12 for (Direction d: Direction.values())
13 assertEquals(d, d.opposite().opposite());
14 }
15
16 @Test
17 public void oppositeIsTwoStepsAway() {
18 for (Direction d: Direction.values())
19 assertEquals(2, Math.abs(d.ordinal() - d.opposite().ordinal()));
20 }
21
22 @Test
23 public void isHorizontalIsCorrect() {
24 assertFalse(Direction.N.isHorizontal());
25 assertTrue(Direction.E.isHorizontal());
26 assertFalse(Direction.S.isHorizontal());
27 assertTrue(Direction.W.isHorizontal());
28 }
29
30 @Test
31 public void isParallelIsTrueOnlyForOppositeAndSelf() {
32 for (Direction d1: Direction.values()) {
33 for (Direction d2: Direction.values()) {
34 if (d1 == d2 || d1 == d2.opposite())
35 assertTrue(d1.isParallelTo(d2));
36 else
37 assertFalse(d1.isParallelTo(d2));
38 }
39 }
40 }
41}
diff --git a/test/ch/epfl/xblast/SubCellTest.java b/test/ch/epfl/xblast/SubCellTest.java
new file mode 100644
index 0000000..1c79791
--- /dev/null
+++ b/test/ch/epfl/xblast/SubCellTest.java
@@ -0,0 +1,60 @@
1package ch.epfl.xblast;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5
6import org.junit.Test;
7
8public class SubCellTest {
9 @Test
10 public void centralSubCellOfKnowCellIsCorrect() {
11 SubCell c = SubCell.centralSubCellOf(new Cell(2, 1));
12 assertEquals(40, c.x());
13 assertEquals(24, c.y());
14 }
15
16 @Test
17 public void centralSubCellIsCentral() {
18 for (Cell c: Cell.ROW_MAJOR_ORDER)
19 assertTrue(SubCell.centralSubCellOf(c).isCentral());
20 }
21
22 @Test
23 public void distanceToCentralOfCentralIsZero() {
24 for (Cell c: Cell.ROW_MAJOR_ORDER)
25 assertEquals(0, SubCell.centralSubCellOf(c).distanceToCentral());
26 }
27
28 @Test
29 public void constructorCorrectlyNormalizesCoordinates() {
30 for (int i = -2; i <= 2; ++i) {
31 SubCell c = new SubCell(239 + 240 * i, 207 + 208 * i);
32 assertEquals(239, c.x());
33 assertEquals(207, c.y());
34 }
35 }
36
37 @Test
38 public void distanceToCentralOfOriginIsCorrect() {
39 SubCell s = new SubCell(0, 0);
40 assertEquals(16, s.distanceToCentral());
41 }
42
43 @Test
44 public void neighborsOfOriginAreCorrect() {
45 SubCell c = new SubCell(0, 0);
46 assertEquals(new SubCell( 0, 207), c.neighbor(Direction.N));
47 assertEquals(new SubCell( 1, 0), c.neighbor(Direction.E));
48 assertEquals(new SubCell( 0, 1), c.neighbor(Direction.S));
49 assertEquals(new SubCell(239, 0), c.neighbor(Direction.W));
50 }
51
52 @Test
53 public void containingCellOfCentralsNeighborIsCorrect() {
54 for (Cell c: Cell.ROW_MAJOR_ORDER) {
55 SubCell s = SubCell.centralSubCellOf(c);
56 for (Direction d: Direction.values())
57 assertEquals(c, s.neighbor(d).containingCell());
58 }
59 }
60}
diff --git a/test/ch/epfl/xblast/namecheck/NameCheck01.java b/test/ch/epfl/xblast/namecheck/NameCheck01.java
new file mode 100644
index 0000000..278d85b
--- /dev/null
+++ b/test/ch/epfl/xblast/namecheck/NameCheck01.java
@@ -0,0 +1,49 @@
1package ch.epfl.xblast.namecheck;
2
3import java.util.List;
4
5import ch.epfl.xblast.Cell;
6import ch.epfl.xblast.Direction;
7import ch.epfl.xblast.SubCell;
8
9/**
10 * Classe abstraite utilisant tous les éléments de l'étape 1, pour essayer de
11 * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est
12 * pas un test unitaire, et n'a pas pour but d'être exécuté!
13 */
14
15abstract class NameCheck01 {
16 void checkDirection() {
17 Direction d = Direction.N;
18 d = Direction.E;
19 d = Direction.S;
20 d = Direction.W;
21 if (d.isHorizontal() || d.isParallelTo(d))
22 d = d.opposite();
23 }
24
25 void checkCell() {
26 int c = Cell.COLUMNS;
27 int r = Cell.ROWS;
28 int t = Cell.COUNT;
29 List<Cell> l = Cell.ROW_MAJOR_ORDER;
30 l.get(c + r + t);
31 l = Cell.SPIRAL_ORDER;
32 l.get(c + r + t);
33 Cell d = new Cell(c, r);
34 c = d.x() + d.y() + d.rowMajorIndex();
35 d = d.neighbor(Direction.N);
36 }
37
38 void checkSubCell() {
39 SubCell c = SubCell.centralSubCellOf(new Cell(0,0));
40 c = new SubCell(0, 0);
41 int t = c.x() + c.y() + c.distanceToCentral();
42 if (t < 10 && c.isCentral())
43 c = c.neighbor(Direction.N);
44 else {
45 Cell cc = c.containingCell();
46 System.out.println(cc);
47 }
48 }
49}